align_to_mask.py
def mask_raster(base_raster_path, mask_raster_path, target_raster_path):
    """Mask base by mask setting nodata to nodata otherwise passthrough."""
    mask_nodata = geoprocessing.get_raster_info(
        mask_raster_path)['nodata'][0]
    base_raster_info = geoprocessing.get_raster_info(base_raster_path)
    base_nodata = base_raster_info['nodata'][0]

    def _mask_op(base_array, mask_array):
        result = numpy.copy(base_array)
        nodata_mask = numpy.isclose(mask_array, mask_nodata)
        result[nodata_mask] = base_nodata
        return result

    geoprocessing.raster_calculator(
        [(base_raster_path, 1), (mask_raster_path, 1)], _mask_op,
        target_raster_path, base_raster_info['datatype'], base_nodata)
Mask base by mask setting nodata to nodata otherwise passthrough.
Mask base by mask setting nodata to nodata otherwise passthrough.
Mask base by mask setting nodata to nodata otherwise passthrough .
def mask_raster(base_raster_path, mask_raster_path, target_raster_path):
    mask_nodata = geoprocessing.get_raster_info(
        mask_raster_path)['nodata'][0]
    base_raster_info = geoprocessing.get_raster_info(base_raster_path)
    base_nodata = base_raster_info['nodata'][0]
    def _mask_op(base_array, mask_array):
        result = numpy.copy(base_array)
        nodata_mask = numpy.isclose(mask_array, mask_nodata)
        result[nodata_mask] = base_nodata
        return result
    geoprocessing.raster_calculator(
        [(base_raster_path, 1), (mask_raster_path, 1)], _mask_op,
        target_raster_path, base_raster_info['datatype'], base_nodata)
def mask_raster ( base_raster_path , mask_raster_path , target_raster_path ) : mask_nodata = geoprocessing . get_raster_info ( mask_raster_path ) [ 'nodata' ] [ 0 ] base_raster_info = geoprocessing . get_raster_info ( base_raster_path ) base_nodata = base_raster_info [ 'nodata' ] [ 0 ] def _mask_op ( base_array , mask_array ) : result = numpy . copy ( base_array ) nodata_mask = numpy . isclose ( mask_array , mask_nodata ) result [ nodata_mask ] = base_nodata return result geoprocessing . raster_calculator ( [ ( base_raster_path , 1 ) , ( mask_raster_path , 1 ) ] , _mask_op , target_raster_path , base_raster_info [ 'datatype' ] , base_nodata )
Mask base by mask setting nodata to nodata otherwise passthrough.
Mask base by mask setting nodata to nodata otherwise passthrough .
"""Mask base by mask setting nodata to nodata otherwise passthrough."""
base_raster_path
mask_raster_path
target_raster_path