solaris.raster API reference

solaris.raster.image Image pre- and post-processing

class solaris.raster.image.K1ScaleFunction(compression_delta)[source]

Calculate the k1 scale function for a quantile given a comp. factor.

solaris.raster.image.create_multiband_geotiff(array, out_name, proj, geo, nodata=0, out_format=1, verbose=False)[source]

Convert an array to an output georegistered geotiff. :param array: A numpy array with a the shape: [Channels, X, Y] or [X, Y] :type array: numpy.ndarray :param out_name: The output name and path for your image :type out_name: str :param proj: A projection, can be extracted from an image opened with gdal with

image.GetProjection(). Can be set to None if no georeferencing is required.

  • geo (gdal.geotransform) – A gdal geotransform which indicates the position of the image on the earth in projection units. Can be set to None if no georeferencing is required. Can be extracted from an image opened with gdal with image.GetGeoTransform()

  • nodata (int) – A value to set transparent for GIS systems. Can be set to None if the nodata value is not required. Defaults to 0.

  • out_format (str, gdalconst) – Must be one of the variables listed in the docs above. Defaults to gdal.GDT_Byte.

  • verbose (bool) – A verbose output, printing all inputs and outputs to the function. Useful for debugging. Default to False


Get the geotransform for a raster image source.


raster_src (str, rasterio.DatasetReader, or osgeo.gdal.Dataset) – Path to a raster image with georeferencing data to apply to geom. Alternatively, an opened rasterio.Band object or osgeo.gdal.Dataset object can be provided. Required if not using affine_obj.


transform – An affine transformation object to the image’s location in its CRS.

Return type


solaris.raster.image.get_intensity_quantiles(dataset_dir, percentiles=[0, 100], ext='tif', recursive=False, channels=None, verbose=0)[source]

Get approximate dataset pixel intensity percentiles for normalization.

This function reads every image in a dataset directory and gets a rough approximation of pixel intensity percentiles

solaris.raster.image.get_tdigest(data_buffer, tdigest=None, scale_function=<class 'solaris.raster.image.K1ScaleFunction'>, compression_delta=0.01)[source]

Create a new t-digest or merge it with an existing digest.

This function is an implementation of Algorithm 1 from

  • data_buffer (numpy.ndarray) – An array of data to load into a tdigest. This will be flattened into a vector.

  • tdigest (TDigest, optional) – An existing TDigest object to merge with the new data.

solaris.raster.image.stitch_images(im_arr, idx_refs=None, out_width=None, out_height=None, method='average', use_GPU=True)[source]

Stitch together images into a single 2- or 3-channel array.

This function helps combine predictions generated by inferencing tiled pieces of larger images, similar to the pre-existing CosmiQ Works tool, BASISS

  • im_arr (numpy.array or list of numpy.array s) – A 3- or 4-D numpy.array with shape [N, Y, X(, C)] or a list of length N made up of 2- or 3-D tensors with shape [Y, X(, C)]. These array(s) will be stitched together to produce a single output of shape [Y, X(, C)] .

  • idx_refs (list, optional) – A list of (Y, X) indices for each sub-array to define the location of the first corner in the final output. Used for stitching together non-overlapping or partially overlapping tiles into a single output. Note that the index reference output of solaris.nets.datagen.InferenceTiler provides the required reference system for stitching here.

  • out_width (int, optional) – The width of the output array in pixels. If not provided, it is assumed that the width is the same as the width of im_arr .

  • out_height (int, optional) – The height of the output array in pixels. If not provided, it is assumed that the height is the same as the height of im_arr .

  • method (str, optional) – possible values are 'average' (default), 'first' , and 'confidence' . * If 'average' , all pixels corresponding to the same location in [Y, X, C] space are averaged. * If 'first' , the value of the first pixel along the N axis for a given [Y, X, C] location is selected. * If 'confidence' , it’s assumed that pixel values correspond to probabilities in [0, 1] . In this case, for a given [Y, X, C] location, the pixel with the greatest distance from 0.5 will be selected (being the value with the highest confidence).

  • use_GPU (bool, optional) – Should processing be performed on the GPU if a GPU is available? Defaults to yes (True). If a GPU isn’t available, this argument is ignored. False will force CPU-located processing.



Return type

a numpy.array with shape [Y, X(, C)] .