Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
Returns:
``numpy.ndarray``, in 2 dimensions. This will contain the ``m``
parameter from the fitted line.
"""
stacked_array = numpy.dstack(blocks)
new_shape = (stacked_array.shape[0]*stacked_array.shape[1],
len(timesteps))
reshaped = numpy.swapaxes(numpy.reshape(stacked_array, new_shape), 0, 1)
regression = numpy.polyfit(timesteps,
reshaped, deg=deg, w=weights)[0]
out_block = regression.reshape(blocks[0].shape)
# Mask out any pixel stacks where there's a nodata value in the stack.
# Out block is multiplied by 365.25 to convert m/day to m/year trend.
return numpy.where(numpy.min(stacked_array, axis=2) == 0, 0, out_block*365.25)
raster_cell_sizes = [pygeoprocessing.get_cell_size_from_uri(r)
for r in rasters]
min_cell_size = min(raster_cell_sizes)
if not len(set(raster_cell_sizes)) == 1:
warnings.warn(('Cell sizes of input rasters do not all match. '
'Using min pixelsize of %s. Mismatched values: %s') % (
min_cell_size, set(raster_cell_sizes)))
pygeoprocessing.vectorize_datasets(
dataset_uri_list=rasters,
dataset_pixel_op=_regression,
dataset_out_uri=out_filename,
datatype_out=gdal.GDT_Float32,
nodata_out=0,
pixel_size_out=min_cell_size,
bounding_box_mode='intersection',
vectorize_op=False,