slippy.surface.subtract_polynomial¶
- slippy.surface.subtract_polynomial(profile: numpy.ndarray, order: int = 1, mask: Optional[Union[numpy.ndarray, float]] = None)[source]¶
Flattens the surface by fitting and subtracting a polynomial
Fits a polynomial to the surface the subtracts it from the surface, to remove slope or curve from imaging machines
- Parameters
profile (array-like or Surface) – The surface or profile to be used
order (int) – The order of the polynomial to be fitted
mask (np.ndarray (dtype=bool) or float, optional (None)) – If an array, the array is used as a mask for the profile, must be the same shape as the profile, if a float or list of floats is given, those values are excluded from the calculation, if None all the values are included in the calculation
- Returns
adjusted (array) – The flattened profile
coefs (array) – The coefficients of the polynomial
Examples
Subtract a quadratic polynomial from the profile of my_surface the result is returned but the profile property of the surface is not updated
>>> import slippy.surface as s >>> import numpy as np >>> profile = np.random.rand(10,10) >>> flat_profile, coefs = subtract_polynomial(profile, 2)
Subtract a plane of best fit from profile and return the result
>>> flat_profile, coefs = subtract_polynomial(profile, 1)
Subtract the profile from the surface ignoring nan height values
>>> flat_profile, coefs = subtract_polynomial(profile_2, 1, mask=float('nan'))
Subtract a polynomial from the surface ignoring a 5 deep boarder
>>> mask=np.zeros_like(profile, dtype=bool) >>> mask[5:-5,5:-5]=True >>> flat_profile, coefs = subtract_polynomial(profile_2, 1, mask=mask)
See also
roughness,numpy.linalg.lstsqNotes
Polynomials of any integer order are supported.