Gravity Models¶
Gravity acceleration functions including point-mass and spherical harmonic models.
Note
For conceptual explanations and examples, see Gravity Models in the Learn section.
Point-Mass Gravity¶
accel_point_mass_gravity builtin ¶
Compute acceleration due to point-mass gravity.
Accepts either a 3D position vector or a 6D state vector for r_object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
r_object | ndarray | Position (length 3) or state (length 6) of the object. Units: (m) | required |
r_central_body | ndarray | Position vector of the central body. Units: (m) | required |
gm | float | Gravitational parameter. Units: (m³/s²) | required |
Returns:
| Type | Description |
|---|---|
ndarray | np.ndarray: Acceleration due to gravity. Units: (m/s²) |
Spherical Harmonic Gravity¶
accel_gravity_spherical_harmonics builtin ¶
accel_gravity_spherical_harmonics(r_eci: ndarray, R_i2b: ndarray, gravity_model: GravityModel, n_max: int, m_max: int) -> ndarray
Compute acceleration due to spherical harmonic gravity model.
This function computes the gravitational acceleration on an object using a spherical harmonic expansion of Earth's gravity field. It transforms the position to body-fixed coordinates, evaluates the spherical harmonics, and transforms the acceleration back to the inertial frame.
Accepts either a 3D position vector or a 6D state vector for r_eci.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
r_eci | ndarray | Position (length 3) or state (length 6) in ECI frame. Units: (m) | required |
R_i2b | ndarray | Rotation matrix from ECI to body-fixed frame (3x3) | required |
gravity_model | GravityModel | Gravity model to use | required |
n_max | int | Maximum degree to evaluate (n_max <= model.n_max) | required |
m_max | int | Maximum order to evaluate (m_max <= min(n_max, model.m_max)) | required |
Returns:
| Type | Description |
|---|---|
ndarray | np.ndarray: Acceleration in ECI frame. Units: (m/s²) |
Raises:
| Type | Description |
|---|---|
Exception | If n_max or m_max exceed model limits or if m_max > n_max |
Example
Gravity Model Class¶
GravityModel ¶
Spherical harmonic gravity model for high-fidelity gravitational acceleration computation.
This class represents a spherical harmonic expansion of Earth's gravitational potential, allowing for accurate modeling of Earth's non-uniform gravity field.
Initialize instance.
compute_spherical_harmonics method descriptor ¶
Compute gravitational acceleration in body-fixed frame using spherical harmonics.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
r_body | ndarray | Position vector in body-fixed frame. Units: (m) | required |
n_max | int | Maximum degree to evaluate (n_max <= model.n_max) | required |
m_max | int | Maximum order to evaluate (m_max <= min(n_max, model.m_max)) | required |
Returns:
| Type | Description |
|---|---|
ndarray | np.ndarray: Acceleration in body-fixed frame. Units: (m/s²) |
Raises:
| Type | Description |
|---|---|
Exception | If n_max or m_max exceed model limits or if m_max > n_max |
from_file builtin ¶
from_file(filepath: str) -> GravityModel
Load gravity model from a .gfc file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filepath | str | Path to the .gfc gravity model file | required |
Returns:
| Name | Type | Description |
|---|---|---|
GravityModel | GravityModel | Loaded gravity model |
Raises:
| Type | Description |
|---|---|
Exception | If file cannot be loaded or parsed |
from_model_type builtin ¶
from_model_type(model_type: GravityModelType) -> GravityModel
Load a gravity model from a GravityModelType.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_type | GravityModelType | Which model to load (packaged or from file) | required |
Returns:
| Name | Type | Description |
|---|---|---|
GravityModel | GravityModel | Loaded gravity model |
Raises:
| Type | Description |
|---|---|
Exception | If file loading fails (for FromFile variant) |
Example
get method descriptor ¶
Get spherical harmonic coefficients for a specific degree and order.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n | int | Degree (0 <= n <= n_max) | required |
m | int | Order (0 <= m <= min(n, m_max)) | required |
Returns:
| Name | Type | Description |
|---|---|---|
tuple | Tuple | (C_nm, S_nm) coefficients |
Raises:
| Type | Description |
|---|---|
Exception | If n or m are out of bounds |
set_max_degree_order method descriptor ¶
Truncate the gravity model to a smaller degree and order to save memory.
This method resizes the internal coefficient matrix in-place, discarding coefficients beyond the specified limits. This is useful when loading a high-fidelity model but only needing a lower-degree expansion.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n | int | New maximum degree (must be <= current n_max) | required |
m | int | New maximum order (must be <= min(n, current m_max)) | required |
Raises:
| Type | Description |
|---|---|
ValueError | If m > n or if n/m exceed current model limits |
Example
See Also¶
- Gravity Models (Learn) - Conceptual explanation and examples
- Orbital Dynamics Module - Complete orbit dynamics API reference