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 withimage.GetProjection(). Can be set to None if no georeferencing is required.
- Parameters
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) – https://gdal.org/python/osgeo.gdalconst-module.html 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
-
solaris.raster.image.
get_geo_transform
(raster_src)[source]¶ Get the geotransform for a raster image source.
- Parameters
raster_src (str,
rasterio.DatasetReader
, or osgeo.gdal.Dataset) – Path to a raster image with georeferencing data to apply to geom. Alternatively, an openedrasterio.Band
object orosgeo.gdal.Dataset
object can be provided. Required if not using affine_obj.- Returns
transform – An affine transformation object to the image’s location in its CRS.
- Return type
affine.Affine
-
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 https://github.com/tdunning/t-digest/blob/master/docs/t-digest-paper/histo.pdf
- Parameters
data_buffer (
numpy.ndarray
) – An array of data to load into a tdigest. This will be flattened into a vector.tdigest (
TDigest
, optional) – An existingTDigest
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
- Parameters
im_arr (
numpy.array
orlist
ofnumpy.array
s) – A 3- or 4-Dnumpy.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 ofsolaris.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 theN
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 from0.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.
- Returns
output_arr
- Return type
a
numpy.array
with shape[Y, X(, C)]
.