Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Comms expansion #209

Open
wants to merge 36 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
1ed3e59
Added models
Jan 17, 2024
abd9fcd
Added additional calculations
Jan 17, 2024
8ee579b
Added tests for communication models and calculations
Jan 17, 2024
4c376af
Fix typo
Feb 6, 2024
0d7298e
Fixed typo
Feb 6, 2024
b840d2c
Comments and cleanup
Feb 7, 2024
7b31547
Tests refactoring
Feb 7, 2024
00da78e
Update
Feb 7, 2024
02f710e
Update
Feb 7, 2024
c0a1c27
Merge branch 'main' into comms_expansion
Feb 7, 2024
ebb0e79
Fixed circular reference errors
Feb 8, 2024
09079cb
Added .idea to gitignore
Feb 8, 2024
4177086
Bugfix after the refactoring
Feb 8, 2024
28ed261
Refactoring
Feb 8, 2024
f6e1de5
Applied black formatting
Feb 8, 2024
c31c38c
Black format attempt 2
Feb 8, 2024
68296cf
Flake8 attempt 1
Feb 8, 2024
c9077b5
Flake8 attempt 2
Feb 8, 2024
5526e95
Black formatting attempt 3
Feb 8, 2024
b9dc375
Add pylintrc to gitignore
Feb 8, 2024
9e31d2e
Delete pylintrc
timsmitdelft Feb 8, 2024
6a5352c
Merge branch 'comms_expansion' of https://github.com/aidotse/PASEOS i…
Feb 8, 2024
8481664
Docstrings
Feb 26, 2024
76c7a47
Updated readme with comms link budget example
Feb 26, 2024
c6311f3
Removed one layer of abstraction
Feb 26, 2024
16c82c9
Updated example notebooks
Feb 26, 2024
ca5ac42
Added constants
Feb 26, 2024
ef5dbb7
Moved comms utils to comms folder
Feb 26, 2024
9bff5eb
Moved comm links to actor instead of paseos
Feb 26, 2024
0583471
Updated comms tests
Feb 26, 2024
1b5d536
Moved tests
Feb 26, 2024
2082b42
Formatting
Feb 26, 2024
51a2dc3
Black formatting with line length 100
Feb 26, 2024
991968d
Improved docstrings
Feb 26, 2024
90af927
Added comments to tests
Feb 26, 2024
44a2ead
Allow radio receiver on satellite
Feb 27, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,9 @@ dmypy.json
# Pyre type checker
.pyre/

.idea
pylintrc

my_notebooks
.vscode
examples/Sentinel_2_example_notebook/Etna_00.tif
Expand Down
82 changes: 82 additions & 0 deletions examples/Communication_example/communication_example_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
import numpy as np
import pandas as pd


def get_known_actor_comms_status(values):
"""Helper function to track comms status"""
timsmitdelft marked this conversation as resolved.
Show resolved Hide resolved
conv_values = []
for val in values:
status = ["No signal", "Ground only", "CommSat only", "Ground + Sat"]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

status shall be implemented as enum, not as string.

idx = ("comms_1" in val) * 2 + 1 * ("gs_1" in val)
conv_values.append(status[idx])
return conv_values


def get_bitrate_status(link):
"""Helper function to get bitrate status history"""
return link.bitrate_history


def get_line_of_sight_status(link):
"""Helper function to get line of sight status history"""
return link.line_of_sight_history


def get_distance_status(link):
"""Helper function to distance status history"""
return link.distance_history


def get_elevation_angle_status(link):
"""Helper function to get elevation angle status history"""
return link.elevation_angle_history


def get_closest_entry(df, t, id):
timsmitdelft marked this conversation as resolved.
Show resolved Hide resolved
df_id = df[df.ID == id]
return df_id.iloc[(df_id["Time"] - t).abs().argsort().iloc[:1]]


def get_analysis_df(df, timestep=60, orbital_period=1):
timsmitdelft marked this conversation as resolved.
Show resolved Hide resolved
t = np.round(np.linspace(0, df.Time.max(), int(df.Time.max() // timestep)))
sats = df.ID.unique()
df["known_actors"] = pd.Categorical(df.known_actors)
df["comm_cat"] = df.known_actors.cat.codes
standby = []
processing = []
is_in_eclipse = []
comm_stat = [[], [], [], []]

for idx, t_cur in enumerate(t):
n_c = 0
n_ec = 0
for c in comm_stat:
c.append(0)
for sat in sats:
vals = get_closest_entry(df, t_cur, sat)
n_c += vals.current_activity.values[0] == "Standby"
n_ec += vals.is_in_eclipse.values[0]
c_idx = vals.comm_cat.values[0]
comm_stat[c_idx][idx] += 1
standby.append(n_c)
processing.append(len(sats) - n_c)
is_in_eclipse.append(n_ec)

ana_df = pd.DataFrame(
{
"Time[s]": t,
"# of Standby": standby,
"# of Processing": processing,
"# in Eclipse": is_in_eclipse,
"# of " + df.known_actors.cat.categories[0]: comm_stat[0],
"# of " + df.known_actors.cat.categories[1]: comm_stat[1],
"# of " + df.known_actors.cat.categories[2]: comm_stat[2],
# "# of " + df.known_actors.cat.categories[3]: comm_stat[3],
}
)
ana_df["Completed orbits"] = ana_df["Time[s]"] / orbital_period
ana_df = ana_df.round({"Completed orbits": 2})
ana_df["Share Processing"] = ana_df["# of Processing"] / len(sats)
ana_df["Share in Eclipse"] = ana_df["# in Eclipse"] / len(sats)

return ana_df
721 changes: 721 additions & 0 deletions examples/Communication_example/communication_simple_ground.ipynb
timsmitdelft marked this conversation as resolved.
Show resolved Hide resolved

Large diffs are not rendered by default.

649 changes: 649 additions & 0 deletions examples/Communication_example/communication_simple_satellite.ipynb
timsmitdelft marked this conversation as resolved.
Show resolved Hide resolved

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion examples/Constellation_example/constellation.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -849,7 +849,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.8 | packaged by conda-forge | (main, Nov 22 2022, 08:16:33) [MSC v.1929 64 bit (AMD64)]"
"version": "3.11.6"
},
"vscode": {
"interpreter": {
Expand Down
39 changes: 25 additions & 14 deletions paseos/__init__.py
Original file line number Diff line number Diff line change
@@ -1,35 +1,43 @@
from loguru import logger
from dotmap import DotMap
import pykep as pk
from dotmap import DotMap
from loguru import logger

from .utils.load_default_cfg import load_default_cfg
from .utils.check_cfg import check_cfg
from .paseos import PASEOS
from .actors.base_actor import BaseActor
from .actors.actor_builder import ActorBuilder
from .actors.base_actor import BaseActor
from .actors.ground_station_actor import GroundstationActor
from .actors.spacecraft_actor import SpacecraftActor
from .central_body.central_body import CentralBody
from .communication.get_communication_window import get_communication_window
from .communication.find_next_window import find_next_window
from .communication.get_communication_window import get_communication_window
from .paseos import PASEOS
from .power.power_device_type import PowerDeviceType
from .utils.check_cfg import check_cfg
from .utils.load_default_cfg import load_default_cfg
from .utils.reference_frame import ReferenceFrame
from .utils.set_log_level import set_log_level
from .visualization.plot import plot, PlotType


set_log_level("WARNING")

logger.debug("Loaded module.")


def init_sim(local_actor: BaseActor, cfg: DotMap = None, starting_epoch: pk.epoch = None):
def init_sim(
local_actor: BaseActor,
cfg: DotMap = None,
starting_epoch: pk.epoch = None,
communication_links=None,
):
"""Initializes PASEOS

Args:
local_actor (BaseActor): The actor linked to the local device which is required to model anything.
cfg (DotMap, optional): Configuration file. If None, default configuration will be used. Defaults to None.
starting_epoch(pk.epoch): Starting epoch of the simulation. Will override cfg and local actor one.
local_actor (BaseActor): The actor linked to the local device which is required to model
anything.
cfg (DotMap, optional): Configuration file. If None, default configuration will be used.
Defaults to None.
starting_epoch(pk.epoch): Starting epoch of the simulation. Will override cfg and local
actor one.
communication_links: A list of links from this instance to others.
Returns:
PASEOS: Instance of the simulation (only one can exist, singleton)
"""
Expand All @@ -47,11 +55,14 @@ def init_sim(local_actor: BaseActor, cfg: DotMap = None, starting_epoch: pk.epoc

if local_actor.local_time.mjd2000 * pk.DAY2SEC != cfg.sim.start_time:
logger.warning(
"You provided a different starting epoch for PASEOS than the local time of the local actor."
"You provided a different starting epoch for PASEOS than the local time of the local "
"actor."
+ "starting_epoch will be used."
)

sim = PASEOS(local_actor=local_actor, cfg=cfg)
sim = PASEOS(
local_actor=local_actor, cfg=cfg, communication_links=communication_links
)
return sim


Expand Down
Loading
Loading