bootsoff package

Submodules

Bootsoff.core module

class bootsoff.core.Station(label=None, coords=(0, 0, 0), crs='EPSG:4326')

Bases: shapely.geometry.point.Point

Station class

property crs
property label
plot(**kwargs)

Plots a marker at the station coordinates

Parameters
  • show_label (bool, default: False) – Set true to show the station label when plotting the station

  • **kwargs (dict) – kwargs to pass to plot_shapely_obj()

to_crs(crs)

Transforms the station coordinates into another coordinate reference system

Parameters

crs (str, default: 'EPSG:4326') – the pyproj string for the destination projection

bootsoff.core.fake_function(text='Hello World!')

Prints and returns a text after capitalizing

Parameters

text (str) –

Returns

text

Return type

a text

Bootsoff.gravity module

bootsoff.topo module

bootsoff.topo.topo.azimuth(origin, target)

Computes the Azimuth of a target point as seen from a origin point

Parameters
  • origin (shapely.geometry.Point) – Point from which the target is observed

  • target (shapely.geometry.Point) – Point which is observed from the origin

Returns

azimuth – azimuth angle in radians

Return type

float

bootsoff.topo.topo.cclength(coefs, x_end=1.0)

Computes the length along a cubic curve defined by the coefficients of its equation z=f(x) from 0 to x_end

Parameters
  • coefs (list) – coefficients of the cubic curve

  • x_end (float) – length is computed for a portion of the curve whose ends are at x=0 and x=x_end

Returns

length – length the portion of the curve

Return type

float

bootsoff.topo.topo.cclength2abs(coefs, length)

Computes the x value of the point at a distance computed along a cubic curve defined by its coefficients

Parameters
  • coefs (list) – coefficients of the cubic curve

  • length (numpy.array) – length of the portion of the curve

Returns

x – value of the end point of the portion of the curve starting at x=0 and of given length

Return type

float

bootsoff.topo.topo.cclength2xz(known_points, distances)

Computes [x,z] of points distributed at set distances along a curve defined by a set of known points and interpolated as a pchip

Parameters
  • known_points (list, numpy.array) – points

  • distances (numpy.array) – distances from the origin of the curve to the points whose x_value are sought

Returns

xz – list of found points coordinates along the curve

Return type

numpy.array

bootsoff.topo.topo.cclengths(known_points)

computes the distance from the first point and each given point along a curve defined by this set of known points and interpolated as a pchip

Parameters

known_points (list, numpy.array) – points

Returns

list of distances along the curve

Return type

numpy.array

bootsoff.topo.topo.ddmm_to_dd(x)

Converts angle expressed as degrees minutes (DDDMM) to decimal degrees (DDD.XXX)

xfloat

angle in degrees minute

Returns

angle – angle converted to the decimal degrees format

Return type

float

bootsoff.topo.geometry.flatten_geometry(obj)

Takes a 3D geometry and returns a 2D geometry discarding the third coordinate

Parameters

obj (shapely.geometry) – A 3D geometry

Returns

A 2D geometry

Return type

shapely.geometry

bootsoff.topo.geometry.gdf_to_ug(gdf, elevation='z')

Transforms a geopandas geodataframe into a pyvista unstructured grid

Parameters
  • gdf (geopandas.GeoDataFrame) – A geodataframe with unique index values

  • elevation (str) – Column name for the elevation field

Returns

A pyvista unstructured grid containing Point, LineString and Polygon with associated data

Return type

pv.core.pointset.UnstructuredGrid

bootsoff.topo.geometry.lift(obj, elevation=0.0)

Takes a geometry and turns it in a 3D geometry with given constant elevation

Parameters
  • obj (shapely.geometry) – A geometry

  • elevation (float) – elevation to which obj will be raised

Returns

A 3D geometry

Return type

shapely.geometry

bootsoff.topo.geometry.plane_normal(points)

Returns the normal vector of a plane defined by three non co-linear 3D points

Parameters

points (tuple or list or numpy.array) – an array-like object of the coordinates of three 3D points

Returns

the vector normal to the plane

Return type

numpy.array

Examples

This example shows how to search for the normal vector of the Oxy plane (assuming first second and thrid components of the vectors correspond to components along x, y and z respectively in a cartesian system :

>>> import numpy as np
>>> a = np.array((0., 0., 0.))
>>> b = np.array((1., 0., 0.))
>>> c = np.array((0., 1., 0.))
>>> plane_normal([a, b, c])
array([0., 0., 1.])

The answer is obviously a unit vector along the z-axis.

bootsoff.topo.geometry.plot_profile(ax=None, obj=None, name='')
bootsoff.topo.geometry.plot_shapely_obj(obj=None, ax=None, **kwargs)

Plots a shapely object in matplotlib axes

Parameters
  • obj (shapely.geometry) – A shapely object to plot

  • ax (matplotlib.axes) – Axes in which the shapely object should be plotted

  • kwargs (dict) – Keywords and arguments to pass to matplotlib plot for Point, MultiPoint, LineString, MultiLineString or LinearStrings and to patches for polygons

Returns

Return type

the matplotlib axes object used to plot the shapely object

bootsoff.topo.geometry.rotate_around_vector(vector, angle, degrees=False, affine_4x4=False)

Returns the matrix associated to a rotation by a given angle around a given vector using Rodrigues formula

Parameters
  • vector (numpy.array) – vector around which the rotation matrix will be computed

  • angle (float) – amplitude of rotation given following the right-hand-side rule

  • degrees (bool, default: False) – set to True if angle is given in degrees rather than in radians

  • affine_4x4 (bool, default: False) – set to True to return a 4x4 affine transform matrix

Returns

transform matrix

Return type

numpy.array

Example

This example shows how to use this function to rotate by 90° a given vector a around vector v.

>>> import numpy as np
>>> import bootsoff.topo.geometry as btg
>>> a = np.array([0., 0., 1.])
>>> v = np.array([3., 0., 0.])
>>> angle = np.pi/2
>>> r = btg.rotate_around_vector(v, angle)
>>> np.dot(r, a)
array([ 0.00000000e+00, -1.00000000e+00,  1.11022302e-16])

For more info. see https://en.wikipedia.org/wiki/Rodrigues’_rotation_formula#Matrix_notation

bootsoff.topo.geometry.transform_matrix_2d(from_obj, to_obj, shapely_format=False)
bootsoff.topo.geometry.transform_vtk(transform_matrix, infile, outfile=None)

Transforms a vtk file using an affine transform in 3D defined by the transform matrix

Parameters
  • transform_matrix (numpy.array) – a 4x4 affine transform matrix

  • infile (str or path) – filename of a vtk file to transform

  • outfile (str or path) – filename of the transformed vtk file

bootsoff.topo.geometry.vtk_transform_matrix_from_control_points(origin_coords, destination_coords, rcond=- 1)

Computes a 4x4 transform matrix to use on vtk objects from control points

Parameters
  • origin_coords (numpy.array) – 3D coordinates of the control points in the origin space

  • destination_coords (numpy.array) – 3D coordinates of the control points in the destination space

  • rcond (float, default: -1) – Cut-off ratio for small singular values used by numpy.linalg.lstsq

Returns

  • matrix (numpy.array) – The 4x4 transform matrix

  • residuals (numpy.array) –

    The residuals of the least-squares fitting of the parameters of the transform from the control points coordinate

    pairs

bootsoff.topo.coordinates.flip_coordinates(geom)

flips the coordinates of a geometry object

Parameters

geom (dict) – geojson geometry object

Returns

geom

Return type

dict

bootsoff.topo.coordinates.flip_geojson_coordinates(gjsn)

flips geojson geographic coordinates because folium uses the Latitude, Longitude order while geojson format is Longitude, Latitude

Note: checked on points only…

Parameters

gjsn (dict) – a geojson dictionary

Returns

status

Return type

bool

bootsoff.topo.coordinates.geojson_points_to_feature_group(gjsn, name='Unnamed feature group')

converts a geojson dictionary into a folium feature group

Parameters
  • gjsn (dict) – a geojson dictionary

  • name – feature group name

  • name – str

Returns

a folium feature group

Return type

folium.FeatureGroup

bootsoff.topo.coordinates.get_center(obj)

gets the coordinates of the center of the bounding box around a folium object that exposes a get_bounds method

:param obj; a folium object with the get_bounds method :type obj: object :return coordinates of the center of the bounding box :rtype tuple

bootsoff.utils module

Searches where to insert a value x in an sorted list or numpy array :param a: list or array to check :type a: list, numpy.array :param x: element to insert :type x: object :param ascending: True if sort order to check is ascending, False otherwise :type ascending: bool :param check: True if a has to be checked to be sorted before insertion :type check: bool

Returns

index – index of the place in sorted list or array where to insert x

Return type

int

bootsoff.utils.ordered.insert_in_sorted(a, x, ascending=True, check=False)

Searches where to insert a value x in an sorted list a and inserts it at that location :param a: list or array to check :type a: list, numpy.array :param x: element to insert :type x: object :param ascending: True if sort order to check is ascending, False otherwise :type ascending: bool :param check: True if a has to be checked to be sorted before insertion :type check: bool

Returns

a – sorted list with x inserted at the right position

Return type

int

bootsoff.utils.ordered.is_sorted(a, ascending=True)

Checks if a list or numpy array is sorted :param a: list or array to check :type a: list, numpy.array :param ascending: True if sort order to check is ascending, False otherwise :type ascending: bool

Returns

is_sorted – returns True if a is sorted in the specified order, False otherwise

Return type

bool