open-space-collective / open-space-toolkit-physics

Physical units, time, reference frames, environment modeling.
https://open-space-collective.github.io/open-space-toolkit-physics/
Apache License 2.0
25 stars 7 forks source link

feat: global environment singleton #267

Closed vishwa2710 closed 1 month ago

vishwa2710 commented 1 month ago

In this MR, we add the concept of a central celestial object to the Environment, and additionally create a "global" environment instance which is a singleton. This is to simplify the instantiation of several objects in OSTk Physics, Astro and Simulation which typically operate for a central celestial object.

Like in simulation toolkits, where you specify your environment and then conduct your analysis, we can now create an Environment and set it to global. This environment will then be used as required by various functions. We still retain the ability to provide celestial specific parameters, if we want to override the global environment. Therefore this is a backwards compatible change.

from ostk.physics import Environment
from ostk.physics.environment.object.celestial import Earth
from ostk.physics.coordinate.spherical import LLA

environment = Environment.default(set_global_instance=True)

lla_1 = LLA.vector([0.0, 0.0, 0.0])
lla_2 = LLA.vector([1.0, 0.0, 0.0])

distance = lla_1.calculate_distance_to(lla_2)  # 110574.38855779878 [m]

egm96_earth = Earth.EGM96()
eg96_distance = lla_1.calculate_distance_to(
    lla_2,
    egm96_earth.get_equatorial_radius(),
    egm96_earth.get_flattening()
) # 110574.37642226892 [m]

We can instantiate orbits similarly and convert COEs etc. using these defaults.

codecov[bot] commented 1 month ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 81.78%. Comparing base (b40541c) to head (ceeda22). Report is 1 commits behind head on main.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #267 +/- ## ========================================== + Coverage 81.22% 81.78% +0.55% ========================================== Files 97 99 +2 Lines 8106 8244 +138 ========================================== + Hits 6584 6742 +158 + Misses 1522 1502 -20 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.