Raster Manipulation
Functions for working with raster data, including masks and platform-specific processing functions.
Key functions
create_matching_dataset()
: Creates an empty raster of the same shape as a source, ready for writing.
stack_images()
: Stacks a list of rasters into a single raster.
n2_images()
: Preprocesses a set of of Sentinel-2 images into single raster files.
clip_raster()
: Clips a raster to a shapefile
Rasters
When working with raster data (geotiff, .jp2, ect) using this module, the following assumptions have been made:
Any function that reads a raster can read from any gdal-readable format
All interim rasters are stored internally as a geotiff
All internal rasters have a .tif extension in the filename
Unless otherwise stated, all rasters are assumed to be in a projected coordinate system - i.e. in meters. Functions may fail if passed a raster in lat-long projection
Timestamps
pyeo uses the same timestamp convention as ESA: yyyymmddThhmmss; for example, 1PM on 27th December 2020 would be 20201227T130000. All timestamps are in UTC
Supported datatypes
When a function in this library asks for a datatype, it can take one of the following
gdal.GDT_Unknown
gdal.GDT_Byte
gdal.GDT_UInt16
gdal.GDT_Int16
gdal.GDT_UInt32
gdal.GDT_Int32
gdal.GDT_Float32
gdal.GDT_Float64
gdal.GDT_CInt16
gdal.GDT_CInt32
gdal.GDT_CFloat32
gdal.GDT_CFloat64
Geotransforms
Every gdal raster has a geotransform associated with it; this defines it’s top-left hand corner in the projection and pixel size. In pyeo, it takes the form of a 6-element tuple; for north-up images, these are the following.
geotransform[0] = top_left_x
geotransfrom[1] = pixel_width
geotransform[2] = 0
geotransform[3] = top_left_y
geotransform[4] = 0
geotransform[5] = pixel_height
A geotransform can be obtained from a raster with the following snippet:
image = gdal.Open("my_raster.tif")
gt = image.GetGeoTransform()
For more information, see the following: See the following: https://gdal.org/user/raster_data_model.html#affine-geotransform
Projections
Each Gdal raster also has a projection, defining (among other things) the unit of the geotransform. Projections in pyeo are referred to either by EPSG number or passed around as a wkt( well-known text) string. You can look up EPSG values at https://epsg.io You can use the following snippet to extract the well-known text of a raster
projection = image.GetProjection()
Masks
Some functions in this module include options for creating and applying masks.
A raster may have an associated mask
A mask is a geotif with an identical name as the raster it’s masking with a .msk extension
For example, the mask for my_sat_image.tif is my_sat_image.msk
A mask is
a single band raster
of identical height, width and resolution of the related image
contains values 0 or 1
A mask is applied by multiplying it with each band of its raster
So any pixel with a 0 in its mask will be removed, and a 1 will be kept
Function reference
- pyeo.raster_manipulation.add_masks(mask_paths, out_path, geometry_func='union')
Creates a raster file by adding a list of mask files containing 0 and 1 values
- Parameters:
mask_paths (list of str) – List of strings containing the full directory paths and file names of all masks to be added
geometry_func ({'intersect' or 'union'}) – How to handle non-overlapping masks. Defaults to ‘union’
- Returns:
out_path – The path to the new raster file.
- Return type:
str
- pyeo.raster_manipulation.align_image_in_place(image_path, target_path)
Adjusts the geotransform of the image at image_path with that of the one at target_path, so they align neatly with the smallest magnitude of movement
- Parameters:
image_path (str) – The path to the image to be adjusted.
target_path (str) – The image to align the image at image_path to.
- Raises:
NonSquarePixelException – Raised if either image does not have square pixels
- pyeo.raster_manipulation.apply_array_image_mask(array, mask, fill_value=0)
Applies a mask of (y,x) to an image array of (bands, y, x). Replaces any masked pixels with fill_value Mask is an a 2 dimensional array of 1 (unmasked) and 0 (masked)
- Parameters:
array (array_like) – The array containing the raster data
mask (array_like) – The array containing the mask
fill_value (number, optional) – The value to replace any masked pixels with. Defaults to 0.
- Returns:
masked_array – The array with masked pixels replaced with fill_value
- Return type:
array_like
- pyeo.raster_manipulation.apply_band_function(in_path, function, bands, out_path, out_datatype=5)
Applys an arbitrary band mathematics function to an image at in_path and saves the result at out_map. Function should be a function object of the form f(band_input_A, band_input_B, …)
- Parameters:
in_path (str) – The image to process
function (Func) –
bands –
out_path –
out_datatype –
Examples
Calculating the NDVI of an image with red band at band 0 and IR band at 4 First, define the function to be run across each pixel:
>>> def ndvi_function(r, i): ... return (r-i)/(r+i)
>>> apply_band_function("my_raster.tif", ndvi_function, [0,1], "my_ndvi.tif")
- pyeo.raster_manipulation.apply_image_function(in_paths, out_path, function, out_datatype=5)
Applies a pixel-wise function across every image. Assumes each image is exactly contiguous and, for now, single-banded. function() should take a list of values and return a single value.
- Parameters:
in_paths (list of str) – list of raster paths to process
out_path (str) – The path to the
function (function) – The function to apply to the list of images. Must take a list of numbers as an input and return a value.
out_datatype (gdal datatype, optional) – The datatype of the final raster. Defaults to gdal.gdt_Int32
Examples
Producing a raster where each pixel contains the sum of the corresponding pixels in a list of other rasters
>>> def sum_function(pixels_in): ... return np.sum(pixels_in) >>> in_paths = os.listdir("my_raster_dir") >>> apply_image_function(in_paths, "sum_raster.tif", sum_function)
- pyeo.raster_manipulation.apply_mask_to_dir(mask_path, image_dir, masked_image_dir)
Iterates over all raster images in image_dir and applies the mask to each image.
- Parameters:
mask_path (str) – Paths and file name of the mask file
image_dir (str) – Path and directory name which contains the raster image files in Geotiff format
masked_image_dir (str) – Path and directory name in which the masked raster image files will be created
- pyeo.raster_manipulation.apply_mask_to_image(mask_path, image_path, masked_image_path)
Applies a mask of 0 and 1 values to a raster image with one or more bands in Geotiff format by multiplying each pixel value with the mask value.
- Parameters:
mask_path (str) – Paths and file name of the mask file
image_path (str) – Path and file name of the raster image file
masked_image_path (str) – Path and file name of the masked raster image file that will be created
- pyeo.raster_manipulation.apply_processing_baseline_0400_offset_correction_to_tiff_file_directory(in_tif_directory: str, out_tif_directory: str, bands_to_offset_labels=('B02', 'B03', 'B04', 'B08'), bands_to_offset_index=[0, 1, 2, 3], BOA_ADD_OFFSET=-1000, backup_flag=False)
Offsets data within selected bands from a directory of stacked raster files Overwrites original file - option to save a backup copy.
- Parameters:
in_tif_directory (str) – Path to the input (and output) directory of tif raster files
out_tif_directory (str) – Path to the output directory of tif raster files
bands_to_offset_labels (list[str]) – List of bands to offset
bands_to_offset_index (list[int]) – List of indices of bands to offset within the tif image
BOA_ADD_OFFSET (int) – Required offset per band (from xml information within L2A SAFE file directory)
backup_flag (bool, optional) – If True leaves unoffset images with .backup extension in tif_directory
- Returns:
out_tif_directory – The path to the output directory
- Return type:
str
- pyeo.raster_manipulation.apply_processing_baseline_offset_correction_to_tiff_file_directory(in_tif_directory, out_tif_directory, bands_to_offset_labels=('B02', 'B03', 'B04', 'B08'), bands_to_offset_index=[0, 1, 2, 3], BOA_ADD_OFFSET=-1000, backup_flag=False)
Offsets data within selected bands from a directory of stacked raster files Overwrites original file - option to save a backup copy.
- Parameters:
in_tif_directory (str) – Path to the input (and output) directory of tif raster files
out_tif_directory (str) – Path to the output directory of tif raster files
bands_to_offset_labels (list of string) – List of bands to offset
bands_to_offset_index (list of int) – List of indices of bands to offset within the tif image
BOA_ADD_OFFSET (int) – Required offset per band (from xml information within L2A SAFE file directory)
backup_flag (True/False) – If True leaves unoffset images with .backup extension in tif_directory
- Returns:
out_tif_directory – The path to the output directory
- Return type:
str
- pyeo.raster_manipulation.apply_scl_cloud_mask(l2_dir, out_dir, scl_classes, buffer_size=0, bands=['B02', 'B03', 'B04', 'B08'], out_resolution=10, haze=None, epsg=None, skip_existing=False)
For every .SAFE folder in l2_dir, creates a cloud-masked raster band for each selected band based on the SCL layer. Applies a rough haze correction based on thresholding the blue band (optional).
- Parameters:
l2_dir (str) – The directory containing a set of L2 .SAFE folders to preprocess
out_dir (str) – The directory to store the preprocessed files
scl_classes (list of int) – values of classes to be masked out
buffer_size (int, optional) – The buffer to apply to the sen2cor mask - defaults to 0
bands (list of str, optional) – List of names of bands to include in the final rasters. Defaults to (“B02”, “B03”, “B04”, “B08”)
out_resolution (number, optional) – Resolution to resample every image to - units are defined by the image projection. Default is 10.
haze (number, optional) – Threshold if a haze filter is to be applied. If specified, all pixel values where “B02” > haze will be masked out. Defaults to None. If set, recommended thresholds range from 325 to 600 but can vary by scene conditions.
epsg (int) – EPSG code of the map projection / CRS if output rasters shall be reprojected (warped)
skip_existing (boolean) – If True, skip cloud masking if a file already exists. If False, overwrite it.
- pyeo.raster_manipulation.apply_sen2cor(image_path, sen2cor_path, delete_unprocessed_image=False, log=<Logger pyeo.raster_manipulation (WARNING)>)
Applies sen2cor to the SAFE file at image_path. Returns the path to the new product.
- Parameters:
image_path (str) – Path to the L1C Sentinel 2 .SAFE file directory
sen2cor_path (str) – Path to the l2a_process script (Linux) or l2a_process.exe (Windows)
delete_unprocessed_image (bool, optional) – If True, delete the unprocessed image after processing is done. Defaults to False.
- Returns:
out_path – The path to the new L2 .SAFE file
- Return type:
str
- pyeo.raster_manipulation.array2raster(raster_file, new_raster_file, array)
Saves the contents of an array to a new raster file and copies the projection from an existing raster file.
- Parameters:
raster_file (str) – Path and file name of the raster file from which the metadata will be copied
new_raster_file (str) – Path and file name of the newly created raster file
array (array) – The array that will be written to new_raster_file
- pyeo.raster_manipulation.atmospheric_correction(in_directory, out_directory, sen2cor_path, delete_unprocessed_image=False, log=<Logger pyeo.raster_manipulation (WARNING)>)
Applies Sen2cor atmospheric correction to each L1C image in in_directory
- Parameters:
in_directory (str) – Path to the directory containing the L1C images
out_directory (str) – Path to the directory that will containg the new L2A images
sen2cor_path (str) – Path to the l2a_process script (Linux) or l2a_process.exe (Windows)
delete_unprocessed_image (bool, optional) – If True, delete the unprocessed image after processing is done. Defaults to False.
log (optional) – if a logger object is provided, atmospheric_correction will pass statements to that logger, otherwise the default namespace logger is used.
- pyeo.raster_manipulation.average_images(raster_paths, out_raster_path, geometry_mode='intersect', format='GTiff', datatype=5)
When provided with a list of rasters, will stack them into a single raster. The number of bands in the output is equal to the total number of bands in the input. Geotransform and projection are taken from the first raster in the list; there may be unexpected behavior if multiple differing projections are provided.
- Parameters:
raster_paths (list of str) – A list of paths to the rasters to be stacked, in order.
out_raster_path (str) – The path to the saved output raster.
geometry_mode ({'intersect' or 'union'}, optional) – Can be either ‘intersect’ or ‘union’. Defaults to ‘intersect’.
'intersect' (- If) –
overlap. (then the output raster will only contain the pixels of the input rasters that) –
'union' (- If) –
0. (then the output raster will contain every pixel in the outputs. Layers without data will have their pixel values set to) –
format (str) – The GDAL image format for the output. Defaults to ‘GTiff’
datatype (gdal datatype) – The datatype of the gdal array - see note. Defaults to gdal.GDT_Int32
- pyeo.raster_manipulation.buffer_mask_in_place(mask_path, buffer_size, cache=None)
Expands a mask in-place, overwriting the previous mask
- Parameters:
mask_path (str) – Path to a multiplicative mask (0; masked, 1; unmasked)
buffer_size (int) – The radius of the buffer, in pixel units of the mask
- pyeo.raster_manipulation.build_sen2cor_output_path(image_path, timestamp, version)
Creates a sen2cor output path dependent on the version of sen2cor
- Parameters:
image_path (str) – Path to the image
timestamp (str) – Timestamp that processing was started (required for v >= 2.8)
version (str) – String of the version of sen2cor (ex “2.05.05”)
- Returns:
new_path – The path of the finished sen2cor file
- Return type:
str
- pyeo.raster_manipulation.calc_ndvi(raster_path, output_path)
Creates a raster of NDVI from the input raster at output_path
- Parameters:
raster_path (str) – Path to a raster with blue, green, red and infrared bands (in that order)
output_path (str) – Path to a location to save the output raster
- pyeo.raster_manipulation.change_from_class_maps(old_class_path, new_class_path, change_raster, change_from, change_to, skip_existing=False)
This function looks for changes from class ‘change_from’ in the composite to any of the ‘change_to_classes’ in the change images. Pixel values are the acquisition date of the detected change of interest or zero.
- Parameters:
old_class_path (str) – Paths to a classification map to be used as the baseline map for the change detection.
new_class_path (str) – Paths to a classification map with a newer acquisition date.
change_raster (str (path to a raster file of type UInt32)) – Path to the output raster file that will be created.
change_from (list of int) – List of integers with the class codes to be used as ‘from’ in the change detection.
change_to (list of int) – List of integers with the class codes to be used as ‘to’ in the change detection.
skip_existing (boolean) – If True, skip the production of files that already exist.
Returns –
---------- –
change_raster – The path to the new change layer containing the acquisition date of the new class image expressed as the difference to the 1/1/2000, where a change has been found, or zero otherwise.
- pyeo.raster_manipulation.clever_composite_directory(image_dir, composite_out_dir, format='GTiff', chunks=10, generate_date_images=False, missing_data_value=0)
- Using clever_composite_images, creates a composite containing every image in image_dir. This will
place a file named composite_[last image date].tif inside composite_out_dir
- Parameters:
image_dir (str) – The directory containing the rasters and associated .msk files to be composited.
composite_out_dir (str) – The directory that will contain the final composite
format (str, optional) – The raster format of the output image. Defaults to ‘GTiff’
generate_date_images (bool, optional) – If true, generates a corresponding date image for the composite. See docs for composite_images_with_mask. Defaults to False.
missing_data_value (int, optional) – Value for no data encoding, will be ignored in calculating the median
- Returns:
composite_out_path – The path to the new composite
- Return type:
str
- pyeo.raster_manipulation.clever_composite_directory_with_masks(image_dir, composite_out_dir, format='GTiff', chunks=10, generate_date_images=False, missing_data_value=0)
- Using clever_composite_images_with_mask, creates a composite containing every image in image_dir. This will
place a file named composite_[last image date].tif inside composite_out_dir
- Parameters:
image_dir (str) – The directory containing the rasters and associated .msk files to be composited.
composite_out_dir (str) – The directory that will contain the final composite
format (str, optional) – The raster format of the output image. Defaults to ‘GTiff’
generate_date_images (bool, optional) – If true, generates a corresponding date image for the composite. See docs for composite_images_with_mask. Defaults to False.
missing_data_value (int, optional) – Value for no data encoding, will be ignored in calculating the median
- Returns:
composite_out_path – The path to the new composite
- Return type:
str
- pyeo.raster_manipulation.clever_composite_images(in_raster_path_list, composite_out_path, format='GTiff', chunks=10, generate_date_image=True, missing_data_value=0)
Works down in_raster_path_list, updating pixels in composite_out_path if not masked. Will also create (optionally) a date image in the same directory. Processes raster stacks by splitting them into a number of chunks to avoid memory allocation errors.
- Parameters:
in_raster_path_list (list[str]) – A list of paths to rasters.
composite_out_path (str) – The path of the output image
format (str, optional) – The gdal format of the image. Defaults to “GTiff”
generate_date_image (bool, optional) – If true, generates a single-layer raster containing the dates of each image detected - see below.
missing_data_value (int, optional) – Value for no data encoding, will be ignored in calculating the median
- Returns:
composite_path – The path to the composite.
- Return type:
str
Notes
If generate_date_images is True, an raster ending with the suffix .date will be created; each pixel will contain the timestamp (yyyymmdd) of the date that pixel was last seen in the composite.
- pyeo.raster_manipulation.clever_composite_images_with_mask(in_raster_path_list, composite_out_path, format='GTiff', chunks=10, generate_date_image=True, missing_data_value=0)
Works down in_raster_path_list, updating pixels in composite_out_path if not masked. Will also create a mask and (optionally) a date image in the same directory. Processes raster stacks by splitting them into a number of chunks to avoid memory allocation errors.
- Parameters:
in_raster_path_list (list of str) – A list of paths to rasters.
composite_out_path (str) – The path of the output image
format (str, optional) – The gdal format of the image. Defaults to “GTiff”
generate_date_image (bool, optional) – If true, generates a single-layer raster containing the dates of each image detected - see below.
missing_data_value (int, optional) – Value for no data encoding, will be ignored in calculating the median
- Returns:
composite_path – The path to the composite.
- Return type:
str
Notes
Masks are assumed to be a multiplicative .msk file with the same path as their corresponding image. All images must have the same number of layers and resolution, but do not have to be perfectly co-registered. If it does not exist, composite_out_path will be created. Takes projection, resolution, etc. from first band of first raster in list. Will reproject images and masks if they do not match initial raster.
If generate_date_images is True, an raster ending with the suffix .date will be created; each pixel will contain the timestamp (yyyymmdd) of the date that pixel was last seen in the composite.
#TODO: Change the date image to contain Julian date numbers.
- pyeo.raster_manipulation.clip_raster(raster_path, aoi_path, out_path, srs_id=4326, flip_x_y=False, dest_nodata=0)
Clips a raster at raster_path to a shapefile given by aoi_path. Assumes a shapefile only has one polygon. Will np.floor() when converting from geo to pixel units and np.absolute() y resolution form geotransform. Will also reproject the shapefile to the same projection as the raster if needed.
- Parameters:
raster_path (str) – Path to the raster to be clipped.
aoi_path (str) – Path to a shapefile containing a single polygon
out_path (str) – Path to a location to save the final output raster
flip_x_y (bool, optional) – If True, swaps the x and y axis of the raster image before clipping. For compatability with Landsat. Default is False.
dest_nodata (number, optional) – The fill value for outside of the clipped area. Defaults to 0.
- pyeo.raster_manipulation.clip_raster_to_intersection(raster_to_clip_path, extent_raster_path, out_raster_path, is_landsat=False)
Clips one raster to the extent provided by the other raster, and saves the result at temp_file. Assumes both raster_to_clip and extent_raster are in the same projection.
- Parameters:
raster_to_clip_path (str) – The location of the raster to be clipped.
extent_raster_path (str) – The location of the raster that will provide the extent to clip to
out_raster_path (str) – A location for the finished raster
- pyeo.raster_manipulation.combine_date_maps(date_image_paths, output_product)
- Combines all change date layers into one output raster with two layers:
pixels show the earliest change detection date (expressed as the number of days since 1/1/2000)
pixels show the number of change detection dates (summed up over all change images in the folder)
- Parameters:
date_image_paths (list of strings) – Containing the full directory paths to the input files with the detection dates as pixel values in UInt32 format
output_product (string) – The string containing the full directory path to the output file for the 2-layer raster file
- Returns:
output_product – The string containing the full directory path to the output file for the 2-layer raster file
- Return type:
string
- pyeo.raster_manipulation.combine_masks(mask_paths, out_path, combination_func='and', geometry_func='intersect')
ORs or ANDs several masks. Gets metadata from top mask. Assumes that masks are a Python true or false. Also assumes that all masks are the same projection for now.
- Parameters:
mask_paths (list of str) – A list of paths to the masks to combine
out_path (str) – The path to the new mask
combination_func ({'and' or 'or}, optional) – Whether the a pixel in the final mask will be masked if - any pixel (‘or’) is masked - or all pixels (‘and’) are masked ..in the corresponding pixels in the list of masks. Defaults to ‘and’
geometry_func ({'intersect' or 'union'}) – How to handle non-overlapping masks. Defaults to ‘intersect’
- Returns:
out_path – The path to the new mask
- Return type:
str
- pyeo.raster_manipulation.composite_directory(image_dir, composite_out_dir, format='GTiff', generate_date_images=False)
- Using composite_images_with_mask, creates a composite containing every image in image_dir. This will
place a file named composite_[last image date].tif inside composite_out_dir
- Parameters:
image_dir (str) – The directory containing the rasters and associated .msk files to be composited.
composite_out_dir (str) – The directory that will contain the final composite
format (str, optional) – The raster format of the output image. Defaults to ‘GTiff’
generate_date_images (bool, optional) – If true, generates a corresponding date image for the composite. See docs for composite_images_with_mask. Defaults to False.
- Returns:
composite_out_path – The path to the new composite
- Return type:
str
- pyeo.raster_manipulation.composite_images_with_mask(in_raster_path_list, composite_out_path, format='GTiff', generate_date_image=True)
Works down in_raster_path_list, updating pixels in composite_out_path if not masked. Will also create a mask and (optionally) a date image in the same directory.
- Parameters:
in_raster_path_list (list of str) – A list of paths to rasters.
composite_out_path (str) – The path of the output image
format (str, optional) – The gdal format of the image. Defaults to “GTiff”
generate_date_image (bool, optional) – If true, generates a single-layer raster containing the dates of each image detected - see below.
- Returns:
composite_path – The path to the composite.
- Return type:
str
Notes
Masks are assumed to be a multiplicative .msk file with the same path as their corresponding image; see REFERENCE. All images must have the same number of layers and resolution, but do not have to be perfectly on top of each other. If it does not exist, composite_out_path will be created. Takes projection, resolution, etc. from first band of first raster in list. Will reproject images and masks if they do not match initial raster.
If generate_date_images is True, an raster ending with the suffix .date will be created; each pixel will contain the timestamp (yyyymmdd) of the date that pixel was last seen in the composite.
- pyeo.raster_manipulation.compress_tiff(in_path, out_path)
Compresses a Geotiff file using gdal.
- Parameters:
in_path (str) – The path to the input GeoTiff file.
out_path (str) – The path to the output GeoTiff file.
- pyeo.raster_manipulation.create_mask_from_band(in_raster_path, out_path, band, threshold, relation='smaller', buffer_size=0, out_resolution=None)
Creates a multiplicative mask from a classification mask: 1 for each pixel containing one of classes_of_interest, otherwise 0
- Parameters:
in_raster_path (str) – Path to the raster file to build the mask from
out_path (str) – Path to the new mask
band (number) – Number of the band in the raster file to be used to create the mask, starting with band 1
threshold (number) – Threshold to be applied when creating the mask
relation (str) – Relationship to be applied to the threshold, can be that pixels are “smaller” or “greater” than the threshold to be set to 1.
buffer_size (int) – If greater than 0, applies a buffer to the masked pixels of this size. Defaults to 0.
out_resolution (int or None, optional) – If present, resamples the mask to this resolution. Applied before buffering. Defaults to 0.
- Returns:
out_path – The path to the new mask.
- Return type:
str
- pyeo.raster_manipulation.create_mask_from_class_map(class_map_path, out_path, classes_of_interest, buffer_size=0, out_resolution=None)
Creates a multiplicative mask from a classification mask: 1 for each pixel containing one of classes_of_interest, otherwise 0
- Parameters:
class_map_path (str) – Path to the classification map to build the mask from
out_path (str) – Path to the new mask
classes_of_interest (list of int) – The list of classes to count as clear pixels
buffer_size (int) – If greater than 0, applies a buffer to the masked pixels of this size. Defaults to 0.
out_resolution (int or None, optional) – If present, resamples the mask to this resoltion. Applied before buffering. Defaults to 0.
- Returns:
out_path – The path to the new mask.
- Return type:
str
- pyeo.raster_manipulation.create_mask_from_confidence_layer(l2_safe_path, out_path, cloud_conf_threshold=0, buffer_size=3)
Creates a multiplicative binary mask where cloudy pixels are 0 and non-cloudy pixels are 1. If cloud_conf_threshold = 0, use scl mask else use confidence image
- Parameters:
l2_safe_path (str) – Path to the L1
out_path (str) – Path to the new path
cloud_conf_threshold (int, optional) – If 0, uses the sen2cor classification raster as the base for the mask - else uses the cloud confidence image. Defaults to 0
buffer_size (int, optional) – The size of the buffer to apply to the cloudy pixel classes
- Returns:
out_path – The path to the mask
- Return type:
str
- pyeo.raster_manipulation.create_mask_from_fmask(in_l1_dir, out_path)
Creates a cloud mask from a level 1 Sentinel-2 product using fmask
- Parameters:
in_l1_dir (str) – The path to the l1 .SAFE folder
out_path (str) – The path to new mask
- pyeo.raster_manipulation.create_mask_from_model(image_path, model_path, model_clear=0, num_chunks=10, buffer_size=0)
Returns a multiplicative mask (0 for cloud, shadow or haze, 1 for clear) built from the ML at model_path.
- Parameters:
image_path (str) – Path to the image
model_path (str) – Path to a pickled scikit-learn classification model
model_clear (int, optional) – The class from the model corresponding to non-cloudy pixels. Defaults to 0
num_chunks (int, optional) – The number of chunks to break the processing into. See
classification.classify_image()
buffer_size (int, optional) – If present, will apply a buffer of this many pixels to the mask, expanding
- Returns:
mask_path – The path to the new mask
- Return type:
str
- pyeo.raster_manipulation.create_mask_from_scl_layer(l2_safe_path, out_path, scl_classes, buffer_size=0)
Creates a multiplicative binary mask where pixels of class scl_class are set to 0 and other pixels are 1.
- Parameters:
l2_safe_path (str) – Path to the L1
out_path (str) – Path to the new path
scl_classes (list of int) – Class values of the SCL scene classification layer to be set to 0
buffer_size (int, optional) – The size of the buffer to apply around the masked out pixels (dilation)
- Returns:
out_path – The path to the mask
- Return type:
str
Notes
The SCL codes correspond to the following classification labels:
0: NO_DATA
1: SATURATED_OR_DEFECTIVE
2: DARK_AREA_PIXELS
3: CLOUD_SHADOWS
4: VEGETATION
5: NOT_VEGETATED
6: WATER
7: UNCLASSIFIED
8: CLOUD_MEDIUM_PROBABILITY
9: CLOUD_HIGH_PROBABILITY
10: THIN_CIRRUS
11: SNOW
- pyeo.raster_manipulation.create_mask_from_sen2cor_and_fmask(l1_safe_file, l2_safe_file, out_mask_path, buffer_size=0)
Creates a cloud mask from a combination of the sen2cor thematic mask and the fmask method. Requires corresponding level 1 and level 2 .SAFE files.
- Parameters:
l1_safe_file (str) – Path to the level 1 .SAFE file
l2_safe_file (str) – Path to the level 2 .SAFE file
out_mask_path (str) – Path to the new mask
buffer_size (int, optional) – If greater than 0, the buffer to apply to the Sentinel 2 thematic map
- pyeo.raster_manipulation.create_matching_dataset(in_dataset: Dataset, out_path: str, format: str = 'GTiff', bands: int = 1, datatype=None)
Creates an empty gdal dataset with the same dimensions, projection and geotransform as in_dataset. Defaults to 1 band. Datatype is set from the first layer of in_dataset if unspecified.
- Parameters:
in_dataset (gdal.Dataset) – A gdal.Dataset object
out_path (str) – The path to save the copied dataset to
format (str, optional) – The Gdal image format. Defaults to geotiff (“GTiff”); for a full list, see https://gdal.org/drivers/raster/index.html
bands (int, optional) – The number of bands in the dataset. Defaults to 1.
datatype (gdal constant, optional) – The datatype of the returned dataset. See the introduction for this module. Defaults to in_dataset’s datatype if not supplied.
- Returns:
new_dataset – An gdal.Dataset of the new, empty dataset that is ready for writing.
- Return type:
gdal.Dataset
Warning
The default of bands=1 will be changed to match the input dataset in the next release of pyeo
- pyeo.raster_manipulation.create_new_image_from_polygon(polygon, out_path, x_res, y_res, bands, projection, format='GTiff', datatype=5, nodata=0)
Returns an empty image that covers the extent of the input polygon.
- Parameters:
polygon (ogr.Geometry) – An OGR.Geometry object of a single polygon
out_path (str) – The path to save the new image to
x_res (number) – Pixel width in the new image
y_res (number) – Pixel height in the new image
bands (int) – Number of bands in the new image.
projection (str) – The projection, in wkt, of the output image.
format (str, optional) – The gdal raster format of the output image. Defaults to “Gtiff”
datatype (gdal datatype, optional) – The gdal datatype of the output image. Defaults to gdal.GDT_Int32
- Return type:
A gdal.Image object
- pyeo.raster_manipulation.create_new_stacks(image_dir, stack_dir)
For each granule present in image_dir Saves the result in stacked_dir. Assumes that each image in image_dir is saved with a Sentinel-2 identifier name - see merge_raster.
- Parameters:
image_dir (str) – A path to the directory containing the images to be stacked, all named as Sentinel 2 identifiers
stack_dir (str) – A path to a directory to save the stacked images to.
- Returns:
new_stacks – A list of paths to the new stacks
- Return type:
list of str
Notes
The pairing algorithm is as follows: Step 1: Group directory by tile number Step 2: For each tile number, sort by time Step 3: For each image in the sorted list, stack each image with it’s next oldest image.
- Raises:
CreateNewStacksException – If the image directory is empty
- pyeo.raster_manipulation.create_quicklook(in_raster_path, out_raster_path, width, height, format='PNG', bands=[1, 2, 3], nodata=None, scale_factors=None)
Creates a quicklook image of reduced size from an input GDAL object and saves it to out_raster_path.
- Parameters:
in_raster_path (string) – The string containing the full directory path to the input file for the quicklook
out_raster_path (string) – The string containing the full directory path to the output file for the quicklook
width (number) – Width of the output raster in pixels
height (number) – Height of the output raster in pixels
format (string, optional) – GDAL format for the quicklook raster file, default PNG
bands (list of numbers) – List of the band numbers to be displayed as RGB. Will be ignored if only one band is in the image raster.
nodata (number (optional)) – Missing data value.
- Returns:
out_raster_path – The output path of the generated quicklook raster file
- Return type:
string
- pyeo.raster_manipulation.filter_by_class_map(image_path, class_map_path, out_map_path, classes_of_interest, out_resolution=10, invert=False)
Filters a raster with a set of classes for corresponding for pixels in filter_map_path containing only classes_of_interest. Assumes that filter_map_path and class_map_path are same resolution and projection.
- Parameters:
image_path (str) – Path to the raster to be filtered.
class_map_path (str) – Path to the map to use as the filter. Assumes a raster of integer class labels.
out_map_path (str) – Path to the filtered map
classes_of_interest (list of int) – The classes in class_map_path to keep present in the raster to be filtered
out_resolution (number, optional) – The resolution of the output image
invert (bool, optional) – If present, invert mask (ie filter out classes_of_interest)
- Returns:
out_map_path – The path to the new map
- Return type:
str
- pyeo.raster_manipulation.find_small_safe_dirs(path, threshold=629145600)
Quickly finds all subdirectories ending with “.SAFE” or “.safe” and logs a warning if the directory size is less than a threshold, 600 MB by default. This indicates incomplete downloads
Returns a list of all paths to the SAFE directories that are smaller than the threshold and a list of all sizes.
- pyeo.raster_manipulation.flatten_probability_image(prob_image, out_path)
Takes a probability output from classify_image and flattens it into a single layer containing only the maximum value from each pixel.
- Parameters:
prob_image (str) – The path to a probability image.
out_path (str) – The place to save the flattened image.
- pyeo.raster_manipulation.get_array(raster)
Returns a numpy array for the raster.
- Parameters:
raster (gdal.Dataset) – A gdal.Dataset object
- Returns:
array – A numpy array of the raster
- Return type:
numpy array
- pyeo.raster_manipulation.get_dir_size(path='.')
Gets the size of all contents of a directory.
- pyeo.raster_manipulation.get_extent_as_shp(in_ras_path, out_shp_path)
Gets the extent of a raster as a shapefile
- Parameters:
in_ras_path (str) – The raster to get
out_shp_path (str) – The shape path
- Returns:
out_shp_path – The path to the new shapefile
- Return type:
str
- pyeo.raster_manipulation.get_file_sizes(dir_path)
Gets all file sizes in bytes from the files contained in dir_path and its subdirs.
- Parameters:
dir_path (str) – Paths to the files.
- Returns:
results – Dictionary containing the results of the function.
- Return type:
dictionary
- pyeo.raster_manipulation.get_image_resolution(image_path)
Returns the resolution of the image in its native projection. Assumes square pixels.
- Parameters:
image_path (str) – Path to a raster
- Returns:
resolution – The size of each pixel in the image, in the units of its native projection.
- Return type:
number
- pyeo.raster_manipulation.get_masked_array(raster, mask_path)
Returns a numpy.mask masked array for the raster. Masked pixels are FALSE in the mask image (multiplicateive map), but TRUE in the masked_array (nodata pixels). If the raster is multi-band and the mask is single-band, the mask will be applied to every raster.
- Parameters:
raster (gdal.Dataset) – A gdal.Dataset object
mask_path (str) – The path to the mask to use
- Returns:
masked_array – A numpy.masked array of the raster.
- Return type:
numpy.masked
- pyeo.raster_manipulation.get_sen2cor_version(sen2cor_path)
Gets the version number of sen2cor from the help string.
- Parameters:
sen2cor_path (str) – Path to the sen2cor executable
- Returns:
version – A string of the version of sen2cor at sen2cor_path
- Return type:
str
- pyeo.raster_manipulation.get_sen_2_band_path(safe_dir, band, resolution=None)
Returns the path to the raster of the specified band in the specified safe_dir.
- Parameters:
safe_dir (str) – Path to the directory containing the raster
band (str) – The band identifier (‘B01’, ‘B02’, ect)
resolution (int, optional) – If given, tries to get that band in that image - if not, tries for the highest resolution
- Returns:
band_path – The path to the raster containing the band.
- Return type:
str
- pyeo.raster_manipulation.get_stats_from_raster_file(in_raster_path, format='GTiff', missing_data_value=0)
Gets simple statistics from a raster file and prints them to the log file
- Parameters:
in_raster_path (str) – A path to a raster file
format (str, optional) – The gdal format of the image. Defaults to “GTiff”
missing_data_value (int, optional) – The encoding of missing values in the raster that will be omitted from the calculations
- Returns:
result – Dictionary containing the results of the function
- Return type:
dictionary
- pyeo.raster_manipulation.mosaic_images(raster_path, out_raster_path, format='GTiff', datatype=5, nodata=0)
Mosaics multiple images in the directory raster_path with the same number of layers into one single image. Overwrites overlapping pixels with the value furthest down raster_paths. Takes projection from the first raster. The output mosaic file will have a name that contains all unique tile IDs and the earliest and latest acquisition date and time from the raster file names.
- Parameters:
raster_path (str) – The directory path containing all Geotiff rasters to be mosaiced (all having the same number of bands)
out_raster_path (str) – The path to the output directory for the new mosaic file
format (str) – The image format of the output raster. Defaults to ‘GTiff’
datatype (gdal datatype) – The datatype of the output raster. Defaults to gdal.GDT_Int32
nodata (number) – The input nodata value; any pixels in raster_paths with this value will be ignored. Defaults to 0.
- pyeo.raster_manipulation.open_dataset_from_safe(safe_file_path, band, resolution='10m')
Opens a dataset given a level 2 .SAFE file.
- Parameters:
safe_file_path (str) – The path to the .SAFE file
band (int) – The band to open
resolution ({'10m', '20m', '60m'}, optional) – The resolution of imagery to open. Defaults to “10m”.
- Returns:
band_raster – A Gdal dataset contining the band
- Return type:
gdal.Dataset
- pyeo.raster_manipulation.preprocess_landsat_images(image_dir, out_image_path, new_projection=None, bands_to_stack=('B2', 'B3', 'B4'))
Stacks a set of Landsat images into a single raster and reorders the bands into [bands, y, x] - by default, Landsat uses [x,y] and bands are in seperate rasters. If given, will also reproject to an EPSG or .wkt
- Parameters:
image_dir (str) – The directory containing the Landsat images
out_image_path (str) – The path to the stacked image
new_projection (int or str, optional) – An EPSG number or a .wkt containing a projection. Defaults to None
bands_to_stack (list of str, optional) – The Landsat bands to put into the stacked
- pyeo.raster_manipulation.preprocess_sen2_images(l2_dir, out_dir, l1_dir, cloud_threshold=60, buffer_size=0, epsg=None, bands=('B02', 'B03', 'B04', 'B08'), out_resolution=10)
For every .SAFE folder in l2_dir and L1_dir, merges the rasters of bands 2,3,4 and 8 into a single geotiff file, creates a cloudmask from the combined fmask and sen2cor cloudmasks and reprojects to a given EPSG if provided.
- Parameters:
l2_dir (str) – The directory containing a set of L2 .SAFE folders to preprocess
out_dir (str) – The directory to store the preprocessed files
l1_dir (str) – The directory containing a set of L1 .SAFE files, corresponding to the L2 files in l2_dir
cloud_threshold (number) – DEPRECIATED; in for backwards compatibility.
buffer_size (int, optional) – The buffer to apply to the sen2cor mask - defaults to 0
epsg (int, optional) – If present, the EPSG number to reproject the final images to.
bands (list of str, optional) – List of names of bands to include in the final rasters. Defaults to (“B02”, “B03”, “B04”, “B08”)
out_resolution (number, optional) – Resolution to resample every image to - units are defined by the image projection. Default is 10.
Warning
This functions’ augment list is likely to be changed in the near future to (l1_dir, l2_dir, out_dir) - please be aware - September 2020.
- pyeo.raster_manipulation.raster2array(raster_file)
Loads the contents of a raster file into an array.
- Parameters:
raster_file (str) – Path and file name of the raster file
- pyeo.raster_manipulation.raster_sum(inRstList, outFn, outFmt='GTiff')
Creates a raster stack from a list of rasters. Adapted from Chris Gerard’s book ‘Geoprocessing with Python’. The output data type is the same as the input data type.
- Parameters:
inRstList (list of str) – List of rasters to stack.
outFn (str) – Filename output as str including directory else image will be written to current working directory.
outFmt (str, optional.) – String specifying the input data format e.g. ‘GTiff’ or ‘VRT’. Defaults to GTiff.
- pyeo.raster_manipulation.raster_to_array(rst_pth)
Reads in a raster file and returns a N-dimensional array.
- Parameters:
rst_pth (str) – Path to input raster.
- Returns:
out_array – An N-dimensional array.
- Return type:
array_like
- pyeo.raster_manipulation.reproject_directory(in_dir, out_dir, new_projection, extension='.tif')
Reprojects every file ending with extension to new_projection and saves in out_dir
- Parameters:
in_dir (str) – A directory containing the rasters to be reprojected/
out_dir (str) – The directory to save the output files to. Output files will be saved in out_dir, with the same filenames.
new_projection (str) – The new projection in wkt.
extension (str, optional) – The file extension to reproject. Default is ‘.tif’
- pyeo.raster_manipulation.reproject_image(in_raster, out_raster_path, new_projection, driver='GTiff', memory=2000.0, do_post_resample=True)
Creates a new, reprojected image from in_raster using the gdal.ReprojectImage function.
- Parameters:
in_raster (str or gdal.Dataset) – Either a gdal.Dataset object or a path to a raster
out_raster_path (str) – The path to the new output raster.
new_projection (str or int) – The new projection in .wkt or as an EPSG number
driver (str, optional) – The format of the output raster.
memory (float, optional) – The amount of memory to give to the reprojection. Defaults to 2e3
do_post_resample (bool, optional) – If set to false, do not resample the image back to the original projection. Defaults to True
Notes
The GDAL reprojection routine changes the size of the pixels by a very small amount; for example, a 10m pixel image can become a 10.002m pixel resolution image. To stop alignment issues, by default this function resamples the images back to their original resolution. If you are reprojecting from latlon to meters and get an outofmemory error from Gdal, set do_post_resample to False.
- pyeo.raster_manipulation.resample_image_in_place(image_path, new_res)
Resamples an image in-place using gdalwarp to new_res in metres. WARNING: This will make a permanent change to an image! Use with care.
- Parameters:
image_path (str) – Path to the image to be resampled
new_res (number) – Pixel edge size in meters
- pyeo.raster_manipulation.save_array_as_image(array, path, geotransform, projection, format='GTiff')
Saves a given array as a geospatial image to disk in the format ‘format’. The datatype will be of one corresponding to Array must be gdal format: [bands, y, x].
- Parameters:
array (array_like) – A Numpy array containing the values to be saved to a raster
path (str) – The path to the location to save the output raster to
geotransform (list) – The geotransform of the image to be saved. See note.
projection (str) – The projection, as wkt, of the image to be saved. See note.
format (str, optional) – The image format. Defaults to ‘GTiff’; see note for other types.
- Returns:
path_to_image – The path to the image
- Return type:
str
- pyeo.raster_manipulation.scale_to_uint8(x, percentiles=[0, 100])
Scales an array to the range from 0-255 and converts the data type to uint8. NaN values will be ignored.
- Parameters:
array (x = input) –
histogram (percentiles = list of length 2 of percentiles for trimming the) –
- Returns:
Scaled array of uint8 data type
- pyeo.raster_manipulation.sieve_directory(in_dir, out_dir=None, neighbours=8, sieve=10, out_type='GTiff', skip_existing=False)
Sieves all class images ending in .tif in in_dir using gdal. Outputs are saved out_dir.
- Parameters:
in_dir (str) – The path to the directory containing the class image files.
out_dir (str) – The directory that will store the sieved class image files
neighbours (int) – Number of neighbouring pixels at sieve stage. Can be 4 or 8.
sieve (int) – Number of pixels in a class polygon. Only polygons below this threshold will be removed. See GDAL Sieve documentation.
out_type (str, optional) – The raster format of the class image. Defaults to “GTiff” (geotif). See gdal docs for valid datatypes.
skip_existing (boolean, optional) – If True, skips the classification if the output file already exists.
Returns –
-------- –
out_image_paths (list of str) – A list with all paths to the sieved class image files, including those that already existed.
- pyeo.raster_manipulation.sieve_image(image_path, out_path, neighbours=8, sieve=10, skip_existing=False)
Sieves a class image using gdal. Output is saved out_path.
- Parameters:
image_path (str) – The path to the class image file with a single band.
out_path (str) – The path to the output file that will store the sieved class image.
neighbours (int) – Number of neighbouring pixels at sieve stage. Can be 4 or 8.
sieve (int) – Number of pixels in a class polygon. Only polygons below this threshold will be removed. See GDAL Sieve documentation.
skip_existing (boolean, optional) – If True, skips the classification if the output file already exists.
- pyeo.raster_manipulation.stack_and_trim_images(old_image_path, new_image_path, aoi_path, out_image)
Stacks an old and new S2 image and trims to within an aoi.
- Parameters:
old_image_path (str) – Path to the image that will be the first set of bands in the output image
new_image_path (str) – Path to the image that will be the second set of bands in the output image
aoi_path (str) – Path to a shapefile containing the AOI
out_image (str) – Path to the location of the clipped and stacked image.
- pyeo.raster_manipulation.stack_image_with_composite(image_path, composite_path, out_dir, create_combined_mask=True, skip_if_exists=True, invert_stack=False)
Creates a single 8-band geotif image with a cloud-free composite and an image, and saves the result in out_dir. Output images are named “composite_tile_timestamp-of-composite_timestamp-of-image”. Bands 1,2,3 and 4 are the B,G,R and NIR bands of the composite, and bands 5,6,7 and 8 are the B,G,R and NIR bands of the image.
- Parameters:
image_path (str) – Path to the image to be stacked
composite_path (str) – Path to the composite to stack the image with
out_dir (str) – The directory to save the resulting composite to
create_combined_mask (bool, optional) – If true, combines the cloud mask files associated with the images into a single mask. The mask will mask out clouds that exist in either image. Defaults to True.
skip_if_exists (bool, optional) – If true, skip stacking if a file with the same name is found. Defaults to True.
invert_stack (bool, optional.) – If true, changes the ordering of the bands to image BGRI - composite BGRI. Included to permit compatibility with older models - you can usually leave this alone.
- Returns:
out_path – The path to the new composite.
- Return type:
str
- pyeo.raster_manipulation.stack_images(raster_paths, out_raster_path, geometry_mode='intersect', format='GTiff', datatype=5, nodata_value=0)
When provided with a list of rasters, will stack them into a single raster. The number of bands in the output is equal to the total number of bands in the input raster. Geotransform and projection are taken from the first raster in the list; there may be unexpected behaviour if multiple differing projections are provided.
- Parameters:
raster_paths (list of str) – A list of paths to the rasters to be stacked, in order.
out_raster_path (str) – The path to the saved output raster.
geometry_mode ({'intersect' or 'union'}) – Can be either ‘intersect’ or ‘union’.
'intersect' (- If) –
overlap. (then the output raster will only contain the pixels of the input rasters that) –
'union' (- If) – have their pixel values set to 0.
will (then the output raster will contain every pixel in the outputs. Layers without data) – have their pixel values set to 0.
format (str, optional) – The GDAL image format for the output. Defaults to ‘GTiff’
datatype (gdal datatype, optional) – The datatype of the gdal array - see introduction. Defaults to gdal.GDT_Int32.
- pyeo.raster_manipulation.stack_old_and_new_images(old_image_path, new_image_path, out_dir, create_combined_mask=True)
Stacks two images that cover the same tile into a single multi-band raster, old_image_path being the first set of bands and new_image_path being the second. The produced image will have the name {tile}_{old_date}_{new_date}.tif.
- Parameters:
old_image_path (str) – Path to the older image
new_image_path (str) – Path to the newer image
out_dir (str) – Directory to place the new stacked raster into
create_combined_mask (bool, optional) – If True, finds and combines the associated mask files between
- Returns:
out_image_path – The path to the new image
- Return type:
str
- pyeo.raster_manipulation.stack_sentinel_2_bands(safe_dir, out_image_path, bands=('B02', 'B03', 'B04', 'B08'), out_resolution=10)
Stacks the specified bands of a .SAFE granule directory into a single geotiff
- Parameters:
safe_dir (str) – Path to the .SAFE file to stack
out_image_path (str) – Location of the new image
bands (list of str, optional) – The band IDs to be stacked
out_resolution – The final resolution of the geotif- bands will be resampled if needed.
- Returns:
out_image_path – The path to the new image
- Return type:
str
- pyeo.raster_manipulation.strip_bands(in_raster_path, out_raster_path, bands_to_strip)
Removes bands from a raster and saves a copy.
- Parameters:
in_raster_path (str) – Path to the raster
out_raster_path (str) – Path to the output
bands_to_strip (list of int) – 0-indexed list of bands to remove
- Returns:
out_path – The path to the output
- Return type:
str
- pyeo.raster_manipulation.trim_image(in_raster_path, out_raster_path, polygon, format='GTiff')
Trims a raster to a polygon.
- Parameters:
in_raster_path (str) – Path to the imput raster
out_raster_path (str) – Path of the output raster
polygon (ogr.Geometry) – A ogr.Geometry containing a single polygon
format (str) – Image format of the output raster. Defaults to ‘GTiff’.
- pyeo.raster_manipulation.update_composite_with_images(composite_in_path, in_raster_path_list, composite_out_path, format='GTiff', generate_date_image=True, missing=0)
Works down in_raster_path_list, updating pixels in composite_out_path if not masked. Will also create a mask and (optionally) a date image in the same directory.
- Parameters:
composite_in_path (str) – The path of the input composite image to be updated
in_raster_path_list (list of str) – A list of paths to rasters.
composite_out_path (str) – The path of the output image
format (str, optional) – The gdal format of the image. Defaults to “GTiff”
generate_date_image (bool, optional) – If true, generates a single-layer raster containing the dates of each image detected - see below.
missing (missing value to be ignored, 0 by default) –
- Returns:
composite_path (str) – The path to the composite.
Notes
If generate_date_images is True, an raster ending with the suffix .date will be created; each pixel will contain the
timestamp (yyyymmdd) of the date that pixel was last seen in the composite.
- pyeo.raster_manipulation.verify_change_detections(class_map_paths, out_path, classes_of_interest, buffer_size=0, out_resolution=None)
Verifies repeated change detections from subsequent class maps. Reads in a list of classification masks where 1 shows pixels containing a change class and adds them up. Classification maps are sorted by timestamp in the file name. The result is a raster file that contains a number from 0 (no change detected) to n (number of mask files) where n is the greatest confidence in the change detection.
- Parameters:
class_map_paths (list of str) – List of paths to the classification maps to build the mask from
out_path (str) – Path to the new raster file containing the confidence layer
classes_of_interest (list of int) – The list of classes to count as clear pixels
buffer_size (int) – If greater than 0, applies a buffer to the masked pixels of this size. Defaults to 0.
out_resolution (int or None, optional) – If present, resamples the mask to this resolution. Applied before buffering. Defaults to 0.
- Returns:
out_path – The path to the new mask.
- Return type:
str
- pyeo.raster_manipulation.write_n_band_tiff(tiff_paths: list, output_path: str) None
This function takes a list of tiff paths and merges the tiffs into a single n-band image.
- Parameters:
tiff_paths (list) – List of tiff input images to merge
output_path (str) – The path to the output GeoTiff file.