satproc package

Subpackages

Submodules

satproc.chips module

satproc.chips.extract_chips(rasters, aoi=None, labels=None, label_property='class', masks={'extent'}, mask_type='class', extent_no_border=False, rescale_mode=None, rescale_range=None, bands=None, chip_type='tif', write_footprints=False, classes=None, crs=None, skip_existing=True, within=False, windows_mode='whole_overlap', skip_low_contrast=False, skip_with_empty_mask=True, *, size, step_size, output_dir)[source]
satproc.chips.extract_chips_from_raster(raster, rescale_mode=None, rescale_range=None, bands=None, chip_type='tif', write_footprints=False, labels=None, label_property='class', mask_type='class', masks={'extent'}, classes=None, crs=None, skip_existing=True, within=False, aoi_poly=None, polys_dict=None, windows_mode='whole_overlap', skip_low_contrast=False, skip_with_empty_mask=True, extent_no_border=False, *, size, step_size, output_dir)[source]
satproc.chips.get_shape(feature)[source]

Get shape geometry from feature

Parameters

feature (dict) – Feature as read from Fiona

Return type

shapely.geometry.BaseGeometry

satproc.chips.prepare_aoi_shape(aoi)[source]
satproc.chips.write_image(img, path, *, percentiles=None, skip_low_contrast=False)[source]
satproc.chips.write_tif(img, path, *, skip_low_contrast=False, window, meta, transform, bands)[source]

satproc.filter module

satproc.filter.filter_by_max_prob(input_dir, output_dir, threshold)[source]
satproc.filter.filter_chip(src, *, threshold, output_dir)[source]
satproc.filter.get_max_prob(p)[source]

satproc.histogram module

satproc.histogram.match_histograms(src_path, dst_path, size=128, step_size=128, *, reference_path)[source]

Match histograms of an image using another one as reference

Parameters
  • src_path (str) – path to input raster

  • dst_path (str) – path to output raster

  • size (int) – size of windows

  • step_size (int) – step size, when sliding windows

  • reference_path (str) – path to the reference raster

Return type

None

satproc.histogram.read_window(ds, window)[source]

Read from a rasterio dataset using a window

NaNs are coerced to zero.

Parameters
  • ds (rasterio.Dataset) – input dataset

  • window (rasterio.windows.Window) – window to read from

Returns

image data on window

Return type

numpy.ndarray

satproc.histogram.write_window(img, ds, window)[source]

Write array to raster on window

Parameters
  • img (numpy.ndarray) – image array

  • ds (rasterio.Dataset) – dataset to write to (must be opened with write access)

  • window (rasterio.windows.Window) – window to write to

Return type

None

satproc.masks module

satproc.masks.all_masks_empty(masks)[source]

Check if all masks are empty

satproc.masks.classify_polygons(labels, label_property, classes)[source]
satproc.masks.make_masks(rasters, *, output_dir, labels, label_property='class', classes=None, mask_type='class', masks={'extent'}, extent_no_border=False)[source]
satproc.masks.mask_from_polygons(polygons, *, win, t, extent_no_border=True, boundary_mask=None, distance_mask=None)[source]

Generate a binary mask array from a set of polygon

It can also generate a distance transform mask

Parameters
  • polygons (List[Union[Polygon, MultiPolygon]]) – list of polygon or multipolygon geometries

  • win (rasterio.windows.Window) – window

  • t (rasterio.transform.Affine) – affine transform

  • extent_no_border (bool) – if True, the extent mask will not include the border of the polygon

  • boundary_mask (bool) – whether to generate boundary (edges) mask

  • distance_mask (bool) – whether to generate a distance mask

Return type

numpy.ndarray

satproc.masks.multiband_chip_mask_by_classes(classes, transform, window, label_property, polys_dict=None, label_path=None, extent_mask_path=None, boundary_mask_path=None, distance_mask_path=None, extent_no_border=False)[source]
satproc.masks.prepare_label_shapes(labels, mask_type='class', label_property='class', classes=None)[source]
satproc.masks.write_window_masks(masks, *, window, metadata, transform)[source]

Write window masks to files

satproc.scale module

satproc.scale.get_min_max(img, window_size=512)[source]

Return minimum and maximum values on array, in blocks

Parameters
  • img (numpy.ndarray) – image array

  • window_size (int) – size of window (default: 512)

Returns

minimum and maximum values

Return type

Tuple[float, float]

satproc.scale.minmax_scale(img, *, min_values, max_values)[source]

Scale bands of image separately, to range 0..1

Parameters
  • img (numpy.ndarray) – image array

  • min_values (List[float]) – minimum values for each band

  • max_values (List[float]) – maximum values for each band

Returns

rescaled image

Return type

numpy.ndarray

satproc.scale.scale(input_img, output_img, window_size=512)[source]

Read a raster, rescale each band with min-max values, and save as another raster

Parameters
  • input_img (str) – path to input image

  • output_img (str) – path to output image

  • window_size (int) – size of window

Return type

None

satproc.utils module

satproc.utils.build_virtual_raster(image_paths, output_path, separate=None, band=None)[source]
satproc.utils.fiona_crs_from_proj_crs(proj_crs)[source]
satproc.utils.get_raster_band_count(path)[source]

Get raster band count

Parameters

path (str) – path of the raster image

Returns

band count

Return type

int

satproc.utils.grouper(iterable, n, fillvalue=None)[source]

Collect data into fixed-length chunks or blocks

satproc.utils.map_with_threads(items, worker, num_jobs=None, total=None, desc=None)[source]

Map a worker function to an iterable of items, using a thread pool

Parameters
  • items (iterable) – items to map

  • worker (Function) – worker function to apply to each item

  • num_jobs (int) – number of threads to use

  • total (int (optional)) – total number of items (for the progress bar)

  • desc (str (optional)) – description of the task (for the progress bar)

Return type

None

satproc.utils.proj_crs_from_fiona_dataset(fio_ds)[source]
satproc.utils.reproject_shape(shp, from_crs, to_crs, project=None)[source]

Reproject a shape from from_crs to to_crs

Parameters
  • shp (Shape) – shape to reproject

  • from_crs (str) – CRS epsg code of shape geometry

  • to_crs (str) – CRS epsg code of reprojected shape geometry

  • project (Optional[str]) – a Transformer instance to use for reprojection

Returns

reprojected shape

Return type

Shape

satproc.utils.rescale_intensity(image, rescale_mode, rescale_range)[source]

Calculate percentiles from a range cut and rescale intensity of image to byte range

Parameters
  • image (numpy.ndarray) – image array

  • rescale_mode (str) – rescaling mode, either ‘percentiles’ or ‘values’

  • rescale_range (Tuple[number, number]) – input range for rescaling

Returns

rescaled image

Return type

numpy.ndarray

satproc.utils.run_command(cmd, quiet=True, *, cwd=None)[source]

Run a shell command

Parameters
  • cmd (str) – command to run

  • quiet (bool (default: True)) – silent output (stdout and sterr)

Return type

None

satproc.utils.sliding_windows(size, step_size, width, height, mode='exact')[source]

Slide a window of +size+ by moving it +step_size+ pixels

Parameters
  • size (int) – window size, in pixels

  • step_size (int) – step or stride size when sliding window, in pixels

  • width (int) – image width

  • height (int) – image height

  • mode (str (default: 'exact')) – either one of ‘exact’, ‘whole’, ‘whole_overlap’. - ‘exact’: clip windows at borders, if needed - ‘whole’: only whole windows - ‘whole_overlap’: only wohle windows, allow overlapping windows at borders.

Yields

Tuple[Window, Tuple[int, int]] – a pair of Window and a pair of position (i, j)

satproc.utils.write_chips_geojson(output_path, chip_pairs, *, chip_type, crs, basename)[source]

Write a GeoJSON containing chips polygons as features

Parameters
  • output_path (str) – GeoJSON output path

  • chip_pairs (Tuple[Shape, Tuple[int, int, int]]) – a pair with the chip polygon geometry, and a tuple of (feature id, x, y)

  • chip_type (str) – chip file type extension (e.g. tif, jpg)

  • crs (str) – CRS epsg code of chip polygon geometry

  • basename (str) – basename of chip files

Return type

None

Module contents