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 dispatches to whichever kernel the GravityModel's GravityModelCoefficients has precomputed (Clenshaw by default). accel_gravity_spherical_harmonics_clenshaw and accel_gravity_spherical_harmonics_cunningham force evaluation through a specific kernel instead of dispatching automatically.
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 |
|---|---|
ValueError | If n_max or m_max exceed model limits or if m_max > n_max |
ValueError | If the model has no precomputed gravity coefficients (neither Clenshaw nor Cunningham) |
ValueError | If the Cunningham kernel is used (no Clenshaw coefficients present on the model) and its denormalized recursion overflows to a non-finite result (can occur above ~degree 150 at low altitude) |
Example
accel_gravity_spherical_harmonics_clenshaw builtin ¶
accel_gravity_spherical_harmonics_clenshaw(r_eci: ndarray, R_i2b: ndarray, gravity_model: GravityModel, n_max: int, m_max: int) -> ndarray
Compute acceleration due to spherical harmonic gravity model using the Clenshaw kernel.
Same behavior as accel_gravity_spherical_harmonics, but forces evaluation through the Clenshaw summation kernel rather than dispatching automatically.
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 |
|---|---|
ValueError | If Clenshaw coefficients are not precomputed for the model, or if n_max or m_max exceed model limits |
accel_gravity_spherical_harmonics_cunningham builtin ¶
accel_gravity_spherical_harmonics_cunningham(r_eci: ndarray, R_i2b: ndarray, gravity_model: GravityModel, n_max: int, m_max: int) -> ndarray
Compute acceleration due to spherical harmonic gravity model using the Cunningham kernel.
Same behavior as accel_gravity_spherical_harmonics, but forces evaluation through the Cunningham V/W recursion kernel rather than dispatching automatically.
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 |
|---|---|
ValueError | If Cunningham coefficients are not precomputed for the model, if n_max or m_max exceed model limits, or if the recursion overflows to a non-finite result (can occur above ~degree 150 at low altitude) |
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.
Dispatches to whichever kernel this model has coefficients for. Clenshaw-first: if the model has precomputed Clenshaw coefficients (the default for every loader), evaluates with the Clenshaw summation kernel. Otherwise falls back to the Cunningham V/W recursion if Cunningham coefficients are present.
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 |
|---|---|
ValueError | If n_max or m_max exceed model limits or if m_max > n_max |
ValueError | If the model has neither Clenshaw nor Cunningham coefficients |
ValueError | If the Cunningham fallback is used and its denormalized recursion overflows to a non-finite result (can occur above ~degree 150 at low altitude) |
compute_spherical_harmonics_clenshaw method descriptor ¶
Compute body-fixed gravitational acceleration with the Clenshaw kernel.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
r_body | ndarray | Position in body-fixed frame (length 3). 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 |
|---|---|
ValueError | If Clenshaw coefficients are not precomputed for this model, or if n_max or m_max exceed model limits |
compute_spherical_harmonics_cunningham method descriptor ¶
Compute body-fixed gravitational acceleration with the Cunningham kernel.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
r_body | ndarray | Position in body-fixed frame (length 3). 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 |
|---|---|
ValueError | If Cunningham coefficients are not precomputed for this model, if n_max or m_max exceed model limits, or if the recursion overflows to a non-finite result (can occur above ~degree 150 at low altitude) |
convert_tide_system method descriptor ¶
convert_tide_system(from_system: GravityModelTideSystem, to_system: GravityModelTideSystem) -> Any
Convert the gravity model's tide system from one convention to another.
Adjusts the C̄₂₀ coefficient in-place so the model represents gravity in the target tide system. The conversion is exact for the permanent-tide component (IERS Conventions 2010, §6.2.2).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
from_system | GravityModelTideSystem | The tide system the model is currently in. | required |
to_system | GravityModelTideSystem | The tide system to convert to. | required |
Raises:
| Type | Description |
|---|---|
ValueError | If |
drop_cunningham_coefficients method descriptor ¶
drop_cunningham_coefficients() -> Any
Drop the Cunningham kernel coefficients, freeing their memory.
The Cunningham kernel errors until precompute_cunningham_coefficients() is called again.
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_file_with_coefficients builtin ¶
from_file_with_coefficients(filepath: str, coefficients: GravityModelCoefficients) -> GravityModel
Load a gravity model from a .gfc file with an explicit coefficient configuration.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filepath | str | Path to the .gfc gravity model file | required |
coefficients | GravityModelCoefficients | Which precomputed evaluation coefficient set(s) to build | 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
from_model_type_with_coefficients builtin ¶
from_model_type_with_coefficients(model_type: GravityModelType, coefficients: GravityModelCoefficients) -> GravityModel
Load a gravity model from a GravityModelType with an explicit coefficient configuration.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_type | GravityModelType | Which model to load (packaged or from file) | required |
coefficients | GravityModelCoefficients | Which precomputed evaluation coefficient set(s) to build | required |
Returns:
| Name | Type | Description |
|---|---|---|
GravityModel | GravityModel | Loaded gravity model |
Raises:
| Type | Description |
|---|---|
Exception | If file loading fails (for FromFile variant) |
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 |
get_c method descriptor ¶
Get the cosine coefficient C_nm 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 |
|---|---|---|
float | float | The C_nm coefficient. |
Raises:
| Type | Description |
|---|---|
ValueError | If n or m are out of bounds |
get_s method descriptor ¶
Get the sine coefficient S_nm 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 |
|---|---|---|
float | float | The S_nm coefficient (0.0 for m == 0). |
Raises:
| Type | Description |
|---|---|
ValueError | If n or m are out of bounds |
has_clenshaw_coefficients method descriptor ¶
has_clenshaw_coefficients() -> bool
Check whether the Clenshaw kernel coefficients are precomputed for this model.
Returns:
| Name | Type | Description |
|---|---|---|
bool | bool | True when the coefficient set is present. |
has_cunningham_coefficients method descriptor ¶
has_cunningham_coefficients() -> bool
Check whether the Cunningham kernel coefficients are precomputed for this model.
Returns:
| Name | Type | Description |
|---|---|---|
bool | bool | True when the coefficient set is present. |
load_uncached builtin ¶
load_uncached(model_type: GravityModelType) -> GravityModel
Parse a GravityModelType directly from its source, bypassing the process-wide cache.
Most callers should prefer :meth:from_model_type, which is cache-backed and avoids re-parsing the model on repeat calls. Reach for load_uncached when you need deterministic memory (each call allocates its own coefficients), to profile cold-load performance, or to re-read a FromFile source whose contents changed on disk (the cache would otherwise return the stale model).
Builds Clenshaw coefficients only. Call :meth:precompute_cunningham_coefficients on the returned model for a different coefficient configuration.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_type | GravityModelType | Which model to load (packaged or from file) | required |
Returns:
| Name | Type | Description |
|---|---|---|
GravityModel | GravityModel | Freshly parsed gravity model |
Raises:
| Type | Description |
|---|---|
Exception | If file loading fails (for FromFile variant) |
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
Gravity Model Coefficients¶
GravityModelCoefficients selects which kernel's precomputed coefficient set(s) a GravityModel builds when it is loaded (GravityModel.from_model_type / from_file default to GravityModelCoefficients.Clenshaw; from_model_type_with_coefficients / from_file_with_coefficients accept an explicit value): GravityModelCoefficients.Clenshaw (default), .Cunningham, or .Both. A model can only evaluate through a kernel whose coefficient set is present; GravityModel.precompute_clenshaw_coefficients() / precompute_cunningham_coefficients() add a coefficient set to an already-loaded model, and drop_clenshaw_coefficients() / drop_cunningham_coefficients() free one to reduce memory use.
GravityModelCoefficients ¶
Selects which precomputed coefficient set(s) a gravity model builds at load.
The Clenshaw and Cunningham kernels require different precomputed values, so each kernel can only run when its coefficient set is present. Default: Clenshaw.
Initialize instance.
Both class-attribute ¶
Both: Any = GravityModelCoefficients.Both
Selects which precomputed coefficient set(s) a gravity model builds at load.
The Clenshaw and Cunningham kernels require different precomputed values, so each kernel can only run when its coefficient set is present. Default: Clenshaw.
Clenshaw class-attribute ¶
Clenshaw: Any = GravityModelCoefficients.Clenshaw
Selects which precomputed coefficient set(s) a gravity model builds at load.
The Clenshaw and Cunningham kernels require different precomputed values, so each kernel can only run when its coefficient set is present. Default: Clenshaw.
Cunningham class-attribute ¶
Cunningham: Any = GravityModelCoefficients.Cunningham
Selects which precomputed coefficient set(s) a gravity model builds at load.
The Clenshaw and Cunningham kernels require different precomputed values, so each kernel can only run when its coefficient set is present. Default: Clenshaw.
Gravity Model Type¶
GravityModelType selects which spherical harmonic field is loaded into a GravityModel (or wired into a GravityConfiguration). In addition to the packaged constants EGM2008_120, GGM05S, and JGM3, two constructors load external models:
GravityModelType.from_file(path)— load any.gfcfile from disk.GravityModelType.icgem(body, name)— reference any model from the ICGEM catalog; the matching.gfcfile is downloaded into$BRAHE_CACHE/icgem/models/<body>/on first use and cached permanently.
The same GravityModelType can be passed to GravityConfiguration.spherical_harmonic(model_type=...) to use the model as the central-body field in a NumericalOrbitPropagator. For end-to-end usage examples see the ICGEM dataset guide and the Gravity Models user guide.
GravityModelType ¶
Default gravity models packaged with Brahe.
These models provide varying levels of fidelity for Earth's gravitational field. Models can either be packaged with Brahe or loaded from external files.
Initialize instance.
EGM2008_120 class-attribute ¶
EGM2008_120: Any = GravityModelType.EGM2008_120
Default gravity models packaged with Brahe.
These models provide varying levels of fidelity for Earth's gravitational field. Models can either be packaged with Brahe or loaded from external files.
GGM05S class-attribute ¶
GGM05S: Any = GravityModelType.GGM05S
Default gravity models packaged with Brahe.
These models provide varying levels of fidelity for Earth's gravitational field. Models can either be packaged with Brahe or loaded from external files.
JGM3 class-attribute ¶
JGM3: Any = GravityModelType.JGM3
Default gravity models packaged with Brahe.
These models provide varying levels of fidelity for Earth's gravitational field. Models can either be packaged with Brahe or loaded from external files.
from_file staticmethod ¶
from_file(filepath: str) -> GravityModelType
Load a custom gravity model from a file.
Validates that the file exists before returning the model type.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filepath | str | Path to the gravity model file in GFC format. | required |
Returns:
| Name | Type | Description |
|---|---|---|
GravityModelType | GravityModelType | Gravity model type for loading from file. |
Raises:
| Type | Description |
|---|---|
FileNotFoundError | If the file does not exist. |
IsADirectoryError | If the path is a directory, not a file. |
icgem staticmethod ¶
icgem(body: str, name: str) -> GravityModelType
Build a GravityModelType referencing an ICGEM model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
body | str | Body name ("earth", "moon", "mars", "venus", "ceres", or other). | required |
name | str | Model name, optionally with | required |
Returns:
| Name | Type | Description |
|---|---|---|
GravityModelType | GravityModelType | A new GravityModelType referencing the ICGEM model. |
See Also¶
- Gravity Models (Learn) - Conceptual explanation and examples
- ICGEM Dataset Interface (Learn) - Discovering and downloading ICGEM models
- ICGEM Functions API -
brahe.datasets.icgemAPI reference - Force Models (Learn) - Using a gravity model in a numerical propagator
- Orbital Dynamics Module - Complete orbit dynamics API reference