solaris.preproc API reference

solaris.preproc.pipesegment Preprocessing base class and control structures

class solaris.preproc.pipesegment.Conditional(condition_class, if_class=<class 'solaris.preproc.pipesegment.Identity'>, else_class=<class 'solaris.preproc.pipesegment.ReturnEmpty'>, condition_args=[], if_args=[], else_args=[], condition_kwargs={}, if_kwargs={}, else_kwargs={})[source]

This is the pipesegment version of an if statement. The piped input is fed into an object of the ‘condition_class’ class. If ‘True’ is returned, then the input is fed through an ‘if_class’ object. Otherwise, the input is fed through an ‘else_class’ object.

class solaris.preproc.pipesegment.FunctionPipe(function)[source]

Turns a user-supplied function into a PipeSegment

class solaris.preproc.pipesegment.Identity[source]

This class is an alias for the PipeSegment base class, to emphasize its property of passing data through, unchanged. Formally, this is the identity element for the ‘*’ operation.

class solaris.preproc.pipesegment.Map(inner_class, *args, **kwargs)[source]

This is the pipesegment version of a for-loop. Given an iterable of inputs, applies the PipeSegment-derived class specified by ‘inner_class’ to each one, then returns all the results as a tuple.

class solaris.preproc.pipesegment.PipeArgs(inner_class, *args, **kwargs)[source]

Wrapper for any PipeSegment subclass which enables it to accept initialization arguments from piped input.

solaris.preproc.pipesegment.PipeFunction(inner_class=<class 'solaris.preproc.pipesegment.PipeSegment'>, pin=(), *args, **kwargs)[source]

Turns a PipeSegment into a standalone function. inner_class is the PipeSegment class, pin is the input to pipe into it, and *args and **kwargs are sent to the PipeSegment’s constructor.

class solaris.preproc.pipesegment.ReturnEmpty[source]

Regardless of input, returns an empty tuple. This can be useful in Map and Conditional classes. Formally, this is the identity element for the ‘+’ operation.

class solaris.preproc.pipesegment.SelectItem(index=0)[source]

Given an iterable, return one of its items. This can be used to select a single output from a class that returns a tuple of outputs.

class solaris.preproc.pipesegment.While(condition_class, inner_class, condition_args=[], inner_args=[], condition_kwargs={}, inner_kwargs={})[source]

This is the pipesegment version of a while-loop. Applies the the PipeSegment-derived class specified by ‘inner_class’ to the piped input over and over again, until sending the piped input through an object of class ‘condition_class’ returns false.

solaris.preproc.image Preprocessing of geospatial imagery

class solaris.preproc.image.Bounds[source]

Output the boundary coordinates [xmin, ymin, xmax, ymax] of an image. Note: Requires the image to have an affine geotransform, not GCPs. Note: Only works for a north-up image without rotation or shearing

class solaris.preproc.image.Crop(bounds, mode='pixel')[source]

Crop image based on either pixel coordinates or georeferenced coordinates. ‘bounds’ is a list specifying the edges: [left, bottom, right, top]

class solaris.preproc.image.CropVariable(mode='pixel')[source]

Like ‘Crop’, but window coordinates are accepted from another PipeSegment at runtime instead of via initialization arguments.

class solaris.preproc.image.GetMask(band=0, flag='nan')[source]

Extract a Boolean mask from an image band. NaN is assumed to be the mask value, unless otherwise specified.

class solaris.preproc.image.Identity[source]

This class is an alias for the PipeSegment base class to emphasize its role as the identity element.

class solaris.preproc.image.ImageStats(print_desc=True, print_props=True, return_image=True, return_props=False, median=True, caption=None)[source]

Calculate descriptive statististics about an image

class solaris.preproc.image.InvertMask[source]

Sets all True values in a mask to False and vice versa.

class solaris.preproc.image.LoadImage(imageinput, name=None, verbose=False)[source]

Makes an image available to subsequent PipeSegments, whether the image is in the filesystem (in which case ‘imageinput’ is the path) or an Image-class variable (in which case ‘imageinput’ is the variable name).

class solaris.preproc.image.LoadImageFromDisk(pathstring, name=None, verbose=False)[source]

Load an image from the file system using GDAL, so it can be fed into subsequent PipeSegments.

class solaris.preproc.image.LoadImageFromMemory(imageobj, name=None, verbose=False)[source]

Points to an ‘Image’-class image so it can be fed into subsequent PipeSegments.

class solaris.preproc.image.MergeToProduct(master=0)[source]

Combine an iterable of images by multiplying the corresponding bands. Assumes that images are of equal size and have equal numbers of bands.

class solaris.preproc.image.MergeToStack(master=0)[source]

Given an iterable of equal-sized images, combine all of their bands into a single image.

class solaris.preproc.image.MergeToSum(master=0)[source]

Combine an iterable of images by summing the corresponding bands. Assumes that images are of equal size and have equal numbers of bands.

class solaris.preproc.image.Resize(rows, cols)[source]

Resize an image to the requested number of pixels

class solaris.preproc.image.SaveImage(pathstring, driver='GTiff', return_image=True, save_projection=True, save_metadata=True, no_data_value=None)[source]

Save an image to disk using GDAL.

class solaris.preproc.image.Scale(factor=1.0)[source]

Scale data by a multiplicative factor.

class solaris.preproc.image.SelectBands(bands=[0])[source]

Reorganize the bands in an image. This class can be used to select, delete, duplicate, or reorder bands.

class solaris.preproc.image.SelectItem(index=0)[source]

Given an iterable, return one of its items. This is useful when passing a list of items into, or out of, a custom class.

class solaris.preproc.image.SetMask(flag=nan, band=None, reverse_order=False)[source]

Given an image and a mask, apply the mask to the image. More specifically, set the image’s pixel value to NaN (or other specified value) for every pixel where the mask value is False.

class solaris.preproc.image.ShowImage(show_text=False, show_image=True, cmap='gray', vmin=None, vmax=None, bands=None, caption=None, width=None, height=None)[source]

Display an image using matplotlib.

solaris.preproc.sar Preprocessing of SAR imagery

class solaris.preproc.sar.Amplitude[source]

Convert complex image to amplitude, by taking the magnitude of each pixel

class solaris.preproc.sar.BandMath(function, master=0)[source]

Modify the array holding an image’s pixel values, using a user-supplied function.

class solaris.preproc.sar.CapellaGridCommonWindow(master=0, subpixel=True)[source]

Given an iterable of Capella grid files with equal orientations and pixel sizes but translational offsets, find the overlapping region and return its array indices for each grid file. Optionally, also return the subpixel offset of each grid file needed for exact alignment.

courseoffset(latgrid, longrid, lattarget, lontarget)[source]

Given a latitude/longitude pair, find the closest point in a grid of almost-regularly-spaced latitude/longitude pairs.

fineoffset(latgrid, longrid, lattarget, lontarget, uidx, vidx)[source]

Given grids of almost-equally-spaced latitude and longitude, and an exact latitude-longitude pair to aim for, and indices of the (ideally) nearest point to that lat-long target, returns a first-order estimate of the target offset, in pixels, relative to the specified point.

haversine(lat1, lon1, lat2, lon2, rad=False, radius=6371000.0)[source]

Haversine formula for distance between two points given their latitude and longitude, assuming a spherical earth.

class solaris.preproc.sar.CapellaGridToGCPs(reverse_order=False, row_range=None, col_range=None, spacing=150, row_spacing=None, col_spacing=None)[source]

Generate ground control points (GCPs) from a Capella grid file and save them in a corresponding image’s metadata. Input is a tuple with the image in the 0 position and the grid in the 1 position. Output is the image with modified metadata. Spacing between points is in pixels.

class solaris.preproc.sar.CapellaGridToPolygon(step=100, flags=False)[source]

Given a Capella grid file, return a GeoJSON string indicating its boundary. ‘step’ is number of pixels between each recorded point.

class solaris.preproc.sar.CapellaScaleFactor[source]

Calibrate Capella single-look complex data (or amplitude thereof) using the scale factor in the metadata

class solaris.preproc.sar.Conjugate[source]

Return complex conjugate of the input image

class solaris.preproc.sar.Decibels(flag='min')[source]

Express quantity in decibels The ‘flag’ argument indicates how to handle nonpositive inputs: ‘min’ outputs the log of the image’s smallest positive value, ‘nan’ outputs NaN, and any other value is used as the flag value itself.

class solaris.preproc.sar.DecompositionFreemanDurden(hh_band=0, vv_band=1, xx_band=2, kernel_size=5)[source]

Compute the three-component polarimetric decomposition of quad-pol SAR data proposed by Freeman and Durden. Note: Convention is Ps–>blue, Pd–>red, Pv–>green

class solaris.preproc.sar.DecompositionHAlpha(band0=0, band1=1, kernel_size=5)[source]

Compute H-Alpha (Entropy-alpha) dual-polarization decomposition

class solaris.preproc.sar.DecompositionPauli(hh_band=0, vv_band=1, xx_band=2)[source]

Compute the Pauli decomposition of quad-pol SAR data. Note: Convention is alpha–>blue, beta–>red, gamma–>green

class solaris.preproc.sar.InPhase[source]

Get in-phase (real) component of complex-valued data

class solaris.preproc.sar.Intensity[source]

Convert amplitude (or complex values) to intensity, by squaring each pixel

class solaris.preproc.sar.Multilook(kernel_size=5, method='avg')[source]

Multilook filter to reduce speckle in SAR magnitude imagery Note: Set kernel_size to a tuple to vary it by direction.

class solaris.preproc.sar.MultilookComplex(kernel_size=5, method='avg')[source]

Like ‘Multilook’, but supports complex input

class solaris.preproc.sar.MultiplyConjugate(master=0)[source]

Given an iterable of two images, multiply the first by the complex conjugate of the second.

class solaris.preproc.sar.Orthorectify(projection=3857, algorithm='lanczos', row_res=1.0, col_res=1.0)[source]

Orthorectify an image using its ground control points (GCPs) with GDAL

class solaris.preproc.sar.Phase[source]

Return the phase of the input image

class solaris.preproc.sar.Quadrature[source]

Get quadrature (imaginary) component of complex-valued data

class solaris.preproc.sar.TerraSARXGeorefToGCPs(reverse_order=False)[source]

Generate ground control points (GCPs) from a TerraSAR-X GEOREF.xml file and save them in a corresponding image’s metadata. Input is a tuple with the image in the 0 position and the georef file in the 1 position. Output is the image with modified metadata.

class solaris.preproc.sar.TerraSARXScaleFactor(reverse_order=False)[source]

Calibrate TerraSAR-X complex data using the scale factor in the accompanying xml file.

solaris.preproc.label Preprocessing of vector labels

class solaris.preproc.label.BoundsToDataFrame(projection=None)[source]

Given a set of tile bounds [left, lower, right, upper], convert it to a GeoPandas GeoDataFrame. Note: User must specify projection, since a simple set of bounds doesn’t include that.

class solaris.preproc.label.DataFramePixelCoords(inverse=False, reverse_order=False, *args, **kwargs)[source]

Given a GeoPandas GeoDataFrame, converts between georeferenced coordinates and pixel coordinates. Assumes image has affine geotransform.

class solaris.preproc.label.DataFrameToString(crs=True, **kwargs)[source]

Given a GeoPandas GeoDataFrame, convert it into a GeoJSON string. Caveat emptor: This follows the GeoJSON 2016 standard, which does not include any coordinate reference system information.

class solaris.preproc.label.ExplodeDataFrame[source]

Given a GeoPandas GeoDataFrame, break multi-part geometries into multiple lines.

class solaris.preproc.label.IntersectDataFrames(master=0)[source]

Given an iterable of GeoPandas GeoDataFrames, returns their intersection

class solaris.preproc.label.LoadDataFrame(pathstring, geom_col='geometry', projection=None)[source]

Load a GeoPandas GeoDataFrame from a file.

class solaris.preproc.label.LoadString(pathstring)[source]

Load a string from a file.

class solaris.preproc.label.ReprojectDataFrame(projection=3857)[source]

Reproject a GeoPandas GeoDataFrame.

class solaris.preproc.label.SaveDataFrame(pathstring, driver='GeoJSON')[source]

Save a GeoPandas GeoDataFrame to disk.

class solaris.preproc.label.SaveString(pathstring, append=False)[source]

Write a string to a file.

class solaris.preproc.label.ShowDataFrame[source]

Print a GeoPandas GeoDataFrame to the screen.

class solaris.preproc.label.ShowString[source]

Print a string to the screen.