igibson.utils package
Submodules
igibson.utils.assets_utils module
igibson.utils.behavior_robot_motion_planning_utils module
igibson.utils.checkpoint_utils module
This file contains utils for BEHAVIOR demo replay checkpoints.
-
igibson.utils.checkpoint_utils.
load_checkpoint
(simulator, root_directory, frame)
-
igibson.utils.checkpoint_utils.
save_checkpoint
(simulator, root_directory)
igibson.utils.constants module
Constant Definitions
-
class
igibson.utils.constants.
CoordinateSystem
(value) Bases:
enum.IntEnum
An enumeration.
-
OPENCV
= 0
-
OPENGL
= 1
-
PYBULLET
= 2
-
SUNRGBD
= 3
-
-
class
igibson.utils.constants.
OccupancyGridState
Bases:
object
-
FREESPACE
= 1.0
-
OBSTACLES
= 0.0
-
UNKNOWN
= 0.5
-
-
class
igibson.utils.constants.
PyBulletSleepState
(value) Bases:
enum.IntEnum
An enumeration.
-
AWAKE
= 1
-
ISLAND_AWAKE
= 3
-
-
class
igibson.utils.constants.
SemanticClass
(value) Bases:
enum.IntEnum
An enumeration.
-
BACKGROUND
= 0
-
DIRT
= 507
-
HEAT_SOURCE_MARKER
= 510
-
ROBOTS
= 1
-
SCENE_OBJS
= 3
-
STAIN
= 508
-
TOGGLE_MARKER
= 511
-
USER_ADDED_OBJS
= 2
-
WATER
= 509
-
-
class
igibson.utils.constants.
ShadowPass
(value) Bases:
enum.IntEnum
An enumeration.
-
HAS_SHADOW_RENDER_SCENE
= 2
-
HAS_SHADOW_RENDER_SHADOW
= 1
-
NO_SHADOW
= 0
-
-
class
igibson.utils.constants.
SimulatorMode
(value) Bases:
enum.IntEnum
An enumeration.
-
GUI_INTERACTIVE
= 1
-
GUI_NON_INTERACTIVE
= 2
-
HEADLESS
= 3
-
HEADLESS_TENSOR
= 4
-
VR
= 5
-
-
class
igibson.utils.constants.
ViewerMode
(value) Bases:
enum.IntEnum
An enumeration.
-
MANIPULATION
= 1
-
NAVIGATION
= 0
-
PLANNING
= 2
-
-
igibson.utils.constants.
get_collision_group_mask
(groups_to_exclude=[]) Get a collision group mask that has collisions enabled for every group except those in groups_to_exclude.
igibson.utils.filters module
-
class
igibson.utils.filters.
ExponentialAverageFilter
(obs_dim, alpha=0.9) Bases:
igibson.utils.filters.Filter
This class uses an exponential average of the form y_n = alpha * x_n + (1 - alpha) * y_{n - 1}. This is an IIR filter.
-
dump_state
() - Return Any
the state of the object other than what’s not included in pybullet state.
-
estimate
(observation) Do an online hold for state estimation given a recent observation. :param observation: New observation to hold internal estimate of state. :return: New estimate of state.
-
load_state
(dump) Load the state of the object other than what’s not included in pybullet state.
- Parameters
dump – Any: the dumped state
-
-
class
igibson.utils.filters.
Filter
Bases:
object
A base class for filtering a noisy data stream in an online fashion.
-
dump_state
() - Return Any
the state of the object other than what’s not included in pybullet state.
-
estimate
(observation) Takes an observation and returns a de-noised estimate. :param observation: A current observation. :return: De-noised estimate.
-
load_state
(dump) Load the state of the object other than what’s not included in pybullet state.
- Parameters
dump – Any: the dumped state
-
reset
() Resets this filter. Default is no-op.
-
-
class
igibson.utils.filters.
MovingAverageFilter
(obs_dim, filter_width) Bases:
igibson.utils.filters.Filter
This class uses a moving average to de-noise a noisy data stream in an online fashion. This is a FIR filter.
-
dump_state
() - Return Any
the state of the object other than what’s not included in pybullet state.
-
estimate
(observation) Do an online hold for state estimation given a recent observation. :param observation: New observation to hold internal estimate of state. :return: New estimate of state.
-
load_state
(dump) Load the state of the object other than what’s not included in pybullet state.
- Parameters
dump – Any: the dumped state
-
reset
() Resets this filter. Default is no-op.
-
-
class
igibson.utils.filters.
Subsampler
Bases:
object
A base class for subsampling a data stream in an online fashion.
-
subsample
(observation) Takes an observation and returns the observation, or None, which corresponds to deleting the observation. :param observation: A current observation. :return: The observation, or None.
-
-
class
igibson.utils.filters.
UniformSubsampler
(T) Bases:
igibson.utils.filters.Subsampler
A class for subsampling a data stream uniformly in time in an online fashion.
-
subsample
(observation) Returns an observation once every T observations, None otherwise. :param observation: A current observation. :return: The observation, or None.
-
igibson.utils.generate_trav_map module
igibson.utils.git_utils module
igibson.utils.grasp_planning_utils module
igibson.utils.ig_logging module
igibson.utils.map_utils module
igibson.utils.mesh_geometric_conversion module
igibson.utils.mesh_util module
igibson.utils.monitor module
igibson.utils.motion_planning_wrapper module
igibson.utils.muvr_utils module
igibson.utils.python_utils module
A set of utility functions for general python usage
-
igibson.utils.python_utils.
assert_valid_key
(key, valid_keys, name=None) Helper function that asserts that @key is in dictionary @valid_keys keys. If not, it will raise an error.
- Parameters
key – Any, key to check for in dictionary @dic’s keys
valid_keys – Iterable, contains keys should be checked with @key
name – str or None, if specified, is the name associated with the key that will be printed out if the key is not found. If None, default is “value”
-
igibson.utils.python_utils.
extract_class_init_kwargs_from_dict
(cls, dic, copy=False) Helper function to return a dictionary of key-values that specifically correspond to @cls class’s __init__ constructor method, from @dic which may or may not contain additional, irrelevant kwargs. Note that @dic may possibly be missing certain kwargs as specified by cls.__init__. No error will be raised. Args:
cls (object): Class from which to grab __init__ kwargs that will be be used as filtering keys for @dic dic (dict): Dictionary containing multiple key-values copy (bool): If True, will deepcopy all values corresponding to the specified @keys
- Returns:
- dict: Extracted subset dictionary possibly containing only the specified keys from cls.__init__ and their
corresponding values
-
igibson.utils.python_utils.
extract_subset_dict
(dic, keys, copy=False) Helper function to extract a subset of dictionary key-values from a current dictionary. Optionally (deep)copies the values extracted from the original @dic if @copy is True. Args:
dic (dict): Dictionary containing multiple key-values keys (Iterable): Specific keys to extract from @dic. If the key doesn’t exist in @dic, then the key is skipped copy (bool): If True, will deepcopy all values corresponding to the specified @keys
- Returns:
dict: Extracted subset dictionary containing only the specified @keys and their corresponding values
-
igibson.utils.python_utils.
get_class_init_kwargs
(cls) Helper function to return a list of all valid keyword arguments (excluding “self”) for the given @cls class. Args:
cls (object): Class from which to grab __init__ kwargs
- Returns:
list: All keyword arguments (excluding “self”) specified by @cls __init__ constructor method
-
igibson.utils.python_utils.
merge_nested_dicts
(base_dict, extra_dict, verbose=False) Iteratively updates @base_dict with values from @extra_dict. Note: This generates a new dictionary! Args:
base_dict (dict): Nested base dictionary, which should be updated with all values from @extra_dict extra_dict (dict): Nested extra dictionary, whose values will overwrite corresponding ones in @base_dict verbose (bool): If True, will print when keys are mismatched
- Returns:
dict: Updated dictionary
igibson.utils.sampling_utils module
igibson.utils.scene_geometric_conversion module
igibson.utils.semantics_utils module
-
igibson.utils.semantics_utils.
get_class_name_to_class_id
(starting_class_id=4) Get mapping from semantic class name to class id
- Parameters
starting_class_id – starting class id for scene objects
-
igibson.utils.semantics_utils.
get_room_name_to_room_id
(starting_room_id=1) Get mapping from room name to room id
igibson.utils.tf_utils module
igibson.utils.transform_utils module
Utility functions of matrix and vector transformations.
NOTE: convention for quaternions is (x, y, z, w)
-
igibson.utils.transform_utils.
axisangle2quat
(vec) Converts scaled axis-angle to quat.
- Args:
vec (np.array): (ax,ay,az) axis-angle exponential coordinates
- Returns:
np.array: (x,y,z,w) vec4 float angles
-
igibson.utils.transform_utils.
clip_rotation
(quat, limit) Limits a (delta) rotation to a specified limit
Converts rotation to axis-angle, clips, then re-converts back into quaternion
- Args:
quat (np.array): (x,y,z,w) rotation being clipped limit (float): Value to limit rotation by – magnitude (scalar, in radians)
- Returns:
2-tuple:
(np.array) Clipped rotation quaternion (x, y, z, w)
(bool) whether the value was clipped or not
-
igibson.utils.transform_utils.
clip_translation
(dpos, limit) Limits a translation (delta position) to a specified limit
Scales down the norm of the dpos to ‘limit’ if norm(dpos) > limit, else returns immediately
- Args:
dpos (n-array): n-dim Translation being clipped (e,g.: (x, y, z)) – numpy array limit (float): Value to limit translation by – magnitude (scalar, in same units as input)
- Returns:
2-tuple:
(np.array) Clipped translation (same dimension as inputs)
(bool) whether the value was clipped or not
-
igibson.utils.transform_utils.
convert_quat
(q, to='xyzw') Converts quaternion from one convention to another. The convention to convert TO is specified as an optional argument. If to == ‘xyzw’, then the input is in ‘wxyz’ format, and vice-versa.
- Args:
q (np.array): a 4-dim array corresponding to a quaternion to (str): either ‘xyzw’ or ‘wxyz’, determining which convention to convert to.
-
igibson.utils.transform_utils.
euler2mat
(euler) Converts euler angles into rotation matrix form
- Args:
euler (np.array): (r,p,y) angles
- Returns:
np.array: 3x3 rotation matrix
- Raises:
AssertionError: [Invalid input shape]
-
igibson.utils.transform_utils.
ewma_vectorized
(data, alpha, offset=None, dtype=None, order='C', out=None) Calculates the exponential moving average over a vector. Will fail for large inputs. :param data: Input data :param alpha: scalar float in range (0,1)
The alpha parameter for the moving average.
- Parameters
offset – optional The offset for the moving average, scalar. Defaults to data[0].
dtype – optional Data type used for calculations. Defaults to float64 unless data.dtype is float32, then it will use float32.
order – {‘C’, ‘F’, ‘A’}, optional Order to use when flattening the data. Defaults to ‘C’.
out – ndarray, or None, optional A location into which the result is stored. If provided, it must have the same shape as the input. If not provided or None, a freshly-allocated array is returned.
-
igibson.utils.transform_utils.
force_in_A_to_force_in_B
(force_A, torque_A, pose_A_in_B) Converts linear and rotational force at a point in frame A to the equivalent in frame B.
- Args:
force_A (np.array): (fx,fy,fz) linear force in A torque_A (np.array): (tx,ty,tz) rotational force (moment) in A pose_A_in_B (np.array): 4x4 matrix corresponding to the pose of A in frame B
- Returns:
2-tuple:
(np.array) (fx,fy,fz) linear forces in frame B
(np.array) (tx,ty,tz) moments in frame B
-
igibson.utils.transform_utils.
get_orientation_error
(target_orn, current_orn) Returns the difference between two quaternion orientations as a 3 DOF numpy array. For use in an impedance controller / task-space PD controller.
- Args:
target_orn (np.array): (x, y, z, w) desired quaternion orientation current_orn (np.array): (x, y, z, w) current quaternion orientation
- Returns:
- orn_error (np.array): (ax,ay,az) current orientation error, corresponds to
(target_orn - current_orn)
-
igibson.utils.transform_utils.
get_pose_error
(target_pose, current_pose) Computes the error corresponding to target pose - current pose as a 6-dim vector. The first 3 components correspond to translational error while the last 3 components correspond to the rotational error.
- Args:
target_pose (np.array): a 4x4 homogenous matrix for the target pose current_pose (np.array): a 4x4 homogenous matrix for the current pose
- Returns:
np.array: 6-dim pose error.
-
igibson.utils.transform_utils.
make_pose
(translation, rotation) Makes a homogeneous pose matrix from a translation vector and a rotation matrix.
- Args:
translation (np.array): (x,y,z) translation value rotation (np.array): a 3x3 matrix representing rotation
- Returns:
pose (np.array): a 4x4 homogeneous matrix
-
igibson.utils.transform_utils.
mat2euler
(rmat, axes='sxyz') Converts given rotation matrix to euler angles in radian.
- Args:
rmat (np.array): 3x3 rotation matrix axes (str): One of 24 axis sequences as string or encoded tuple (see top of this module)
- Returns:
np.array: (r,p,y) converted euler angles in radian vec3 float
-
igibson.utils.transform_utils.
mat2pose
(hmat) Converts a homogeneous 4x4 matrix into pose.
- Args:
hmat (np.array): a 4x4 homogeneous matrix
- Returns:
2-tuple:
(np.array) (x,y,z) position array in cartesian coordinates
(np.array) (x,y,z,w) orientation array in quaternion form
-
igibson.utils.transform_utils.
mat2quat
(rmat) Converts given rotation matrix to quaternion.
- Args:
rmat (np.array): 3x3 rotation matrix
- Returns:
np.array: (x,y,z,w) float quaternion angles
-
igibson.utils.transform_utils.
mat4
(array) Converts an array to 4x4 matrix.
- Args:
array (n-array): the array in form of vec, list, or tuple
- Returns:
np.array: a 4x4 numpy matrix
-
igibson.utils.transform_utils.
matrix_inverse
(matrix) Helper function to have an efficient matrix inversion function.
- Args:
matrix (np.array): 2d-array representing a matrix
- Returns:
np.array: 2d-array representing the matrix inverse
-
igibson.utils.transform_utils.
pose2mat
(pose) Converts pose to homogeneous matrix.
- Args:
- pose (2-tuple): a (pos, orn) tuple where pos is vec3 float cartesian, and
orn is vec4 float quaternion.
- Returns:
np.array: 4x4 homogeneous matrix
-
igibson.utils.transform_utils.
pose_in_A_to_pose_in_B
(pose_A, pose_A_in_B) Converts a homogenous matrix corresponding to a point C in frame A to a homogenous matrix corresponding to the same point C in frame B.
- Args:
pose_A (np.array): 4x4 matrix corresponding to the pose of C in frame A pose_A_in_B (np.array): 4x4 matrix corresponding to the pose of A in frame B
- Returns:
np.array: 4x4 matrix corresponding to the pose of C in frame B
-
igibson.utils.transform_utils.
pose_inv
(pose) Computes the inverse of a homogeneous matrix corresponding to the pose of some frame B in frame A. The inverse is the pose of frame A in frame B.
- Args:
pose (np.array): 4x4 matrix for the pose to inverse
- Returns:
np.array: 4x4 matrix for the inverse pose
-
igibson.utils.transform_utils.
quat2axisangle
(quat) Converts quaternion to axis-angle format. Returns a unit vector direction scaled by its angle in radians.
- Args:
quat (np.array): (x,y,z,w) vec4 float angles
- Returns:
np.array: (ax,ay,az) axis-angle exponential coordinates
-
igibson.utils.transform_utils.
quat2mat
(quaternion) Converts given quaternion to matrix.
- Args:
quaternion (np.array): (x,y,z,w) vec4 float angles
- Returns:
np.array: 3x3 rotation matrix
-
igibson.utils.transform_utils.
quat_conjugate
(quaternion) Return conjugate of quaternion.
E.g.: >>> q0 = random_quaternion() >>> q1 = quat_conjugate(q0) >>> q1[3] == q0[3] and all(q1[:3] == -q0[:3]) True
- Args:
quaternion (np.array): (x,y,z,w) quaternion
- Returns:
np.array: (x,y,z,w) quaternion conjugate
-
igibson.utils.transform_utils.
quat_distance
(quaternion1, quaternion0) Returns distance between two quaternions, such that distance * quaternion0 = quaternion1
- Args:
quaternion1 (np.array): (x,y,z,w) quaternion quaternion0 (np.array): (x,y,z,w) quaternion
- Returns:
np.array: (x,y,z,w) quaternion distance
-
igibson.utils.transform_utils.
quat_inverse
(quaternion) Return inverse of quaternion.
E.g.: >>> q0 = random_quaternion() >>> q1 = quat_inverse(q0) >>> np.allclose(quat_multiply(q0, q1), [0, 0, 0, 1]) True
- Args:
quaternion (np.array): (x,y,z,w) quaternion
- Returns:
np.array: (x,y,z,w) quaternion inverse
-
igibson.utils.transform_utils.
quat_multiply
(quaternion1, quaternion0) Return multiplication of two quaternions (q1 * q0).
E.g.: >>> q = quat_multiply([1, -2, 3, 4], [-5, 6, 7, 8]) >>> np.allclose(q, [-44, -14, 48, 28]) True
- Args:
quaternion1 (np.array): (x,y,z,w) quaternion quaternion0 (np.array): (x,y,z,w) quaternion
- Returns:
np.array: (x,y,z,w) multiplied quaternion
-
igibson.utils.transform_utils.
quat_slerp
(quat0, quat1, fraction, shortestpath=True) Return spherical linear interpolation between two quaternions.
E.g.: >>> q0 = random_quat() >>> q1 = random_quat() >>> q = quat_slerp(q0, q1, 0.0) >>> np.allclose(q, q0) True
>>> q = quat_slerp(q0, q1, 1.0) >>> np.allclose(q, q1) True
>>> q = quat_slerp(q0, q1, 0.5) >>> angle = math.acos(np.dot(q0, q)) >>> np.allclose(2.0, math.acos(np.dot(q0, q1)) / angle) or np.allclose(2.0, math.acos(-np.dot(q0, q1)) / angle) True
- Args:
quat0 (np.array): (x,y,z,w) quaternion startpoint quat1 (np.array): (x,y,z,w) quaternion endpoint fraction (float): fraction of interpolation to calculate shortestpath (bool): If True, will calculate the shortest path
- Returns:
np.array: (x,y,z,w) quaternion distance
-
igibson.utils.transform_utils.
random_axis_angle
(angle_limit=None, random_state=None) Samples an axis-angle rotation by first sampling a random axis and then sampling an angle. If @angle_limit is provided, the size of the rotation angle is constrained.
If @random_state is provided (instance of np.random.RandomState), it will be used to generate random numbers.
- Args:
angle_limit (None or float): If set, determines magnitude limit of angles to generate random_state (None or RandomState): RNG to use if specified
- Raises:
AssertionError: [Invalid RNG]
-
igibson.utils.transform_utils.
random_quat
(rand=None) Return uniform random unit quaternion.
E.g.: >>> q = random_quat() >>> np.allclose(1.0, vector_norm(q)) True >>> q = random_quat(np.random.random(3)) >>> q.shape (4,)
- Args:
- rand (3-array or None): If specified, must be three independent random variables that are uniformly distributed
between 0 and 1.
- Returns:
np.array: (x,y,z,w) random quaternion
-
igibson.utils.transform_utils.
rotation_matrix
(angle, direction, point=None) Returns matrix to rotate about axis defined by point and direction.
- E.g.:
>>> angle = (random.random() - 0.5) * (2*math.pi) >>> direc = numpy.random.random(3) - 0.5 >>> point = numpy.random.random(3) - 0.5 >>> R0 = rotation_matrix(angle, direc, point) >>> R1 = rotation_matrix(angle-2*math.pi, direc, point) >>> is_same_transform(R0, R1) True
>>> R0 = rotation_matrix(angle, direc, point) >>> R1 = rotation_matrix(-angle, -direc, point) >>> is_same_transform(R0, R1) True
>>> I = numpy.identity(4, numpy.float32) >>> numpy.allclose(I, rotation_matrix(math.pi*2, direc)) True
>>> numpy.allclose(2., numpy.trace(rotation_matrix(math.pi/2, ... direc, point))) True
- Args:
angle (float): Magnitude of rotation direction (np.array): (ax,ay,az) axis about which to rotate point (None or np.array): If specified, is the (x,y,z) point about which the rotation will occur
- Returns:
np.array: 4x4 homogeneous matrix that includes the desired rotation
-
igibson.utils.transform_utils.
unit_vector
(data, axis=None, out=None) Returns ndarray normalized by length, i.e. eucledian norm, along axis.
- E.g.:
>>> v0 = numpy.random.random(3) >>> v1 = unit_vector(v0) >>> numpy.allclose(v1, v0 / numpy.linalg.norm(v0)) True
>>> v0 = numpy.random.rand(5, 4, 3) >>> v1 = unit_vector(v0, axis=-1) >>> v2 = v0 / numpy.expand_dims(numpy.sqrt(numpy.sum(v0*v0, axis=2)), 2) >>> numpy.allclose(v1, v2) True
>>> v1 = unit_vector(v0, axis=1) >>> v2 = v0 / numpy.expand_dims(numpy.sqrt(numpy.sum(v0*v0, axis=1)), 1) >>> numpy.allclose(v1, v2) True
>>> v1 = numpy.empty((5, 4, 3), dtype=numpy.float32) >>> unit_vector(v0, axis=1, out=v1) >>> numpy.allclose(v1, v2) True
>>> list(unit_vector([])) []
>>> list(unit_vector([1.0])) [1.0]
- Args:
data (np.array): data to normalize axis (None or int): If specified, determines specific axis along data to normalize out (None or np.array): If specified, will store computation in this variable
- Returns:
None or np.array: If @out is not specified, will return normalized vector. Otherwise, stores the output in @out
-
igibson.utils.transform_utils.
vec
(values) Converts value tuple into a numpy vector.
- Args:
values (n-array): a tuple of numbers
- Returns:
np.array: vector of given values
-
igibson.utils.transform_utils.
vel_in_A_to_vel_in_B
(vel_A, ang_vel_A, pose_A_in_B) Converts linear and angular velocity of a point in frame A to the equivalent in frame B.
- Args:
vel_A (np.array): (vx,vy,vz) linear velocity in A ang_vel_A (np.array): (wx,wy,wz) angular velocity in A pose_A_in_B (np.array): 4x4 matrix corresponding to the pose of A in frame B
- Returns:
2-tuple:
(np.array) (vx,vy,vz) linear velocities in frame B
(np.array) (wx,wy,wz) angular velocities in frame B
igibson.utils.urdf_utils module
igibson.utils.utils module
igibson.utils.vision_utils module
-
class
igibson.utils.vision_utils.
RandomScale
(minsize, maxsize, interpolation=2) Bases:
object
Rescale the input PIL.Image to the given size. Args: size (sequence or int): Desired output size. If size is a sequence like (w, h), output size will be matched to this. If size is an int, smaller edge of the image will be matched to this number. i.e, if height > width, then image will be rescaled to (size * height / width, size) interpolation (int, optional): Desired interpolation. Default is
PIL.Image.BILINEAR
-
igibson.utils.vision_utils.
randomize_colors
(N, bright=True) Modified from https://github.com/matterport/Mask_RCNN/blob/master/mrcnn/visualize.py#L59 Generate random colors. To get visually distinct colors, generate them in HSV space then convert to RGB.
-
igibson.utils.vision_utils.
segmentation_to_rgb
(seg_im, N, colors=None) Helper function to visualize segmentations as RGB frames. NOTE: assumes that geom IDs go up to N at most - if not, multiple geoms might be assigned to the same color.
igibson.utils.vr_log_converter module
igibson.utils.vr_plot_profiling module
Code to plot realtime graph.
To use, run the iGibson simulator loop with simulator.step(print_stats=True) and redirect stdout to a file:
python my_gibson_test.py > log.txt
and provide log.txt to the profiling script via the –filename arg
-
igibson.utils.vr_plot_profiling.
main
()
-
igibson.utils.vr_plot_profiling.
parse_args
()