percentile_cdf_pipeline.py
def calculate_percentile(
        raster_path, percentiles_list, workspace_dir, result_pickle_path):
    """Calculate the percentile cutoffs of a given raster. Store in json.

    Parameters:
        raster_path (str): path to raster to calculate over.
        percentiles_list (list): sorted list of increasing percentile
            cutoffs to calculate.
        workspace_dir (str): path to a directory where this function can
            create a temporary directory to work in.
        result_pickle_path (path): path to .json file that will store
            "percentiles_list" -- original value of perentile_list
            "percentile_values_list" -- list of percentile threshold values
                in the same position in `percentile_list`.
            "percentile_sums_list" -- sum of all values up to the given
                percentile in the same position in `percentile_list`.

    Returns:
        None.

    """
    churn_dir = tempfile.mkdtemp(dir=workspace_dir)
    LOGGER.debug('processing percentiles for %s', raster_path)
    heap_size = 2**28
    ffi_buffer_size = 2**10
    result_dict = {
        'percentiles_list': percentiles_list,
        'percentile_sum_list': [0.] * len(percentiles_list),
        'percentile_values_list': pygeoprocessing.raster_band_percentile(
            (raster_path, 1), churn_dir, percentiles_list,
            heap_size, ffi_buffer_size)
    }
    LOGGER.debug('intermediate result_dict: %s', str(result_dict))
    LOGGER.debug('processing percentile sums for %s', raster_path)
    nodata_value = pygeoprocessing.get_raster_info(raster_path)['nodata'][0]
    for _, block_data in pygeoprocessing.iterblocks((raster_path, 1)):
        nodata_mask = numpy.isclose(block_data, nodata_value)
        # this loop makes the block below a lot simpler
        for index, percentile_value in enumerate(
                result_dict['percentile_values_list']):
            mask = (block_data > percentile_value) & (~nodata_mask)
            result_dict['percentile_sum_list'][index] += (
                numpy.sum(block_data[mask]))

    LOGGER.debug(
        'pickling percentile results of %s to %s', raster_path,
        result_pickle_path)
    with open(result_pickle_path, 'wb') as pickle_file:
        pickle_file.write(pickle.dumps(result_dict))
    shutil.rmtree(churn_dir)
Calculate the percentile cutoffs of a given raster. Store in json.

    Parameters:
        raster_path (str): path to raster to calculate over.
        percentiles_list (list): sorted list of increasing percentile
            cutoffs to calculate.
        workspace_dir (str): path to a directory where this function can
            create a temporary directory to work in.
        result_pickle_path (path): path to .json file that will store
            "percentiles_list" -- original value of perentile_list
            "percentile_values_list" -- list of percentile threshold values
                in the same position in `percentile_list`.
            "percentile_sums_list" -- sum of all values up to the given
                percentile in the same position in `percentile_list`.

    Returns:
        None.

    
Calculate the percentile cutoffs of a given raster. Store in json.
Calculate the percentile cutoffs of a given raster . Store in json .
def calculate_percentile(
        raster_path, percentiles_list, workspace_dir, result_pickle_path):
    churn_dir = tempfile.mkdtemp(dir=workspace_dir)
    LOGGER.debug('processing percentiles for %s', raster_path)
    heap_size = 2**28
    ffi_buffer_size = 2**10
    result_dict = {
        'percentiles_list': percentiles_list,
        'percentile_sum_list': [0.] * len(percentiles_list),
        'percentile_values_list': pygeoprocessing.raster_band_percentile(
            (raster_path, 1), churn_dir, percentiles_list,
            heap_size, ffi_buffer_size)
    }
    LOGGER.debug('intermediate result_dict: %s', str(result_dict))
    LOGGER.debug('processing percentile sums for %s', raster_path)
    nodata_value = pygeoprocessing.get_raster_info(raster_path)['nodata'][0]
    for _, block_data in pygeoprocessing.iterblocks((raster_path, 1)):
        nodata_mask = numpy.isclose(block_data, nodata_value)
        for index, percentile_value in enumerate(
                result_dict['percentile_values_list']):
            mask = (block_data > percentile_value) & (~nodata_mask)
            result_dict['percentile_sum_list'][index] += (
                numpy.sum(block_data[mask]))
    LOGGER.debug(
        'pickling percentile results of %s to %s', raster_path,
        result_pickle_path)
    with open(result_pickle_path, 'wb') as pickle_file:
        pickle_file.write(pickle.dumps(result_dict))
    shutil.rmtree(churn_dir)
def calculate_percentile ( raster_path , percentiles_list , workspace_dir , result_pickle_path ) : churn_dir = tempfile . mkdtemp ( dir = workspace_dir ) LOGGER . debug ( 'processing percentiles for %s' , raster_path ) heap_size = 2 ** 28 ffi_buffer_size = 2 ** 10 result_dict = { 'percentiles_list' : percentiles_list , 'percentile_sum_list' : [ 0. ] * len ( percentiles_list ) , 'percentile_values_list' : pygeoprocessing . raster_band_percentile ( ( raster_path , 1 ) , churn_dir , percentiles_list , heap_size , ffi_buffer_size ) } LOGGER . debug ( 'intermediate result_dict: %s' , str ( result_dict ) ) LOGGER . debug ( 'processing percentile sums for %s' , raster_path ) nodata_value = pygeoprocessing . get_raster_info ( raster_path ) [ 'nodata' ] [ 0 ] for _ , block_data in pygeoprocessing . iterblocks ( ( raster_path , 1 ) ) : nodata_mask = numpy . isclose ( block_data , nodata_value ) for index , percentile_value in enumerate ( result_dict [ 'percentile_values_list' ] ) : mask = ( block_data > percentile_value ) & ( ~ nodata_mask ) result_dict [ 'percentile_sum_list' ] [ index ] += ( numpy . sum ( block_data [ mask ] ) ) LOGGER . debug ( 'pickling percentile results of %s to %s' , raster_path , result_pickle_path ) with open ( result_pickle_path , 'wb' ) as pickle_file : pickle_file . write ( pickle . dumps ( result_dict ) ) shutil . rmtree ( churn_dir )
Calculate the percentile cutoffs of a given raster.
Calculate the percentile cutoffs of a given raster .
"""Calculate the percentile cutoffs of a given raster. Store in json.

    Parameters:
        raster_path (str): path to raster to calculate over.
        percentiles_list (list): sorted list of increasing percentile
            cutoffs to calculate.
        workspace_dir (str): path to a directory where this function can
            create a temporary directory to work in.
        result_pickle_path (path): path to .json file that will store
            "percentiles_list" -- original value of perentile_list
            "percentile_values_list" -- list of percentile threshold values
                in the same position in `percentile_list`.
            "percentile_sums_list" -- sum of all values up to the given
                percentile in the same position in `percentile_list`.

    Returns:
        None.

    """ # this loop makes the block below a lot simpler

None
raster_path
path to raster to calculate over.
path to raster to calculate over .
percentiles_list
sorted list of increasing percentile
cutoffs to calculate.
sorted list of increasing percentile cutoffs to calculate .
workspace_dir
path to a directory where this function can
create a temporary directory to work in.
path to a directory where this function can create a temporary directory to work in .
result_pickle_path
path to .json file that will store
"percentiles_list" -- original value of perentile_list
"percentile_values_list" -- list of percentile threshold values
in the same position in `percentile_list`.
"percentile_sums_list" -- sum of all values up to the given
percentile in the same position in `percentile_list`.
path to . json file that will store " percentiles_list " -- original value of perentile_list " percentile_values_list " -- list of percentile threshold values in the same position in ` percentile_list ` . " percentile_sums_list " -- sum of all values up to the given percentile in the same position in ` percentile_list ` .