Tectonic_Utils.geodesy package
datums
Convert between local enu, local llh, and global xyz coordinates Translated from the Matlab toolkit of the Stanford lab.
- get_datums(names=None)
Returns da, df, dX, dY, dZ given a specific datum. DATUMVALUE=data(DATUMNAMES) returns the datum parameters for datum specified by string array DATUMNAMES. These parameters are defined as differences to the WGS-84 ellipsoid: * da = WGS-84 equatorial radius minus the specified datum equatorial radius (meters) * df = WGS-84 flattening minus the specified datum flattening * dX = X-coordinate of WGS-84 geocenter minus the specified datum X-coordinate (meters) * dY = Y-coordinate of WGS-84 geocenter minus the specified datum Y-coordinate (meters) * dZ = Z-coordinate of WGS-84 geocenter minus the specified datum Z-coordinate (meters)
For reference: * WGS-84 Equatorial Radius (a) = 6378137.0 * WGS-84 Flattening (f) = 1/298.257223563
Calling the function without input arguments returns a list of available datums. Unmatched datums return NaNs.
- Parameters
names (string) – string
- Returns
5 floats representing the chosen datum relative to WGS-84
- Return type
array
euler_pole
Functions to rotate a point by a known Euler pole.
- degma2radyr(omega)
Convert omega from degrees/Ma to radians/yr.
- Parameters
omega (float) – rotation rate in degrees per million years
- Returns
rotation rate in radians per year
- Return type
float
- euler_pole_to_euler_vector(euler_pole)
Convert a lon/lat/rate representing an Euler Pole into a vector representation of the Euler Pole.
- Parameters
euler_pole (array_like) – [lon, lat, rate]
- Returns
ev_x, ev_y, ev_z in same units as rate, where longitude 0 is along the positive east axis.
- Return type
float, float, float
- euler_vector_to_euler_pole(euler_vector)
Convert a three-component vector representing an Euler Pole into a lon/lat/rate representation of the Euler Pole.
- Parameters
euler_vector (array_like) – [ev_x, ev_y, ev_z] in deg/ma, where longitude 0 is along the positive east axis
- Returns
lon, lat, rate
- Return type
float, float, float
- get_opposite_ep(euler_pole)
Get opposite pole on other side of the Earth.
- Parameters
euler_pole (array_like) – [lon, lat, rate]
- Returns
opposite euler pole, -180 <= lon <= 180
- Return type
[float, float, float]
- get_r(lon, lat)
Vector from center of earth to the point in question assuming a spherical earth. The XYZ coordinate system has x=0 at longitude=0 and z=0 at the equator with positive to the north.
- Parameters
lon (float) – Longitude of initial point, in degrees
lat (float) – Latitude of initial point, in degrees
- Returns
[X, Y, Z] coordinates in meters.
- Return type
[float, float, float]
- get_unit_east(lon)
Unit east vector from a point on earth’s surface in XYZ coordinates. The XYZ coordinate system has x=0 at longitude=0 and z=0 at the equator with positive to the north. The return value of Z is zero for eastward motion.
- Parameters
lon (float) – Longitude of initial point, in degrees
- Returns
[X, Y, Z] components
- Return type
[float, float, float]
- point_rotation_by_Euler_Pole(Point, Euler_Pole)
Compute the velocity of rotation of a point about an Euler pole on a spherical earth. This function is useful for computing the velocity of a stationary point in one reference frame with respect to another reference frame. The resulting velocity is assumed to be horizontal.
- Parameters
Point (array_like) – [longitude, latitude] of observation point, in degrees
Euler_Pole (array_like) – [longitude, latitude, omega] of Euler Pole, in degrees and degrees/Ma
- Returns
[e_velocity, n_velocity, u_velocity] of point in rotated reference frame, in mm/yr
- Return type
[float, float, float]
- xyz2en(x, y, z, lon)
Convert velocities from xyz to horizontal east and north, assuming spherical earth and no vertical motion. We take the dot product of the velocity with the unit east vector and the north component is the remainder. A more complex function xyz2enu(X, Y, Z, lon, lat) could be written later.
- Parameters
x (float) – x velocity at observation point
y (float) – y velocity at observation point
z (float) – z velocity at observation point
lon (float) – Longitude of observation point, in degrees
- Returns
[east_vel, north_vel]
- Return type
[float, float]
fault_vector_functions
Useful utilities for defining fault planes and coordinate systems.
- add_vector_to_point(x0, y0, vector_mag, vector_heading)
- Parameters
x0 (float) – starting x-coordinate for vector
y0 (float) – starting y-coordinate for vector
vector_mag (float) – magnitude of vector to be added to point
vector_heading (float) – direction of vector, in degrees CW from north
- Returns
x1, y1 coordinates of ending point
- Return type
float, float
- get_dip_degrees(x0, y0, z0, x1, y1, z1)
Get the dip of the line that connects two points.
- Parameters
x0 (float) – x coordinate of shallower point
y0 (float) – y coordinate of shallower point
z0 (float) – z coordinate of shallower point
x1 (float) – x coordinate of deeper point
y1 (float) – y coordinate of deeper point
z1 (float) – z coordinate of deeper point
- Returns
dip, in degrees
- Return type
float
- get_dip_vector(strike, dip)
Get a unit vector along the dip direction of a plane.
- Parameters
strike (float) – strike, in degrees CW from N
dip (float) – dip, in degrees
- Returns
3-component unit vector, in x, y, z coordinates
- Return type
[float, float, float]
- get_downdip_width(top, bottom, dip)
Get total downdip-width of a rectangular fault plane given top depth, bottom depth, and dip.
- Parameters
top (float) – depth of top of fault plane, in km (positive down)
bottom (float) – depth of top of fault plane, in km (positive down)
dip (float) – dip of fault plane, in degrees (range 0 to 90)
- Returns
total down-dip width of the rectangle, in km
- Return type
float
- get_leftlat_reverse_slip(slip, rake)
Decompose slip into left lateral and reverse slip components.
- Parameters
slip (float) – slip, in any length unit
rake (float) – rake, in degrees
- Returns
left-lat strike slip and reverse dip slip, in the same length units as slip
- Return type
float, float
- get_plane_normal(strike, dip)
Get the outward-facing unit normal to a plane of specified strike and dip (dip-cross-strike).
- Parameters
strike (float) – strike, degrees
dip (float) – dip, degrees
- Returns
3-component vector of outward facing unit normal vector, [x, y, z]
- Return type
np.ndarray
- get_rake(rtlat_strike_slip, dip_slip)
Return the rake of a given slip vector. Positive strike-slip is right lateral, and positive dip-slip is reverse. Will return 0 if dipslip,strikeslip == 0,0.
- Parameters
rtlat_strike_slip (float) – quantity of right lateral slip, any length units
dip_slip (float) – quantity of reverse slip, any length units
- Returns
rake in range -180 to 180 degrees
- Return type
float
- get_rtlat_dip_slip(slip, rake)
Decompose slip into right lateral and reverse dip slip components.
- Parameters
slip (float) – slip, in any length unit
rake (float) – rake, in degrees
- Returns
rt-lat strike slip and reverse dip slip, in the same length units as slip
- Return type
float, float
- get_strike(deltax, deltay)
Compute the strike of a vector x,y.
- Parameters
deltax (float) – displacement in x direction, in any length unit
deltay (float) – displacement in y direction, in any length unit
- Returns
strike of vector, in CW degrees from north
- Return type
float
- get_strike_length(x0, x1, y0, y1)
Just the pythagorean theorem.
- get_strike_vector(strike)
Get a unit vector along the strike direction of a plane.
- Parameters
strike (float) – strike, in degrees CW from N
- Returns
3-component unit vector, in x, y, z coordinates
- Return type
[float, float, float]
- get_top_bottom_from_center(center_depth, width, dip)
Get the top and bottom depth of a rectangular fault from its width, center, and dip.
- Parameters
center_depth (float) – depth of center of fault plane, in km (positive down)
width (float) – total downdip width of rectangular fault plane, in km
dip (float) – dip of fault plane, in degrees (range 0 to 90)
- Returns
top and bottom of fault plane, in km
- Return type
float, float
- get_top_bottom_from_top(top_depth, width, dip)
Get the top and bottom depth of a rectangular fault from its width, top-edge depth, and dip.
- Parameters
top_depth (float) – depth of top edge of fault plane, in km (positive down)
width (float) – total downdip width of rectangular fault plane, in km
dip (float) – dip of fault plane, in degrees (range 0 to 90)
- Returns
top and bottom of fault plane, in km
- Return type
float, float
- get_total_slip(strike_slip, dip_slip)
Just the pythagorean theorem.
- get_unit_vector(vec)
Get unit vector.
- Parameters
vec (array_like) – 3-component vector, any units
- Returns
unit vector
- Return type
array_like
- get_vector_magnitude(vector)
Get magnitude of a vector.
- Parameters
vector (array_like) – n-component vector, any units
- Returns
magnitude
- Return type
float
- latlon2xy(loni, lati, lon0, lat0)
Convert lon/lat coordinates into cartesian x/y coordinates using reference point.
- Parameters
loni (float or list) – longitude of target point(s)
lati (float or list) – latitude of target point(s)
lon0 (float) – longitude of reference point
lat0 (float) – latitude of reference point
- Returns
x, y of target point(s), in km
- Return type
list, list (float, float in case of single inputs)
- latlon2xy_single(loni, lati, lon0, lat0)
Convert lon/lat coordinate into cartesian x/y coordinate using reference point.
- Parameters
loni (float) – longitude of target point
lati (float) – latitude of target point
lon0 (float) – longitude of reference point
lat0 (float) – latitude of reference point
- Returns
x, y of target point, in km
- Return type
float, float
- simple_cross_product(a, b)
Implement the simple cross product for 2 vectors in 3-D space.
- Parameters
a – array-like, 3-component vector
b – array-like, 3-component vector
- Returns
3-component array, [x, y, z]
- Return type
[float, float, float]
- xy2lonlat(xi, yi, reflon, reflat)
Convert cartesian x/y coordinates into lon/lat coordinates using reference point.
- Parameters
xi (float or list) – x coordinate of target point(s), in km
yi (float or list) – y coordinate of target point(s), in km
reflon (float) – longitude of reference point
reflat (float) – latitude of reference point
- Returns
lon, lat of target point(s)
- Return type
list, list (float, float in case of single inputs)
- xy2lonlat_single(xi, yi, reflon, reflat)
Convert cartesian x/y coordinate into lon/lat coordinate using reference point.
- Parameters
xi (float) – x coordinate of target point, in km
yi (float) – y coordinate of target point, in km
reflon (float) – longitude of reference point
reflat (float) – latitude of reference point
- Returns
lon, lat of target point
- Return type
float, float
geojson2txt
This script contains utility functions to convert between two different InSAR data representations:
geojson, produced by Kite after downsampling
text representation, used for inversions
- namedtuple Downsampled_pixel(mean, median, std, BL_corner, TR_corner, unitE, unitN, unitU)
Bases:
NamedTuple
A namedtuple object containing a quadtree-downsampled pixel, including downsampled pixel footprint, downsampled pixel look vector, and downsampled deformation values.
- mean: float
mean of LOS values within the pixel (meters)
- median: float
median of LOS values within the pixel (meters)
- std: float
standard deviation of LOS values within the pixel (meters)
- BL_corner: tuple, list, or array
Coordinates of Bottom Left corner (longitude, latitude)
- TR_corner: tuple, list, or array
Coordinates of Top Right corner (longitude, latitude)
- unitE: float
east component of unit vector from ground to satellite
- unitN: float
north component of unit vector from ground to satellite
- unitU: float
up component of unit vector from ground to satellite
Downsampled_pixel(mean, median, std, BL_corner, TR_corner, unitE, unitN, unitU)
- Fields
mean – Alias for field number 0
median – Alias for field number 1
std – Alias for field number 2
BL_corner – Alias for field number 3
TR_corner – Alias for field number 4
unitE – Alias for field number 5
unitN – Alias for field number 6
unitU – Alias for field number 7
- pixels_to_txt(pixel_list, text_file, bbox=(- 180, 180, - 90, 90), std_min=0.001)
Write InSAR pixels in basic text format: Lon Lat Value unitE unitN unitU.
- Parameters
pixel_list (list) – list of Downsampled_pixel objects
text_file (str) – name of output file
bbox (array_like, optional) – tuple of (W, E, S, N) bounding box, defaults to (-180, 180, -90, 90)
std_min (float, optional) – minimum value of uncertainty (m), defaults to 0.001
- read_geojson(infile)
Read a geojson as created by Kite downsampling into downsampled pixel objects.
- Parameters
infile (string) – name of geojson file
- Returns
list of Downsampled_pixel objects
- Return type
list
haversine
Haversine formula example in Python. Original author Wayne Dyck.
- add_vector_to_coords(lon0, lat0, dx, dy)
Add a vector of km to a set of latitude/longitude points.
- Parameters
lon0 (float) – Longitude of initial point, in degrees
lat0 (float) – Latitude of initial point, in degrees
dx (float) – x component of vector added to the point, in km
dy (float) – y component of vector added to the point, in km
- Returns
[lon1, lat1], in degrees
- Return type
[float, float]
- calculate_endpoint_given_bearing(origin, bearing, angular_distance_degrees)
Travel a certain angular distance (degrees) along a bearing starting from a coordinate. Source: https://www.movable-type.co.uk/scripts/latlong.html
- Parameters
origin (array_like) – Tuple representing (latitude, longitude) of first point, in decimal degrees
bearing (float) – angle clockwise from north, in decimal degrees
angular_distance_degrees (float) – angular distance, in decimal degrees
- Returns
[lat, lon], in degrees
- Return type
[float, float]
- calculate_initial_compass_bearing(pointA, pointB)
Calculate the bearing between two points. By the formula
\[\theta = atan2(\sin(\Delta_{long})*\cos(lat_2), \cos(lat_1)*\sin(lat_2) - \sin(lat_1)*\cos(lat_2)*\cos(\Delta_{long})).\]- Parameters
pointA (array_like) – Tuple representing (latitude, longitude) of first point, in decimal degrees
pointB (array_like) – Tuple representing (latitude, longitude) of second point, in decimal degrees
- Returns
bearing, in degrees CW from north
- Return type
float
- distance(origin, destination)
Computes the distance between origin [lat1, lon1] and destination [lat2, lon2].
- Parameters
origin (array_like) – Tuple representing (latitude, longitude) of first point, in decimal degrees
destination (array_like) – Tuple representing (latitude, longitude) of second point, in decimal degrees
- Returns
distance, in km
- Return type
float
- xy_distance(ref_loc, sta_loc)
Pythagorean distance between two latitude/longitude pairs, assuming flat surface between the points. Returns x and y in meters.
- Parameters
ref_loc (array_like) – Tuple representing (latitude, longitude) of first point, in decimal degrees
sta_loc (array_like) – Tuple representing (latitude, longitude) of second point, in decimal degrees
- Returns
[distance_x, distance_y], in m
- Return type
[float, float]
insar_vector_functions
Useful utilities for look vectors and coordinate systems.
- bearing_to_cartesian(heading)
Bearing (heading from North) to cartesian orientation CCW from east.
- Parameters
heading (float) – CW from North, in degrees
- Returns
Cartesian direction, CCW from East, in degrees
- Return type
float
- calc_lkv_from_rdr_azimuth_incidence(azimuth, incidence)
Function especially for ISCE interferograms to extract the lkv from azimuth/incidence. Convention: Azimuth angle measured from North in Anti-clockwise direction, in degrees, from ground to plane. Convention: Incidence angle measured from vertical at target. (aka degrees from vertical at satellite) (always +ve), in degrees. lkve, lkvn, lkvu describe vector from ground to plane.
- Parameters
azimuth (float) – CCW from north angle of vector from ground to plane, in degrees (ISCE LOS.RDR convention)
incidence (float) – angle from look vector to vertical, measured at the target (aka deg. from vertical at satellite)
- Returns
lkve, lkvn, lkvu, unit vector from ground to plane
- calc_rdr_azimuth_incidence_from_lkv_plane_down(lkve, lkvn, lkvu)
Function especially for UAVSAR interferograms to extract the incidence angle from lkv products. lkve, lkvn, lkvu describe vector from plane to ground. Convention: Azimuth angle measured from North in Anti-clockwise direction, in degrees, from ground to plane. Convention: Incidence angle measured from vertical at target. (aka degrees from vertical at satellite) (always +ve), in degrees.
- Parameters
lkve (float) – e component of look vector FROM PLANE TO GROUND
lkvn (float) – n component of look vector FROM PLANE TO GROUND
lkvu (float) – u component of look vector FROM PLANE TO GROUND
- Returns
azimuth, incidence, angles in degrees
- Return type
float, float
- cartesian_to_ccw_from_north(angle)
angle minus 90, in degrees.
- Parameters
angle – degrees
- Returns
angle in degrees
- cartesian_to_heading(cartesian_angle)
Cartesian orientation (CCW from east) to heading (CW from north).
- Parameters
cartesian_angle (float) – CCW from East, in degrees
- Returns
heading direction, CW from North, in degrees
- Return type
float
- complement_angle(angle)
90 minus angle, in degrees.
- Parameters
angle – degrees
- Returns
angle in degrees
- def3D_into_LOS(U_e, U_n, U_u, flight_angle, incidence_angle, look_direction='right')
Fialko, 2001, equation to project relative deformation into the LOS.
\[d_{los} = [U_n \sin(\phi) - U_e \cos(\phi)]*\sin(\lambda) + U_u \cos(\lambda).\]where lambda = incidence angle, phi = flight heading, and [U_e, U_n, U_u] are the east, north, and up components of the deformation.
- Parameters
U_e (float) – east component of deformation
U_n (float) – north component of deformation
U_u (float) – vertical component of deformation
flight_angle (float) – azimuth of satellite heading vector in degrees, CW from north
incidence_angle (float) – local incidence angle at the reflector (angle from the vertical), in degrees
look_direction (string) – ‘left’ or ‘right’ (default ‘right’)
- Returns
los deformation (in same units as U_e)
- Return type
float
- flight_incidence_angles2look_vector(flight_angle, incidence_angle)
General InSAR look vector math function, assuming right-looking satellite. lkv_e, lkv_n, lkv_u are the components of the look vector from ground to satellite.
- Parameters
flight_angle (float) – heading, clockwise from north, in degrees
incidence_angle (float) – angle between look vector and vertical, in degrees
- Returns
[lkv_e, lkv_n, lkv_u]
- Return type
list
- flight_incidence_angles2look_vector_leftlook(flight_angle, incidence_angle)
General InSAR look vector math function, assuming left-looking satellite. lkv_e, lkv_n, lkv_u are the components of the look vector from ground to satellite.
- Parameters
flight_angle (float) – heading, clockwise from north, in degrees
incidence_angle (float) – angle between look vector and vertical, in degrees
- Returns
[lkv_e, lkv_n, lkv_u]
- Return type
list
- get_unit_vector_from_angle(angle)
Get the unit vector associated with a cartesian angle (CCW from east in degrees).
- Parameters
angle – degrees CW from North
- Returns
list of two floats, x-component and y-component of unit vector
- get_unit_vector_from_heading(heading)
Get the unit vector associated with a heading angle (CW from north in degrees).
- Parameters
heading – degrees CW from North
- Returns
list of two floats, x-component and y-component of unit vector
- look_vector2flight_incidence_angles(lkv_e, lkv_n, lkv_u)
General InSAR look vector math function, assuming right-looking satellite. lkv_e, lkv_n, lkv_u are the components of the look vector from ground to satellite. incidence angle is angle between look vector and vertical in degrees. Flight angle is clockwise from north in degrees.
- Parameters
lkv_e (float) – e component of look vector from ground to satellite
lkv_n (float) – n component of look vector from ground to satellite
lkv_u (float) – u component of look vector from ground to satellite
- Returns
[flight_angle, incidence_angle] in degrees
- Return type
list
- normalize_vector(lkve, lkvn, lkvu)
Take a 3-component vector and normalize its components to a unit vector.
- proj_los_into_vertical_no_horiz(los, lkv)
Project LOS deformation into a pseudo-vertical deformation, assuming horizontal deformation is zero. Compute the vertical deformation needed to produce given LOS deformation.
- Parameters
los – float
lkv – list of 3 floats, normalized look vector components E, N, U
- rotate_vector_by_angle(x0, y0, theta)
rotate a vector by an angle theta, in degrees CCW from East.
- Parameters
x0 (float) – x component of vector
y0 (float) – y component of vector
theta (float) – angle to rotate by, in degrees CCW from East like the mathematical definition
- Returns
xprime, yprime
- Return type
float, float
linear_elastic
Theory: Conversion functions between the six fundamental material parameters in 3D Linear elasticity. Example: https://en.wikipedia.org/wiki/Elastic_modulus
- get_constants_from_bulk_and_lame1(K, lame1)
Given Bulk modulus (K) and lame1 (lambda), what are the other elastic constants?
- Parameters
K – bulk modulus
lame1 – lame’s first parameter
- Returns
[E, G, poisson’s ratio, and p-wave modulus]
- Return type
list of 4 floats
- get_constants_from_bulk_and_pr(K, nu)
Given Bulk modulus (K) and poisson’s ratio (nu), what are the other elastic constants?
- Parameters
K – bulk modulus
nu – poisson’s ratio
- Returns
[E, G, lame1, and p-wave modulus]
- Return type
list of 4 floats
- get_constants_from_bulk_and_pwave(K, M)
Given Bulk modulus (K) and P-wave modulus (M), what are the other elastic constants?
- Parameters
K – bulk modulus
M – p-wave modulus
- Returns
[E, G, lame1, and poisson’s ratio]
- Return type
list of 4 floats
- get_constants_from_bulk_and_shear(K, G)
Given Bulk modulus (K) and shear modulus (G), what are the other elastic constants?
- Parameters
K – bulk modulus
G – shear modulus
- Returns
[E, lame1, poisson’s ratio, and p-wave modulus]
- Return type
list of 4 floats
- get_constants_from_bulk_and_youngs(K, E)
Given Bulk (K) and Young’s (E) moduli, what are the other elastic constants?
- Parameters
K – bulk modulus
E – young’s modulus
- Returns
[lame1, G, poisson’s ratio, and p-wave modulus]
- Return type
list of 4 floats
- get_constants_from_lame1_and_nu(lame1, nu)
Given lame1 (lambda) and poisson’s ratio (nu), what are the other elastic constants?
- Parameters
lame1 – lame’s first parameter
nu – poisson’s ratio
- Returns
[K, E, G, and p-wave modulus]
- Return type
list of 4 floats
- get_constants_from_lame1_and_pwave(lame1, M)
Given lame1 (lambda) and P-wave modulus (M), what are the other elastic constants?
- Parameters
lame1 – lame’s first parameter
M – p-wave modulus
- Returns
[K, E, G, and poisson’s ratio]
- Return type
list of 4 floats
- get_constants_from_lame1_and_shear(lame1, G)
Given lame1 (lambda) and shear modulus (G), what are the other elastic constants?
- Parameters
lame1 – lame’s first parameter
G – shear modulus
- Returns
[K, E, poisson’s ratio, and p-wave modulus]
- Return type
list of 4 floats
- get_constants_from_nu_and_pwave(nu, M)
Given shear modulus (G) and p-wave modulus (M), what are the other elastic constants?
- Parameters
nu – poisson’s ratio
M – p-wave modulus
- Returns
[K, E, G, and lame1]
- Return type
list of 4 floats
- get_constants_from_shear_and_nu(G, nu)
Given shear modulus (G) and poisson’s ratio (nu), what are the other elastic constants?
- Parameters
G – shear modulus
nu – poisson’s ratio
- Returns
[K, E, lame1, and p-wave modulus]
- Return type
list of 4 floats
- get_constants_from_shear_and_pwave(G, M)
Given shear modulus (G) and p-wave modulus (M), what are the other elastic constants?
- Parameters
G – shear modulus
M – p-wave modulus
- Returns
[K, E, lame1, and pr]
- Return type
list of 4 floats
- get_constants_from_youngs_and_lame1(E, lame1)
Given Young’s modulus (E) and lame1 (lambda), what are the other elastic constants?
- Parameters
E – Young’s modulus
lame1 – lame’s first parameter
- Returns
[K, G, poisson’s ratio, and p-wave modulus]
- Return type
list of 4 floats
- get_constants_from_youngs_and_nu(E, nu)
Given Young’s modulus (E) and poisson’s ratio (nu), what are the other elastic constants?
- Parameters
E – Young’s modulus
nu – poisson’s ratio
- Returns
[K, lame1, G, and p-wave modulus]
- Return type
list of 4 floats
- get_constants_from_youngs_and_shear(E, G)
Given Young’s modulus (E) and shear modulus (G), what are the other elastic constants?
- Parameters
E – Young’s modulus
G – shear modulus
- Returns
[K, lame1, poisson’s ratio, and p-wave modulus]
- Return type
list of 4 floats
utilities
- get_unit_vector(vec)
Get unit vector in the direction of a given vector.
- Parameters
vec (array_like) – 3-component vector, any units
- Returns
unit vector
- Return type
array_like
- get_vector_magnitude(vector)
Get magnitude of a vector.
- Parameters
vector (array_like) – n-component vector, any units
- Returns
magnitude
- Return type
float
- wrap_lon(longitude)
Ensure longitude value is between -180° and 180° (e.g., not 240° E).
- Parameters
longitude – float
- Returns
wrapped longitude, from -180° to 180°
xyz2llh
Functions to convert between local enu, local llh, and global xyz coordinates. Translated from Matlab.
- enu2xyz(d, origin, dcov=None)
- ENU2XYZ Transforms from global cartestian to local cartesian.
[E,ECOV]=xyz2enu(D,DCOV,ORIGIN) transforms data vector D and data covariance DCOV from a local cartesian (ENU) coordinate system aligned with the geographic directions at the position ORIGIN to a global (XYZ) coordinate system. D should be either 3nx1 or 3xn (n = number of individual vectors). DCOV should be 3nx3n. ORIGIN should be a vector of length 2 or 3. If length 2, ORIGIN is taken as a longitude, latitude pair (degrees); if length 3, ORIGIN is taken as an XYZ station position. E is matrix (vector) of transformed coordinates the same size as input D. ECOV is a matrix containing the transformed covariance. E=xyz2enu(D,ORIGIN) behaves as above without a data covariance matrix.
- Parameters
d (numpy array) – nx3 np array of e, n, u values
origin (numpy array) – 1x3 np array (x, y, z) or 1x2 np.array (lon, lat)
dcov (numpy array) – 3x3 np array
- llh2xyz(llh, datum='NAD83')
- LLH2XYZ Calculates global cartesisan coordinates from longitude, latitude, and height.
XYZ=llh2xyz(llh,DATUM) calculates global cartestian coordinates given the nx3 (n = number of coordinate triples) matrix LLH that contains longitude (deg), latitude (deg), and height (m) on the ellipsoid specified by DATUM. DATUM can either be a vector the first two elements of which give da and df, or it can be a string containing the name of a datum that is resolved by the function DATUMS function. Note that longitude occupies the first row of LLH. See DATUMS for more information on datum parameters.
- Parameters
llh (numpy array) – [lon, lat, height]
datum (string) – name of datum
- xyz2enu(d, origin, dcov=None)
- XYZ2ENU Transforms from global cartestian to local cartesian.
[E,ECOV]=xyz2enu(D,DCOV,ORIGIN) transforms data vector D and data covariance DCOV from a global cartesian (XYZ) coordinate system to a local coordinate system aligned with the geographic directions at the position ORIGIN. D should be either 3nx1 or 3xn (n = number of individual vectors). DCOV should be 3nx3n. ORIGIN should be a vector of length 2 or 3. If length 2, ORIGIN is taken as a longitude, latitude pair (degrees); if length 3, ORIGIN is taken as an XYZ station position. E is matrix (vector) of transformed coordinates the same size as input D. ECOV is a matrix containing the transformed covariance. E=xyz2enu(D,ORIGIN) behaves as above without a data covariance matrix.
- Parameters
d (numpy array) – nx3 np array of x, y, z values
origin (numpy array) – 1x3 np array (x, y, z) or 1x2 np.array (lon, lat)
dcov (numpy array) – 3x3 np array
- xyz2enum(origin)
- XYZ2ENUM Returns a global to local transformation matrix.
T=xyz2enum(ORIGIN) Returns a transformation matrix that tranforms coordinates in a global ECEF cartesian system into to a local coordinate system aligned with the geographic directions at the position ORIGIN. ORIGIN should contain a longitude and a latitude pair (degrees). T is 3x3.
- Parameters
origin (np array) – [longitude, latitude]
- xyz2llh(xyz, datum='NAD83')
XYZ2LLH calculates longitude, latitude, and height from global cartesisan coordinates. LLH = xyz2llh(XYZ, DATUM) calculates longitude(deg), latitude(deg), and height(m) on the ellipsoid specified by DATUM from the global cartestian coordinates given in the nx3(n=number of coordinate triples) matrix XYZ. DATUM can either be a vector the first two elements of which give da and df, or it can be a string containing the name of a datum that is resolved by the function DATUMS function. Note that longitude occupies the first row of LLH. See DATUMS for more information on datum parameters.
- Parameters
xyz (numpy array) – [x, y, z]
datum (string) – name of datum
- Returns
[lon, lat, height]
- Return type
numpy array