Skip to content

Commit

Permalink
feat: update notebooks to OSTk astro ~14.0 (#161)
Browse files Browse the repository at this point in the history
feat: update notebooks to OSTk astro ~14.0
  • Loading branch information
vishwa2710 authored Jan 27, 2025
1 parent 9f35793 commit 59bfce0
Show file tree
Hide file tree
Showing 6 changed files with 123 additions and 78 deletions.
161 changes: 100 additions & 61 deletions notebooks/Astrodynamics/Flight Dynamics/Access Computation.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,14 @@
"from ostk.physics.time import DateTime\n",
"from ostk.physics.time import Time\n",
"from ostk.physics.coordinate.spherical import LLA\n",
"from ostk.physics.coordinate import Position\n",
"from ostk.physics.coordinate import Frame\n",
"\n",
"from ostk.astrodynamics import Trajectory\n",
"from ostk.astrodynamics.trajectory import Orbit\n",
"from ostk.astrodynamics.trajectory.orbit.model import Kepler\n",
"from ostk.astrodynamics.trajectory.orbit.model.kepler import COE\n",
"from ostk.astrodynamics.trajectory.orbit.model import SGP4\n",
"from ostk.astrodynamics.trajectory.orbit.model.sgp4 import TLE\n",
"from ostk.astrodynamics.access import Generator as AccessGenerator\n",
"from ostk.astrodynamics.access import AccessTarget\n",
"from ostk.astrodynamics.access import VisibilityCriterion\n",
"from ostk.astrodynamics.utilities import compute_trajectory_geometry\n",
"from ostk.astrodynamics.utilities import compute_time_lla_aer_coordinates"
]
Expand Down Expand Up @@ -105,7 +103,7 @@
"metadata": {},
"outputs": [],
"source": [
"environment = Environment.default()\n",
"environment = Environment.default(True) # Set global environment instance as the default instance \n",
"earth = environment.access_celestial_object_with_name(\"Earth\")"
]
},
Expand All @@ -120,55 +118,89 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"Let's define a fixed ground position, using its geographic coordinates:"
"#### Visibility Criterion\n",
"Let's define a visibility criterion, there are currently 4 types of Visibility Criterion\n",
"- AERInterval : Defined by Azimuth, Elevation and Range intervals (typically used for accesses with Ground Stations)\n",
"- ElevationInterval : Defined solely by an Elevation interval (typically used for imaging windows)\n",
"- AERMask : Defined by an Azimuth-Elevation mask, and a Range interval (typically used for accesses with Ground Stations)\n",
"- LineOfSight : Defined by a pure line of sight constraint, occluded by the bodies in the provided Environment (typically used for Satellite <-> Satellite accesses)"
]
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"latitude = Angle.degrees(50.0)\n",
"longitude = Angle.degrees(20.0)\n",
"altitude = Length.meters(30.0)"
"visibility_criterion = VisibilityCriterion.from_aer_interval(\n",
" azimuth_interval=RealInterval.closed(0.0, 360.0), # [deg]\n",
" elevation_interval=RealInterval.closed(0.0, 90.0), # [deg]\n",
" range_interval=RealInterval.closed(0.0, 10000e3), # [m]\n",
")"
]
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from_lla = LLA(latitude, longitude, altitude)"
"# visibility_criterion = VisibilityCriterion.from_aer_mask(\n",
"# azimuth_elevation_mask={0.0: 0.0, 90.0: 45.0, 270.0: 30.0},\n",
"# range_interval=RealInterval.closed(0.0, 10000e3),\n",
"# )"
]
},
{
"cell_type": "code",
"execution_count": 6,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from_position = Position.meters(\n",
" from_lla.to_cartesian(earth.get_equatorial_radius(), earth.get_flattening()),\n",
" Frame.ITRF(),\n",
")"
"# visibility_criterion = VisibilityCriterion.from_elevation_interval(\n",
"# elevation_interval=RealInterval.closed(80.0, 90.0),\n",
"# )"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# visibility_criterion = VisibilityCriterion.from_line_of_sight(\n",
"# environment=environment,\n",
"# )"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"And derive a trajectory, fixed at that position:"
"#### Access Target\n",
"Now that we have defined a visibility criterion, we can create an access target to compute accesses with.\n",
"Let's define a fixed ground position, using its geographic coordinates.\n",
"We can create a list of multiple access targets and compute a list of accesses corresponding to each access target"
]
},
{
"cell_type": "code",
"execution_count": 7,
"execution_count": 5,
"metadata": {},
"outputs": [],
"source": [
"from_trajectory = Trajectory.position(from_position)"
"access_target = AccessTarget.from_lla(\n",
" visibility_criterion=visibility_criterion,\n",
" lla=LLA(Angle.degrees(50.0), Angle.degrees(20.0), Length.meters(30.0)),\n",
" celestial=earth,\n",
")\n",
"another_access_target = AccessTarget.from_lla(\n",
" visibility_criterion=visibility_criterion,\n",
" lla=LLA(Angle.degrees(-50.0), Angle.degrees(10.0), Length.meters(30.0)),\n",
" celestial=earth,\n",
")\n",
"\n",
"access_targets = [access_target, another_access_target]"
]
},
{
Expand All @@ -185,15 +217,6 @@
"Let's consider a satellite in **Low-Earth Orbit**."
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [],
"source": [
"earth = environment.access_celestial_object_with_name(\"Earth\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
Expand Down Expand Up @@ -354,7 +377,7 @@
"start_instant = Instant.date_time(DateTime.parse(\"2018-01-01 00:00:00\"), Scale.UTC)\n",
"end_instant = Instant.date_time(DateTime.parse(\"2018-01-10 00:00:00\"), Scale.UTC)\n",
"\n",
"interval = Interval.closed(start_instant, end_instant);"
"interval = Interval.closed(start_instant, end_instant)"
]
},
{
Expand All @@ -370,15 +393,8 @@
"metadata": {},
"outputs": [],
"source": [
"azimuth_range = RealInterval.closed(0.0, 360.0) # [deg]\n",
"elevation_range = RealInterval.closed(20.0, 90.0) # [deg]\n",
"range_range = RealInterval.closed(0.0, 10000e3) # [m]\n",
"\n",
"# Access generator with Azimuth-Range-Elevation constraints\n",
"\n",
"access_generator = AccessGenerator.aer_ranges(\n",
" azimuth_range, elevation_range, range_range, environment\n",
")"
"access_generator = AccessGenerator(environment=environment)"
]
},
{
Expand All @@ -387,7 +403,38 @@
"metadata": {},
"outputs": [],
"source": [
"accesses = access_generator.compute_accesses(interval, from_trajectory, satellite_orbit)"
"accesses = access_generator.compute_accesses(\n",
" interval=interval,\n",
" access_targets=access_targets,\n",
" to_trajectory=satellite_orbit,\n",
")\n",
"\n",
"assert len(accesses) == len(access_targets) # a list of accesses per target\n",
"\n",
"first_target_accesses = accesses[0]\n",
"second_target_accesses = accesses[1]\n",
"\n",
"accesses_data = [\n",
" (\n",
" str(access.get_type()),\n",
" repr(access.get_acquisition_of_signal()),\n",
" repr(access.get_time_of_closest_approach()),\n",
" repr(access.get_loss_of_signal()),\n",
" float(access.get_duration().in_seconds()),\n",
" \"first_target\",\n",
" ) for access in first_target_accesses\n",
"]\n",
"\n",
"accesses_data += [\n",
" (\n",
" str(access.get_type()),\n",
" repr(access.get_acquisition_of_signal()),\n",
" repr(access.get_time_of_closest_approach()),\n",
" repr(access.get_loss_of_signal()),\n",
" float(access.get_duration().in_seconds()),\n",
" \"second_target\",\n",
" ) for access in second_target_accesses\n",
"]"
]
},
{
Expand All @@ -404,17 +451,8 @@
"outputs": [],
"source": [
"accesses_df = pd.DataFrame(\n",
" [\n",
" [\n",
" str(access.get_type()),\n",
" repr(access.get_acquisition_of_signal()),\n",
" repr(access.get_time_of_closest_approach()),\n",
" repr(access.get_loss_of_signal()),\n",
" float(access.get_duration().in_seconds()),\n",
" ]\n",
" for access in accesses\n",
" ],\n",
" columns=[\"Type\", \"AOS\", \"TCA\", \"LOS\", \"Duration\"],\n",
" data=accesses_data,\n",
" columns=[\"Type\", \"AOS\", \"TCA\", \"LOS\", \"Duration\", \"Target\"],\n",
")"
]
},
Expand Down Expand Up @@ -766,7 +804,7 @@
"source": [
"def compute_access_geometry(access):\n",
" return [\n",
" compute_time_lla_aer_coordinates(state, from_position, environment)\n",
" compute_time_lla_aer_coordinates(state, access_target.get_position(), environment)\n",
" for state in satellite_orbit.get_states_at(\n",
" access.get_interval().generate_grid(Duration.seconds(1.0))\n",
" )\n",
Expand All @@ -780,7 +818,7 @@
"outputs": [],
"source": [
"satellite_orbit_geometry_df = pd.DataFrame(\n",
" compute_trajectory_geometry(satellite_orbit, interval),\n",
" [lla.to_vector() for lla in compute_trajectory_geometry(satellite_orbit, interval)],\n",
" columns=[\"Latitude\", \"Longitude\", \"Altitude\"],\n",
")"
]
Expand Down Expand Up @@ -889,7 +927,7 @@
" ],\n",
" )\n",
" for access in accesses\n",
"];"
"]"
]
},
{
Expand Down Expand Up @@ -39233,15 +39271,16 @@
"\n",
"# Target geometry\n",
"\n",
"data.append(\n",
" dict(\n",
" type=\"scattergeo\",\n",
" lon=[float(longitude.in_degrees())],\n",
" lat=[float(latitude.in_degrees())],\n",
" mode=\"markers\",\n",
" marker=dict(size=10, color=\"orange\"),\n",
"for access_target in access_targets:\n",
" data.append(\n",
" dict(\n",
" type=\"scattergeo\",\n",
" lon=[float(access_target.get_lla(earth).in_degrees())],\n",
" lat=[float(access_target.get_lla(earth).in_degrees())],\n",
" mode=\"markers\",\n",
" marker=dict(size=10, color=\"orange\"),\n",
" )\n",
" )\n",
")\n",
"\n",
"# Orbit geometry\n",
"\n",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@
"# Constant Thrust Dynamics"
]
},
{
"cell_type": "markdown",
"id": "c5135c8e",
"metadata": {},
"source": []
},
{
"cell_type": "markdown",
"id": "a937df35-5b6c-4b85-a297-a53a8830e1cd",
Expand Down Expand Up @@ -82,8 +88,8 @@
"The dynamics child must have 4 methods defined:\n",
"- `is_defined` &rarr; used to verify that the class has been instantiated correctly\n",
"- `compute_contribution` &rarr; computes the contribution to the state derivative\n",
"- `get_read_coordinates_subsets` &rarr; defines the order expected for the state variable `x`\n",
"- `get_write_coordinates_subsets` &rarr; defines the order expected in the outputted contribution within `compute_contribution`"
"- `get_read_coordinate_subsets` &rarr; defines the order expected for the state variable `x`\n",
"- `get_write_coordinate_subsets` &rarr; defines the order expected in the outputted contribution within `compute_contribution`"
]
},
{
Expand All @@ -106,14 +112,14 @@
" def is_defined(self):\n",
" return self._isp is not None and self._thrust is not None\n",
"\n",
" def get_read_coordinates_subsets(self):\n",
" def get_read_coordinate_subsets(self):\n",
" return [\n",
" CartesianPosition.default(),\n",
" CartesianVelocity.default(),\n",
" CoordinateSubset.mass(),\n",
" ]\n",
"\n",
" def get_write_coordinates_subsets(self):\n",
" def get_write_coordinate_subsets(self):\n",
" return [CartesianVelocity.default(), CoordinateSubset.mass()]\n",
"\n",
" def compute_contribution(self, instant, x, frame):\n",
Expand Down Expand Up @@ -330,4 +336,4 @@
},
"nbformat": 4,
"nbformat_minor": 5
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@
"metadata": {},
"outputs": [],
"source": [
"orbit_data = [convert_state(instant, state) for [instant, state] in states]"
"orbit_data = [convert_state(state) for state in states]"
]
},
{
Expand Down Expand Up @@ -626,4 +626,4 @@
},
"nbformat": 4,
"nbformat_minor": 4
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"id": "260b01cf-af50-4a65-8388-06917b48aab8",
"metadata": {},
"source": [
"### Visualize Satellite States (Cesium)"
"### Visualize Satellite Trajectory (Cesium)"
]
},
{
Expand Down Expand Up @@ -98,7 +98,7 @@
"metadata": {},
"outputs": [],
"source": [
"profile = Profile.nadir_pointing(\n",
"profile = Profile.local_orbital_frame_pointing(\n",
" orbit=orbit,\n",
" orbital_frame_type=Orbit.FrameType.VVLH,\n",
")"
Expand Down Expand Up @@ -130,7 +130,7 @@
")\n",
"viewer.add_profile(\n",
" profile=profile,\n",
" step=Duration.seconds(30.0),\n",
" step=Duration.seconds(5.0),\n",
" show_orbital_track=True,\n",
" cesium_asset_id=669199,\n",
" sensors=[\n",
Expand Down
Loading

0 comments on commit 59bfce0

Please sign in to comment.