Git Product home page Git Product logo

tudatpy-examples's Introduction

Tudatpy examples

Welcome to the repository showcasing example applications set up with Tudatpy!

If you want to know more about Tudatpy, please visit the Tudat website.

Format

The examples are available as both Jupyter Notebooks and raw .py scripts.

Jupyter Notebook

To run these examples, first create the tudat-space conda environment to install tudatpy and its required depedencies, as described here.

Then, make sure that the tudat-space environment is activated:

conda activate tudat-space

Two packages then need to be added to this environment. First, the notebook package is needed to run the Jupyter notebooks:

conda install notebook

Then, if you wish to be able to run the Pygmo examples, this package also need to be installed:

conda install pygmo

The tudat-space environment has to be added to the Jupyter kernel, running the following:

python -m ipykernel install --user --name=tudat-space

Finally, run the following command to start the Jupyter notebooks:

jupyter notebook

Static code

To run the examples as regular Python files, you can clone this repository, open the examples on your favorite IDE, and install the tudat-space conda environment, as described here.

All of the examples, provided as .py files, can then be run and edited as you see fit.

Please note that these .py files were generated from the Jupyter Notebooks.

Content

The examples are organized in different categories.

Estimation

Examples related to state estimation.

  • basic_orbit_estimation: orbit estimation of a satellite in MEO

Propagation

Examples related to state propagation.

  • keplerian_satellite_orbit: simulation of a Keplerian orbit around Earth (two-body problem)
  • perturbed_satellite_orbit: simulation of a perturbed orbit around Earth
  • linear_sensitivity_analysis: extension of the perturbed_satellite_orbit example to propagate variational equations to perform a sensitivity analysis
  • reentry_trajectory: simulation of a reentry flight for the Space Transportation System (STS) and implementation of aerodynamic guidance
  • solar_system_propagation: numerical propagation of solar-system bodies, showing how a hierarchical, multi-body simulation can be set up
  • thrust_between_Earth_Moon: transfer trajectory between the Earth and the Moon that implements a simple thrust guidance scheme
  • two_satellite_phasing: shows the effects of differential drag for CubeSats in LEO

Pygmo

Examples showing how to optimize a problem modelled with Tudatpy via algorithms provided by Pygmo.

  • himmelblau_optimization: finds the minimum of an analytical function to show the basic usage of Pygmo
  • asteroid_orbit_optimization: simulates the orbit around the Itokawa asteroid and finds the initial state that ensures optimal coverage and close approaches

MyBinder

We set up a repository on MyBinder: this way, you can explore and run the examples online, without having to set up a development environment or installing the tudatpy conda environment. Click on the button below to launch the examples on mybinder:

Binder

Contribute

Contributions to this repository are always welcome. However, there are some guidelines that should be followed when creating a new example application. Here are some points to be kept in mind.

  1. Any modification or addition to this set of examples should be made in a personal fork of the current repository. No changes are to be done directly on a local clone of this repo.
  2. The example should be written directly on a Jupyter notebook (.ipynb file). Then, the following command can be run from the CLI to create a .py file with the same code as the notebook file: jupyter nbconvert --to python mynotebook.ipynb. Make sure to change mynotebook to the name of the notebook file.
  3. The markdown blocks are not optimally converted. Thus, once the .py file is created as described above, the script clean_py_notebooks.py is to be executed. This file reformats the markdown blocks in the .py files into a more readable look. Sometimes this cleanup is not perfect, so manually check the .py file to make sure everything is fine and correct anything that is not.
  4. At this point, the example is complete. You are ready to create a pull request from your personal fork to the current repository, and the admins will take it from there.

tudatpy-examples's People

Contributors

alopezrivera avatar dominicdirkx avatar filippooggionni avatar gaffarelj avatar jo11he avatar kgzenk avatar miguelavillez avatar sbcowan avatar transferorbit avatar tristandijkstra avatar yorchmcm avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

tudatpy-examples's Issues

Create Jupyter notebooks from existing examples

This issue is low-priority. It is more important to come up with new examples (see #3) and make the existing ones more on point. In addition, the .py file is preferred for example code.

However, Jupyter notebooks are more practical to describe examples. Using mybinder.org is a possibility.

EDIT: the new strategy is to convert .py scripts to Jupyter notebooks and have notebooks as main scripts. .py will still be provided for users by converting Jupyter notebooks with pandoc.org.

Tasks

Notebook conversion

  • Basic orbit estimation (a0cbeca)
  • Keplerian satellite orbit (8868847)
  • Linear sensitivity analysis (1f454f4)
  • Perturbed satellite orbit (98aed13)
  • Two satellites phasing (c1d5430)
  • Reentry trajectory (0356de4)
  • Thrust between Earth and Moon (5b4c206)
  • Solar system propagation (941d2d4)
  • Asteroid orbit optimisation (831c24d)
  • Himmelblau minimisation (f1b1370)

Automated conversion between .py and .ipynb

While there are ways to convert the .ipynb to .py and vice versa, both directions bring certain unwanted issues that should be addressed.

From .ipynb to .py
The go-to way is to use jupyter nbconvert --to script 'example.ipynb'. This results in a working example. This can be followed up with using the clean_py_notebooks.py to make them more usable, however there are still empty quotes left over. Furthermore, it converts all the files in hard coded directories.

Solution:

  1. Improve clean_py_notebook.py to get rid of empty """ strings.
  2. Create a script that combines the command above with the clean_py_notebooks.py file so that the conversion from .ipynb to .py is seamless. The script should allow you to both choose specific files to be converted, and in addition also convert whole example libraries.

From .py to .ipynb
This direction is of lesser importance because the .ipynb will remain the actively developed examples. There are two options:

  • The convert_py_to_ipynb.py file just creates one big code cell in a .ipynb file.
  • The p2j (installed with pip) package does allocate code and markdown cells properly, but introduces countless <br> instances and does not allocate headers in markdown cells consistently.

The two options are both sub-optimal, which could use more work in the future also by means of a script.

Add a rotational dynamics example

An example should be added that demonstrated how to propagate rotational dynamics. Ideally, the followings should be included:

  • Torque from the environment (Spherical Harmonics for instance).
  • Torque from some kind of RCS thruster/momentum wheel (from the vehicle itself).
  • Rotation from aerodynamics moment coefficient.
  • Initial angular velocity.
  • Incorporate thrust (and even TVC?) based on the vehicle orientation.

Move, rename and update tudatpy example applications

Steps needed

  1. Move example applications from here to this repository;
  2. Rename examples with more descriptive names;
  3. Update examples with new tudatpy module names/structure;
  4. Go through examples, add a better initial description and improve inline comments.
  5. Add this repository as a git submodule of tudatpy repo.

Note
@DominicDirkx has already updated examples 1, 2 and 10 (.py files) in tudatpy to the new setup, where examples 2 and 10 correspond to the two example applications on the website. Example 2 was renamed to "perturbed_satellite_orbit" (here on the website), example 10 was renamed to "linear_sensitivity_analysis" (here on the website).

Galileo Constellation Simulator

Hi at all,

I just wanted to suggest if the galileo constellation simulator could be converted as well, as it is a brilliant example to make pupils curious about the STEAM field. Thank you.

Best,
Stephan

Several example applications do not work

The example applications "Keplerian satellite orbit" and "Solar System Propagation" (and possibly more) return errors.

The errors I met in the "Keplerian satellite orbit" are the following:

  • In the script block [8] of the .ipynb file (or line 174 of the .py file):
    image

I bypassed this by modifying the input of the runge_kutta_4 function as follows:
integrator_settings = propagation_setup.integrator.runge_kutta_4(fixed_step_size, fixed_step_size)

  • In the script block [8] of the .ipynb file (or lines 177-185 of the .py file):
    image

I bypassed this by modifying the input of the translational function by omitting the simulation_start_epoch and integrator_settings input as follows:
propagator_settings = propagation_setup.propagator.translational(
central_bodies,
acceleration_models,
bodies_to_propagate,
initial_state,
termination_settings
)

  • In the script block [9] of the .ipynb file (or line 205 of the .py file):
    image

At this point I attempted to run the "Solar System Propagation" example application but it returned similar errors.

The "Keplerian satellite orbit" example application seems to work fine before the last commit (The commit with SHA fff7b20 is functional).

Update example introductory and license paragraph

The common introductory paragraph needs some beauty treatment. In particular the current year should be updated from 2022 to 2023, this sentence "This file is part of the Tudat." grammatically seems to be the reminiscent of two (?) once combined sentences, and the clickable link at the end does not work...

Importing notebooks

This issue tracks tudat-team/tudat-space#87. The issue relates to importing jupyter notebooks to reduce the overall size of certain examples. This is currently necessary for the asteroid orbit optimization example only. Both the .py and .ipynb files now import the necessary functions from the ipynb notebook.

Additions to PyGMO examples

It is not really clear from the current PyGMO examples when an aerodynamic coefficient interface or a thrust interface is set if it is included in the fitness function or in the general propagation file or in both. It gets a bit complicated to identify this from the current examples. Perhaps, it could be nice to provide few additions to current examples that shows where these attributes of the vehicle is included.

Update .py versions of examples

As a follow-up task from the developer meeting, @gaffarelj, could you please take care of the following tasks?

  • delete the old .py examples
  • provide new .py examples created via automatic conversion of Jupyter notebooks
  • add this information (i.e., .py examples are provided, but they are converted automatically, so we don't maintain them / assure that everything is fine) to the README

coupled_translational_rotational_dynamics error

When i run coupled_translational_rotational_dynamics.ipynb in JupyterLab, everything works fine until Cell In[5]:

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Cell In[11], line 12
     10 body_settings.get('Phobos').rotation_model_settings = environment_setup.rotation_model.synchronous('Mars', 'J2000', 'Phobos_body_fixed')
     11 body_settings.get('Phobos').gravity_field_settings = get_gravitational_field('Phobos_body_fixed')
---> 12 body_settings.get('Phobos').gravity_field_settings.scaled_mean_moment_of_inertia = 0.43
     14 # AND NOW WE CREATE THE BODIES OBJECT
     15 bodies = environment_setup.create_system_of_bodies(body_settings)

AttributeError: 'tudatpy.kernel.numerical_simulation.environment_setup.gravity_field.SphericalHarmonicsGravityFieldSe' object has no attribute 'scaled_mean_moment_of_inertia'

When I commented out the code that reported the error, Cell In[10] reported another error:

---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
Cell In[10], line 2
      1 # DYNAMICS SIMULATION
----> 2 simulator = numerical_simulation.create_dynamics_simulator(bodies, combined_propagator_settings)
      3 state_history = simulator.state_history
      4 dependent_variable_history = simulator.dependent_variable_history

RuntimeError: Error when creating rotational state derivative model, inverse inertia tensor of body Phoboscontains NaN. 

Why tudatpy.kernel.numerical_simulation.environment_setup.gravity_field.SphericalHarmonicsGravityFieldSe object has no attribute scaled_mean_moment_of_inertia here? Please help!

>>> dir(body_settings.get('Phobos').gravity_field_settings)

['__class__',
 '__delattr__',
 '__dir__',
 '__doc__',
 '__eq__',
 '__format__',
 '__ge__',
 '__getattribute__',
 '__gt__',
 '__hash__',
 '__init__',
 '__init_subclass__',
 '__le__',
 '__lt__',
 '__module__',
 '__ne__',
 '__new__',
 '__reduce__',
 '__reduce_ex__',
 '__repr__',
 '__setattr__',
 '__sizeof__',
 '__str__',
 '__subclasshook__',
 'associated_reference_frame',
 'create_time_dependent_field',
 'gravitational_parameter',
 'gravity_field_type',
 'normalized_cosine_coefficients',
 'normalized_sine_coefficients',
 'reference_radius']

Write new example applications

We can use this thread to come up with ideas.

From my side: e.g., simulation of two objects in LEO with high collision risks (conjunction messages). We can reproduce situations that actually happened (real collisions or avoided ones).

Integrator comparison example

A new example should be added that shows a plot of the error in position vs the number of function evaluations for different integrators, for a pure Keplerian orbit (perturbed orbit could be added later).

The error in position from the different integrators can be computed by taking the difference w.r.t. the analytical solution of a Kepler orbit.

This example would then showcase all the different integrators available.

Clarification for PyGMO examples

In general, the PyGMO examples are very well detailed especially the asteroid orbit optimization. However, the examples lacks the information that provides why the input arguments of the UDP class is defined as a lambda function arguments. Perhaps this is something required for PyGMO to be compatible but it could be nice if it is clarified why this is done and whether or not if it is mandatory, meaning if the code can still work if these attributes are not set as functions but set as variables instead. (I am assuming it won't work).

Collision example

A new example can be added that:

  • propagates multiple satellites (at least 3)
  • in an almost not perturbed orbit (only PM gravity or SH up to D/O2)
    • almost circular orbit (e<0.1)
    • almost polar orbit (i~88deg)
  • Use one of the latest integrators for maximum positional accuracy (<1 m)

In this example, two of the satellites should be at the same position at the same time (also called collision). This would showcase the accuracy of the integrator. This example can be linked to #9 when discussing accuracy).

The fact that 3 satellites would be propagated could also be used to showcase the dependent variable that saves the body that is the closest to another one (see this issue).

Two-stage rocket ascent needs fixing

The two-stage rocket ascent example returns an error now.

Problems:

  • There is a difference in behaviour between the .py and .ipynb file.
  • Compared to before the thrust refactoring, there is now an error for an exceeded minimum step size.

The question of what exactly needs to be shown with this example needs answering. Depending on that answer, the problem with the example is more or less problematic.

The problem occurs since the thrust refactoring in two_stage_rocket_ascent.py of commit 730e6ac.

I tested a few commits:

  • With commit 730e6ac (random old commit without thrust refactoring or integrator/propagator refactor), the stage separation occurs after 8.33 minutes with no errors. This is run with tudatpy=0.6.4 and tudat=2.10.6.
  • With commit 0ebc2e8 (commit where Miguel merged among others the updated two stage rocket ascent example for the .py file), the stage separation occurs after 7.75 minutes with a propagation error due to the minimum step size being exceeded. This commit has the updated thrust refactor, without the integrator/propagator refactor. This was run with tudatpy=0.7.1 and tudat=2.11.1.
  • With commit f8989ee (master), which includes the thrust refactor and the integrator/propagator refactor, the stage separation also occurs after 7.75 minutes with a propagation error due to the minimum step size being exceeded. This is also with tudatpy=0.7.1 and tudat=2.11.1.

This is all for the .py files. The .ipynb files were not updated in sync with these commits. Running the .ipynb file of commit f8989ee that I refactored results in an index error because there are too few time steps to create results (because of the premature termination). Here the stage separation already occurs after 3.91 minutes.

Make existing examples standard

Picking up from #1.

Existing examples to be updated following a more "standard" template:

  • keplerian_satellite_orbit.py
  • perturbed_satellite_orbit.py
  • linear_sensitivity_analysis.py
  • solar_system_propagation.py
  • satellite_separation_via_differential_drag.py
  • an estimation script , which is ready to be formatted in the same style as the example scripts listed above and even incorporated as a guided estimation example on tudat-space
  • a thrust (orbit raising) script, which is ready to be formatted in the same style as the example scripts listed above (thrust_between_Earth_Moon.py, previously named earth_moon_transfer.py,)
  • reentry_trajectory.py: a reentry script, which has an issue with the guidance scheme and is therefore not ready for publishing (but could still be styled)

Checks required for each example are:

  • it should run on the latest tudatpy
  • it should have an "intro" ("abstract")
  • it should be properly commented and follow PEP 8 (more or less)
  • (optional) it should be written in a Jupyter notebook, then turned into a .py script (automatically)

Workflow: creation of examples and uploading to tudatpy-examples

Right now, new examples have to be manually copied from the tudat-space repo to tudatpy-examples (or vice-versa), as well as manually converted from jupyter notebooks to py files (or the other way around).

Ideally, the examples should only be modified as jupyter files in tudat-space and automatically copied as jupyter and py files to tudatpy-examples.

If that automatic workflow is not possible (or at least while it isn't implemented), people working on examples should only modify them in the tudat-space repo. Only afterwards should they be copied to the tudatpy-examples repo. The goal is to have all the more recent versions of the examples in a single repo and in a single file type (to avoid having the two repos with a mix of new and old files), as the likelihood of someone forgetting to copy the examples to the repo they are not using relatively large.

Add additional estimation examples

To better make the estimation functionality visible, and identify shortcomings/improvements in the interfaces, additional example applications are to be created. Ideas for example applications will be provided and prioritized in this issue

Add rocket ascent example

A new example should be made about the ascent of a solid rocket on Mars.

This can showcase a basic model for thrust (off when no more propellant), of translational + mass propagation, and of the use of selected dependent variables, including a custom one.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.