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

Visual implementation #27

Merged
merged 44 commits into from
Nov 22, 2022
Merged
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
e68c1ad
Changed name of init
johanos1 Oct 8, 2022
5f04f97
Merge branch 'main' of github.com:aidotse/PASEOS
johanos1 Oct 18, 2022
6fa1d00
Merge branch 'main' of github.com:aidotse/PASEOS
johanos1 Oct 21, 2022
d99d84f
First implementation of visualization for PASEOS
johanos1 Oct 23, 2022
77668f2
First implementation of visualization for PASEOS
johanos1 Oct 23, 2022
a33f978
Ability to save animation added
johanos1 Oct 24, 2022
a2be401
First implementation of visualization for PASEOS
johanos1 Oct 23, 2022
9edcdf1
Animation added to class
johanos1 Oct 24, 2022
8f9f0b7
First implementation of visualization for PASEOS
johanos1 Oct 24, 2022
1e38513
Fixed review comments
johanos1 Oct 24, 2022
605e056
Updated requirements
johanos1 Oct 24, 2022
4ff2201
Tests included
johanos1 Oct 24, 2022
1166add
Merge branch 'visual_implementation' of github.com:aidotse/PASEOS int…
johanos1 Oct 24, 2022
f4bafcd
Removed redundant properties in paseos + spacecraftactor
johanos1 Oct 27, 2022
8000098
Tests added and minimal examples.
johanos1 Oct 27, 2022
352f1a5
Readme updated + communication plotted
johanos1 Oct 27, 2022
3c34f97
Lint fixes
johanos1 Oct 27, 2022
9b2db8f
lint fix
johanos1 Oct 27, 2022
cf812ac
lint fixes
johanos1 Oct 27, 2022
1f7490b
lint fix
johanos1 Oct 27, 2022
cb0b41b
lint again...
johanos1 Oct 27, 2022
ccc7373
Removed otf file for fontawesome
johanos1 Oct 27, 2022
186f2bb
Updated examples and fixed docstrings
johanos1 Oct 28, 2022
2127bd7
Jupyter example added
johanos1 Oct 28, 2022
c5c0183
Axes scales automatically
johanos1 Oct 28, 2022
9502420
formatting using black
johanos1 Oct 29, 2022
0c03df1
Colon linting for flake...
johanos1 Oct 29, 2022
d7e1a4f
Flake8 :/
johanos1 Oct 29, 2022
4ec6b5e
Fine tuning to animation
johanos1 Nov 6, 2022
ef75b2c
WIP
gomezzz Nov 11, 2022
6feb866
Bugfixing and beautification
gomezzz Nov 11, 2022
9aec062
- Some renaming, refactoring
gomezzz Nov 14, 2022
ed2c532
Removing duplicate code, flake fixes, getting rid of matplotlib warnings
gomezzz Nov 14, 2022
931d088
applying comments from previous review
gomezzz Nov 14, 2022
618fc42
Merge branch 'main' into visual-implementation-follow-up
gomezzz Nov 14, 2022
ce2a85d
readded try catch
gomezzz Nov 15, 2022
538ddc7
Merge pull request #39 from aidotse/visual-implementation-follow-up
gomezzz Nov 16, 2022
b724943
Merge branch 'main' into visual_implementation
gomezzz Nov 16, 2022
c72394f
flaking
johanos1 Nov 17, 2022
659668c
Readme update and small review comments
johanos1 Nov 18, 2022
3e9e218
Update README.md
johanos1 Nov 22, 2022
03d16fc
Update README.md
johanos1 Nov 22, 2022
bba16cf
Update README.md
johanos1 Nov 22, 2022
0bbfc19
Update README.md
johanos1 Nov 22, 2022
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
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,17 @@ This project is currently under development. Use at your own risk. :)
<p align="center">
Description of PASEOS workflow on an individual device
</p>
</p>

## Visualising PASEOS
Navigate to paseos/visualization_example to find minimal examples of how to visualize PASEOS.
gomezzz marked this conversation as resolved.
Show resolved Hide resolved
Visualization can be done in interactive mode or as an animation that is saved to disc.

<p align="center">
<a href="https://github.com/aidotse/PASEOS/">
<img src="resources/images/animation.png" alt="Scheme" width="500" height="500">
</a>
<p align="center">
Snapshot of PASEOS visualization
</p>
</p>
1 change: 1 addition & 0 deletions environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ dependencies:
- sphinx_rtd_theme
- toml
- tqdm
- matplotlib
2 changes: 1 addition & 1 deletion paseos/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@ def init_sim(local_actor: BaseActor):
return sim


__all__ = ["ActorBuilder", "GroundstationActor", "SpacecraftActor"]
gomezzz marked this conversation as resolved.
Show resolved Hide resolved
__all__ = ["ActorBuilder", "GroundstationActor", "SpacecraftActor", "SpaceAnimation"]
11 changes: 1 addition & 10 deletions paseos/actors/spacecraft_actor.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ def __init__(
epoch: pk.epoch,
) -> None:
"""Constructor for a spacecraft actor
gomezzz marked this conversation as resolved.
Show resolved Hide resolved

Args:
name (str): Name of this actor
position (list of floats): [x,y,z]
Expand All @@ -35,7 +34,6 @@ def __init__(
@property
def charging_rate_in_W(self):
"""Get the current charging rate.

Returns:
float: current charging rate in W.
"""
Expand All @@ -44,7 +42,6 @@ def charging_rate_in_W(self):
@property
def battery_level_in_Ws(self):
"""Get the current battery level.

Returns:
float: current battery level in wattseconds.
"""
Expand All @@ -53,15 +50,13 @@ def battery_level_in_Ws(self):
@property
def battery_level_ratio(self):
"""Get the current battery level as ratio of maximum.

Returns:
float: current battery level ratio in [0,1].
"""
return self._battery_level_in_Ws / self._max_battery_level_in_Ws

def discharge(self, consumption_rate_in_W: float, duration_in_s: float):
"""Discharge battery depending on power consumption.

Args:
consumption_rate_in_W (float): Consumption rate of the activity in Watt
duration_in_s (float): How long the activity is performed in seconds
Expand All @@ -78,17 +73,13 @@ def charge(self, t0: pk.epoch, t1: pk.epoch):
"""Charges the actor during that period. Note that it is only
verified the actor is neither at start nor end of the period in eclipse,
thus short periods are preferable.

Args:
t0 (pk.epoch): Start of the charging interval
t1 (pk.epoch): End of the charging interval

"""
time_interval = (t1.mjd2000 - t0.mjd2000) * pk.DAY2SEC
logger.debug(f"Charging actor {self} for {time_interval}s.")
assert (
time_interval > 0
), "Charging interval has to be positive but t1 was less or equal t0."
assert time_interval > 0, "Charging interval has to be positive but t1 was less or equal t0."
gomezzz marked this conversation as resolved.
Show resolved Hide resolved
gomezzz marked this conversation as resolved.
Show resolved Hide resolved

if is_in_eclipse(self, central_body=self._central_body, t=t0) or is_in_eclipse(
self, central_body=self._central_body, t=t1
Expand Down
14 changes: 2 additions & 12 deletions paseos/paseos.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ def __init__(self, local_actor: BaseActor):

def advance_time(self, time_to_advance: float):
"""Advances the simulation by a specified amount of time
Copy link
Collaborator

Choose a reason for hiding this comment

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

same as in spacecraft actor, these white spaces are part of the docstring format


Args:
time_to_advance (float): Time to advance in seconds.
"""
Expand Down Expand Up @@ -78,7 +77,6 @@ def advance_time(self, time_to_advance: float):

def add_known_actor(self, actor: BaseActor):
"""Adds an actor to the simulation.

Args:
actor (BaseActor): Actor to add
"""
Expand All @@ -95,7 +93,6 @@ def add_known_actor(self, actor: BaseActor):
@property
def local_actor(self) -> BaseActor:
"""Returns the local actor.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Please revert these white space changes. There should be an empty line after description to follow https://sphinxcontrib-napoleon.readthedocs.io/en/latest/example_google.html

Returns:
BaseActor: Local actor
"""
Expand All @@ -104,7 +101,6 @@ def local_actor(self) -> BaseActor:
@property
def known_actors(self) -> dict:
"""Returns known actors.

Returns:
dict of BaseActor: Dictionary of the known actors.
"""
Expand All @@ -113,7 +109,6 @@ def known_actors(self) -> dict:
@property
def known_actor_names(self) -> list:
"""Returns names of known actors.

Returns:
list: List of names of known actors.
"""
Expand All @@ -125,7 +120,6 @@ def emtpy_known_actors(self):

def remove_known_actor(self, actor_name: str):
"""Remove an actor from the list of known actors.

Args:
actor_name (str): name of the actor to remove.
"""
Expand All @@ -141,10 +135,10 @@ def register_activity(
power_consumption_in_watt: float = None,
):
"""Registers an activity that can then be performed on the local actor.

Args:
name (str): Name of the activity
requires_line_of_sight_to (list): List of strings with names of actors which need to be visible for this activity.
requires_line_of_sight_to (list): List of strings with names of actors which
need to be visible for this activity.
power_consumption_in_watt (float, optional): Power consumption of performing
the activity (per second). Defaults to None.
"""
Expand All @@ -171,13 +165,11 @@ def perform_activity(
duration_in_s: float = 1.0,
):
"""Perform the activity and discharge battery accordingly

gomezzz marked this conversation as resolved.
Show resolved Hide resolved
Args:
name (str): Name of the activity
power_consumption_in_watt (float, optional): Power consumption of the
activity in seconds if not specified. Defaults to None.
duration_in_s (float, optional): Time to perform this activity. Defaults to 1.0.

Returns:
bool: Whether the activity was performed successfully.
"""
Expand Down Expand Up @@ -216,7 +208,6 @@ def perform_activity(

def set_central_body(self, planet: pk.planet):
"""Sets the central body of the simulation for the orbit simulation

Args:
planet (pk.planet): The central body as a pykep planet
"""
Expand All @@ -225,7 +216,6 @@ def set_central_body(self, planet: pk.planet):

def get_cfg(self) -> DotMap:
"""Returns the current cfg of the simulation

Returns:
DotMap: cfg
"""
Expand Down
2 changes: 1 addition & 1 deletion paseos/power/is_in_eclipse.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def is_in_eclipse(
Returns:
bool: True if actor is in eclipse
"""
logger.debug(f"Checking whether {actor} is in eclipse at {t}.")
logger.debug(f"Checking whether {actor} is in eclipse at {t.mjd2000/pk.SEC2DAY}.")
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please don't change this. I don't know if it is day at 1482579s (old code shows date and time)

Copy link
Collaborator

Choose a reason for hiding this comment

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

Please revert 🙏

Copy link
Collaborator

Choose a reason for hiding this comment

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

Still open

Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
logger.debug(f"Checking whether {actor} is in eclipse at {t.mjd2000/pk.SEC2DAY}.")
logger.debug(f"Checking whether {actor} is in eclipse at {t}.")


# Compute central body position in solar reference frame
r_central_body_heliocentric, _ = np.array(central_body.eph(t))
Expand Down
29 changes: 29 additions & 0 deletions paseos/tests/visualization_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
"""Tests to check visualization."""
import sys

sys.path.append("../..")
from paseos import ActorBuilder, SpacecraftActor
from paseos.visualization.space_animation import SpaceAnimation
from test_utils import get_default_instance
import pykep as pk


def test_animation():
sim, sat1, earth = get_default_instance()

sat2 = ActorBuilder.get_actor_scaffold(
"sat2", SpacecraftActor, [10000000, 0, 0], pk.epoch(0)
)
ActorBuilder.set_orbit(sat2, [0, 10000000, 0], [0, 0, 8000.0], pk.epoch(0), earth)
ActorBuilder.set_power_devices(sat2, 5000, 10000, 1)
sim.add_known_actor(sat2)

anim = SpaceAnimation(sim)

dt = 100
for t in range(10):
anim.animate(sim, dt)


if __name__ == "__main__":
test_animation()
29 changes: 29 additions & 0 deletions paseos/visualization/animation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
from abc import ABC, abstractmethod
from paseos.paseos import PASEOS


class Animation(ABC):
"""Abstract class for visualization."""

def __init__(self, sim: PASEOS) -> None:
self._local_actor = sim.local_actor
self._other_actors = sim.known_actors
self.objects = list()

def _sec_to_ddhhmmss(self, time: float) -> str:
gomezzz marked this conversation as resolved.
Show resolved Hide resolved
"""Convert seconds to ddhhmmss format
Returns:
str: time in ddhhmmss.
"""
m, s = divmod(time, 60)
h, m = divmod(m, 60)
d, h = divmod(h, 24)
return f"T={d:.0f}d{h:.0f}h{m:.0f}m{s:.0f}s"

@abstractmethod
def _plot_actors(self) -> None:
pass

@abstractmethod
def _update(self, sim: PASEOS) -> None:
pass
Loading