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

Updated tutorial #6

Closed

Conversation

grantcurell
Copy link

I went looking for ways to improve on the SGP4 algorithm and stumbled across your paper. I'm only sitting on a bachelors in comp sci & engineering so it took me a bit to spin up on everything and get to a point where it made sense to me. I overhauled the gradient descent tutorial so that it will make more sense at a lower education level and make the project more accessible to us average people hahaha.

Feel free to kick it back to me if there's anything you don't like and I'll fix it.


  • Updated .gitignore for pycharm
  • Updated the gradient_based_optimization tutorial with my understanding of what is going on with an explanation at a level that an engineer with a bachelors in comp sci understands
  • Added/updated comments for the gradient_based_optimization tutorial
  • Removed the duplicate copy of the gradient_based_optimization notebook
  • Fixed a bug in the gradient_based_optimization code. It was trying to call tle load from kessler which is actually a local function
  • Shamelessly added my name to the bottom of that tutorial so that I have something to point to for the time spend with leadership. Feel free to delete it if my explanation is terrible :-p
  • Added comments to initl.py
  • Removed unused import from newton_method.py
  • Updated the README.md to reflect the website with the compiled docs

Signed-off-by: Grant Curell [email protected]

@Sceki
Copy link
Member

Sceki commented Mar 17, 2024

Hi @grantcurell, thanks a lot for the PR.

I am working on some more tutorials & cleaner API, which hopefully will clarify some of your comments/doubts (this is currently happening here: #7 ).

There will be several new tutorials that go through basic and more advanced functionalities of dSGP4, in particular:

  • What a TLE object is, and how to create TLE objects from TLE files
  • How to propagate TLE objects with dSGP4, both in single TLE and batch mode (in both cases, the TLE(s) can be propagated multiple times in parallel)
  • How to retrieve gradients w.r.t. to both time and TLE parameters
  • several advanced tutorials on the use of these functionalities for spaceflight mechanics problems

Due to the large amount of changes, I will first push that PR, and then, if you do not mind, ask you to revise this, based on what is still outstanding from that.

Cheers!

@Sceki
Copy link
Member

Sceki commented Mar 18, 2024

@grantcurell #7 has been merged.

Please, have a look, and let me know if some of the aspects you mentioned are solved.

As for the rest: can you please update this PR to reflect those changes? Perhaps it is easier to close this, and re-open a new one? As you prefer!
Also, please make sure the build test is passed!

Thanks again.

@grantcurell grantcurell force-pushed the update_gradient_descent_tutorial branch from 3517e2f to 2fbdd08 Compare March 18, 2024 14:50
@grantcurell
Copy link
Author

PR updated and tests run:

grant@storben:~/Documents/code/dSGP4/tests$ pytest
========================================================================================= test session starts ==========================================================================================
platform linux -- Python 3.10.12, pytest-7.2.2, pluggy-1.3.0
rootdir: /home/grant/Documents/code/dSGP4
plugins: anyio-3.7.1, xdist-3.2.1
collected 16 items                                                                                                                                                                                     

test_batched_sgp4.py .                                                                                                                                                                           [  6%]
test_differentiability.py ..                                                                                                                                                                                                                                                             [ 18%]
test_initl.py ..                                                                                                                                                                                                                                                                         [ 31%]
test_newton.py .                                                                                                                                                                                                                                                                         [ 37%]
test_sgp4.py ...                                                                                                                                                                                                                                                                         [ 56%]
test_sgp4init.py .                                                                                                                                                                                                                                                                       [ 62%]
test_tle.py .....                                                                                                                                                                                                                                                                        [ 93%]
test_utils.py .                                                                                                                                                                                                                                                                          [100%]

@grantcurell grantcurell force-pushed the update_gradient_descent_tutorial branch from 2fbdd08 to 8456f08 Compare March 18, 2024 15:17
@Sceki
Copy link
Member

Sceki commented Mar 18, 2024

Thanks!

I left a few comments.

Also, in case you want to run all the tests locally, you also need to build the docs if you want to mirror what happens in the CI (currently the docs are failing)

@grantcurell
Copy link
Author

I can't build locally because the code was written with dependencies on files I don't have.

TLDR: TLEs_catalog_tests.txt is missing. I can rewrite the code as well if you want, but I don't think this was ever working.

Traceback (most recent call last):
  File "/home/grant/Documents/code/dSGP4/venv/lib/python3.10/site-packages/jupyter_cache/executors/utils.py", line 58, in single_nb_execution
    executenb(
  File "/home/grant/Documents/code/dSGP4/venv/lib/python3.10/site-packages/nbclient/client.py", line 1314, in execute
    return NotebookClient(nb=nb, resources=resources, km=km, **kwargs).execute()
  File "/home/grant/Documents/code/dSGP4/venv/lib/python3.10/site-packages/jupyter_core/utils/__init__.py", line 165, in wrapped
    return loop.run_until_complete(inner)
  File "/usr/lib/python3.10/asyncio/base_events.py", line 649, in run_until_complete
    return future.result()
  File "/home/grant/Documents/code/dSGP4/venv/lib/python3.10/site-packages/nbclient/client.py", line 709, in async_execute
    await self.async_execute_cell(
  File "/home/grant/Documents/code/dSGP4/venv/lib/python3.10/site-packages/nbclient/client.py", line 1062, in async_execute_cell
    await self._check_raise_for_error(cell, cell_index, exec_reply)
  File "/home/grant/Documents/code/dSGP4/venv/lib/python3.10/site-packages/nbclient/client.py", line 918, in _check_raise_for_error
    raise CellExecutionError.from_cell_and_msg(cell, exec_reply_content)
nbclient.exceptions.CellExecutionError: An error occurred while executing the following cell:
------------------
import dsgp4

path="TLEs_catalog_tests.txt"
tles=dsgp4.tle.load(file_name=path)

# Retrieve the gravitational constants for the WGS-72 Earth model
whichconst=dsgp4.util.get_gravity_constants("wgs-72")

# Exclude the TLEs that re-enter or are invalid:
deep_space_counter=0
error_counter=0

# List to store filtered TLEs, excluding those that re-enter or are invalid
tles_filtered=[]
for idx, tle_satellite in enumerate(tles):
    
    try:
        # Initialize the SGP4 model for each satellite with the specific parameters
        # from its TLE, adjusting epoch to a Julian date relative to the model's base date
        dsgp4.sgp4init(whichconst=whichconst,
                        opsmode=tle_satellite._opsmode,
                        satn=tle_satellite.satellite_catalog_number,
                        epoch=(tle_satellite._jdsatepoch+tle_satellite._jdsatepochF)-2433281.5,
                        xbstar=tle_satellite._bstar,
                        xndot=tle_satellite._ndot,
                        xnddot=tle_satellite._nddot,
                        xecco=tle_satellite._ecco,
                        xargpo=tle_satellite._argpo,
                        xinclo=tle_satellite._inclo,
                        xmo=tle_satellite._mo,
                        xno_kozai=tle_satellite._no_kozai,
                        xnodeo=tle_satellite._nodeo,
                        satrec=tle_satellite)
        
        # If the satellite does not have any initialization errors, add it to the filtered list
        if tle_satellite._error==0:
            tles_filtered.append(tle_satellite)
        else:
            error_counter+=1
    except:
         # Increment the deep space counter for TLEs that fail initialization
        deep_space_counter+=1
        
# Extract the first TLE to show gradient-based optimization usage:
my_tle=tles[0]
------------------


�[0;31m---------------------------------------------------------------------------�[0m
�[0;31mFileNotFoundError�[0m                         Traceback (most recent call last)
Cell �[0;32mIn[1], line 4�[0m
�[1;32m      1�[0m �[38;5;28;01mimport�[39;00m �[38;5;21;01mdsgp4�[39;00m
�[1;32m      3�[0m path�[38;5;241m=�[39m�[38;5;124m"�[39m�[38;5;124mTLEs_catalog_tests.txt�[39m�[38;5;124m"�[39m
�[0;32m----> 4�[0m tles�[38;5;241m=�[39m�[43mdsgp4�[49m�[38;5;241;43m.�[39;49m�[43mtle�[49m�[38;5;241;43m.�[39;49m�[43mload�[49m�[43m(�[49m�[43mfile_name�[49m�[38;5;241;43m=�[39;49m�[43mpath�[49m�[43m)�[49m
�[1;32m      6�[0m �[38;5;66;03m# Retrieve the gravitational constants for the WGS-72 Earth model�[39;00m
�[1;32m      7�[0m whichconst�[38;5;241m=�[39mdsgp4�[38;5;241m.�[39mutil�[38;5;241m.�[39mget_gravity_constants(�[38;5;124m"�[39m�[38;5;124mwgs-72�[39m�[38;5;124m"�[39m)

File �[0;32m~/Documents/code/dSGP4/venv/lib/python3.10/site-packages/dsgp4/tle.py:298�[0m, in �[0;36mload�[0;34m(file_name)�[0m
�[1;32m    287�[0m �[38;5;28;01mdef�[39;00m �[38;5;21mload�[39m(file_name):
�[1;32m    288�[0m �[38;5;250m    �[39m�[38;5;124;03m"""�[39;00m
�[1;32m    289�[0m �[38;5;124;03m    This function takes a file name that contains TLE (either with names or without),�[39;00m
�[1;32m    290�[0m �[38;5;124;03m    and returns a list of TLE objects.�[39;00m
�[0;32m   (...)�[0m
�[1;32m    296�[0m �[38;5;124;03m        `list`: list of `dsgp4.tle.TLE` objects�[39;00m
�[1;32m    297�[0m �[38;5;124;03m    """�[39;00m
�[0;32m--> 298�[0m     �[38;5;28;01mwith�[39;00m �[38;5;28;43mopen�[39;49m�[43m(�[49m�[43mfile_name�[49m�[43m)�[49m �[38;5;28;01mas�[39;00m f:
�[1;32m    299�[0m         lines �[38;5;241m=�[39m util�[38;5;241m.�[39mget_non_empty_lines(f�[38;5;241m.�[39mread())
�[1;32m    301�[0m     i �[38;5;241m=�[39m �[38;5;241m0�[39m

�[0;31mFileNotFoundError�[0m: [Errno 2] No such file or directory: 'TLEs_catalog_tests.txt'

@Sceki
Copy link
Member

Sceki commented Mar 18, 2024

@grantcurell this is gone after #7 (see: https://github.com/esa/dSGP4/blob/master/doc/notebooks/gradient_based_optimization.ipynb). I guess you have not updated this file?

You should be able to build locally, but let me know if that is not the case :)

@grantcurell
Copy link
Author

@grantcurell this is gone after #7 (see: https://github.com/esa/dSGP4/blob/master/doc/notebooks/gradient_based_optimization.ipynb). I guess you have not updated this file?

You should be able to build locally, but let me know if that is not the case :)

My bad, I'll go back through it line by line

@Sceki
Copy link
Member

Sceki commented Mar 18, 2024

My bad, I'll go back through it line by line

hopefully it is not going to be too painful :)

@grantcurell grantcurell force-pushed the update_gradient_descent_tutorial branch 2 times, most recently from a749d0d to 662e808 Compare March 18, 2024 18:04
@grantcurell
Copy link
Author

My bad, I'll go back through it line by line

hopefully it is not going to be too painful :)

Na, wasn't too bad. Let me know if I need to clean up anything else.

I'm jazzed about the new tutorials - this is a cool project

@grantcurell
Copy link
Author

Looks like there is a failure across all the notebooks but it does build locally:

Sphinx

(venv) grant@storben:~/Documents/code/dSGP4/doc$ make html
Running Sphinx v7.2.6
loading pickled environment... done
myst v2.0.0: MdParserConfig(commonmark_only=False, gfm_only=False, enable_extensions={'deflist', 'colon_fence', 'amsmath', 'dollarmath', 'html_image'}, disable_syntax=[], all_links_external=False, url_schemes=('http', 'https', 'mailto', 'ftp'), ref_domains=None, fence_as_directive=set(), number_code_blocks=[], title_to_header=False, heading_anchors=0, heading_slug_func=None, html_meta={}, footnote_transition=True, words_per_minute=200, substitutions={}, linkify_fuzzy_links=True, dmath_allow_labels=True, dmath_allow_space=True, dmath_allow_digits=True, dmath_double_inline=False, update_mathjax=True, mathjax_classes='tex2jax_process|mathjax_process|math|output_area', enable_checkboxes=False, suppress_warnings=[], highlight_code_blocks=True)
myst-nb v1.0.0: NbParserConfig(custom_formats={}, metadata_key='mystnb', cell_metadata_key='mystnb', kernel_rgx_aliases={}, eval_name_regex='^[a-zA-Z_][a-zA-Z0-9_]*$', execution_mode='force', execution_cache_path='', execution_excludepatterns=['tle_propagation.ipynb'], execution_timeout=30, execution_in_temp=False, execution_allow_errors=False, execution_raise_on_error=False, execution_show_tb=False, merge_streams=False, render_plugin='default', remove_code_source=False, remove_code_outputs=False, code_prompt_show='Show code cell {type}', code_prompt_hide='Hide code cell {type}', number_source_lines=False, output_stderr='show', render_text_lexer='myst-ansi', render_error_lexer='ipythontb', render_image_options={}, render_figure_options={}, render_markdown_format='commonmark', output_folder='build', append_css=True, metadata_to_fm=False)
Using jupyter-cache at: /home/grant/Documents/code/dSGP4/doc/_build/.jupyter_cache
[autosummary] generating autosummary for: api.rst, capabilities.ipynb, credits.ipynb, index.md, install.rst, notebooks/covariance_propagation.ipynb, notebooks/covariance_transformation.ipynb, notebooks/gradient_based_optimization.ipynb, notebooks/sgp4_partial_derivatives.ipynb, notebooks/tle_object.ipynb, notebooks/tle_propagation.ipynb, tutorials.rst
building [mo]: targets for 0 po files that are out of date
writing output... 
building [html]: targets for 0 source files that are out of date
updating environment: 0 added, 0 changed, 1 removed
reading sources... 
looking for now-outdated files... none found
no targets are out of date.
build succeeded.

The HTML pages are in _build/html.

pytest

grant@storben:~/Documents/code/dSGP4/tests$ pytest
===================================================================================================================================== test session starts ======================================================================================================================================
platform linux -- Python 3.10.12, pytest-7.2.2, pluggy-1.3.0
rootdir: /home/grant/Documents/code/dSGP4
plugins: anyio-3.7.1, xdist-3.2.1
collected 16 items                                                                                                                                                                                                                                                                             

test_batched_sgp4.py .                                                                                                                                                                                                                                                                   [  6%]
test_differentiability.py ..                                                                                                                                                                                                                                                             [ 18%]
test_initl.py ..                                                                                                                                                                                                                                                                         [ 31%]
test_newton.py .                                                                                                                                                                                                                                                                         [ 37%]
test_sgp4.py ...                                                                                                                                                                                                                                                                         [ 56%]
test_sgp4init.py .                                                                                                                                                                                                                                                                       [ 62%]
test_tle.py .....                                                                                                                                                                                                                                                                        [ 93%]
test_utils.py .                                                                                                                                                                                                                                                                          [100%]

===================================================================================================================================== 16 passed in 22.13s ======================================================================================================================================

@grantcurell grantcurell force-pushed the update_gradient_descent_tutorial branch from 662e808 to fd7c474 Compare March 18, 2024 20:13
@Sceki
Copy link
Member

Sceki commented Mar 18, 2024

Thanks for the followup @grantcurell

It seems to be related to the .py file you pushed.. we could resolve it, but I think that file is not needed anyway (I would refrain to push things not strictly related to the project). I left a review above discussing this and a few other things, if that is okay, I would recommend addressing those first

@grantcurell
Copy link
Author

grantcurell commented Mar 18, 2024

Thanks for the followup @grantcurell

It seems to be related to the .py file you pushed.. we could resolve it, but I think that file is not needed anyway (I would refrain to push things not strictly related to the project). I left a review above discussing this and a few other things, if that is okay, I would recommend addressing those first

No problem - the python file just generates the graph visually demonstrating gradient descent with Newton's method. I can delete it.

This is my ignorance showing - where is the review with the requested changes?

@Sceki
Copy link
Member

Sceki commented Mar 18, 2024

I just tagged you there: let me know if you see it :)

(you might also be able to access the review from the top right part of the PR, under the +++ --- of the lines of code)

@grantcurell
Copy link
Author

grantcurell commented Mar 21, 2024

I just tagged you there: let me know if you see it :)

(you might also be able to access the review from the top right part of the PR, under the +++ --- of the lines of code)

Apologies - busy at work. I checked my notifications and I don't have a tag - the only mention I have is on this thread:

image

Can you link it? Are these inline code comments? (Like this)

image

I didn't see any and normally those show up in the PR thread but maybe there is something I'm missing?

Are you able to drop a hyperlink to it?

@Sceki
Copy link
Member

Sceki commented Mar 21, 2024

@grantcurell just scroll up in this PR, and you should see: "Sceki requested a review" and all my comments still "pending".

As for the hyperlink, maybe try this: https://github.com/esa/dSGP4/pull/6/files#diff-83f35df9a3fe0a2b91c93481a5af0169fd86ba7f4296ae84b9e7fa65ad1af9a2. Not sure it works.

Let me know how it goes!

@grantcurell
Copy link
Author

Apologies, on the road a lot and been busy. I'm familiar with what that should look like from other projects, but I don't see it here and it's not visible on my page. I also don't see any of the reviewer comments you normally get when someone leaves feedback on the commit itself. You're talking about this right? https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/reviewing-changes-in-pull-requests/reviewing-proposed-changes-in-a-pull-request

I've looked everywhere I can think to look, but I don't see any of the comments like I normally would. Let me know if I'm just off in outer space. (No pun intended)

@Sceki
Copy link
Member

Sceki commented Apr 21, 2024

@grantcurell Yes, I am talking about that. I also linked it: can you click and check if it works?
Otherwise, just scroll up and you should see that I started a review if you open it there are the comments under the code lines.. Maybe have a look on youtube/google on how this usually looks, if nothing works :)

@Sceki
Copy link
Member

Sceki commented Apr 21, 2024

(Here's an example of the comments I gave:)

Screenshot 2024-04-21 at 17 26 03

@grantcurell
Copy link
Author

That's why - your comments are in the pending state. You haven't actually posted them yet. See this stack overflow post: https://stackoverflow.com/a/45336490/4427375

doc/notebooks/code/gradient_descent_image_code.py Outdated Show resolved Hide resolved
doc/notebooks/images/gradient_descent.png Outdated Show resolved Hide resolved
@Sceki
Copy link
Member

Sceki commented Apr 29, 2024

That's why - your comments are in the pending state. You haven't actually posted them yet. See this stack overflow post: https://stackoverflow.com/a/45336490/4427375

you are right. I needed to press the complete review button! Done now, let me know!

@grantcurell grantcurell force-pushed the update_gradient_descent_tutorial branch 2 times, most recently from 79c6b2f to 8b4c56b Compare April 29, 2024 15:47
…g of what is going on with an explanation at a level that an engineer with a bachelors in comp sci understands

- Added/updated comments for the gradient_based_optimization tutorial
- Shamelessly added my name to the bottom of that tutorial so that I have something to point to for the time spend with leadership. Feel free to delete it if my explanation is terrible :-p
- Added comments to initl.py

Signed-off-by: Grant Curell [email protected]
@grantcurell grantcurell force-pushed the update_gradient_descent_tutorial branch from 8b4c56b to 428d0c1 Compare April 29, 2024 15:47
@grantcurell grantcurell requested a review from Sceki April 29, 2024 15:49
@grantcurell
Copy link
Author

All requested changes made!

Copy link
Member

@Sceki Sceki left a comment

Choose a reason for hiding this comment

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

Now that the PR matches the master I could have a look and I went through the tutorial, but there is some confusion on the notebook content: we are leveraging the gradient to apply Newton's method here, we are not doing gradient descent.

Of course, there are tons of application where you can use dsgp4 for gradient descent, but in this case it was not used.

In the paper, we discuss for instance a case where we apply gradient descent to learn the ML-dSGP4 corrections.

Anyway, I cannot accept this PR as it is, since it creates a bit of confusion and it is incorrect w.r.t. what it's actually done in the tutorial. I am sorry and thanks a lot for spending the time. I will be happy to accept other contributions in the future (in case they add relevant content/explanations!).

"\n",
"We can propagate the state from $t_0 \\rightarrow t_{obs}$, and obtain the state at $t_{obs}$. In general, we define the state (i.e., position and velocity), as:\n",
"We can use the SGP4 algorithm to propagate the state from $t_0 \\rightarrow t_{obs}$, and obtain the state at $t_{obs}$. We define the state (i.e., position and velocity) of an object in 3D space, as (this is described in more detail below):\n",
Copy link
Member

Choose a reason for hiding this comment

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

it is actually 6D (position and velocity), so please remove the 3D specification

Comment on lines +27 to +29
"- **$[ \\cdot ]$:** Indicates this is a vector\n",
"- **$x(t), y(t), z(t)$:** These are the positional coordinates of the object at time $t$. They represent the location of the object in a three-dimensional space\n",
"- **$\\dot{x}(t), \\dot{y}(t), \\dot{z}(t)$:** These terms represent the velocities of the object in the direction of each corresponding axis (X, Y, and Z). The dot above each symbol signifies these are first derivatives of the position coordinates. $\\dot{x}(t)$ is the velocity in the X direction, $\\dot{y}(t)$ is the velocity in the Y direction, and $\\dot{z}(t)$ is the velocity in the Z direction.\n",
Copy link
Member

Choose a reason for hiding this comment

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

we do not need these three explanations.. they are kind of trivial, and can be found in the paper anyway if someone wants to dig deeper

"- **$x(t), y(t), z(t)$:** These are the positional coordinates of the object at time $t$. They represent the location of the object in a three-dimensional space\n",
"- **$\\dot{x}(t), \\dot{y}(t), \\dot{z}(t)$:** These terms represent the velocities of the object in the direction of each corresponding axis (X, Y, and Z). The dot above each symbol signifies these are first derivatives of the position coordinates. $\\dot{x}(t)$ is the velocity in the X direction, $\\dot{y}(t)$ is the velocity in the Y direction, and $\\dot{z}(t)$ is the velocity in the Z direction.\n",
"\n",
"We then have: TLE$_0$, $\\vec{x}(t_0)$, and $\\vec{x}(t_{obs})$, but we want to find TLE$_{obs}$. Said with an example: Imagine we have some satellite with TLE$_0$. For TLE$_0$ we have all the orbital parameters required to define the satellite's orbit at $t_0$; inclination, right ascension of the ascending node, eccentricity, etc. Now we use TLE$_0$ as input to an orbital propagation model (SGP4) to compute the satellite's state vector at time 0 ($t_0$). This calculation gives us $\\vec{x}(t_0)$ which is the satellite's position and velocity in space. Now fast-forward a bit into the future to a new time ($t_{obs}$) where we again observe the satellite's actual position and velocity ($\\vec{x}(t_{obs})$). The problem is that our initial estimate $\\vec{x}(t_0) \\neq \\vec{x}(t_{obs})$. Our estimate was wrong. What we now want to do is to calculate TLE${_{obs}}$. TLE${_{obs}}$ is the TLE set that when applied at our new observation time **would** give us $\\vec{x}(t_{obs})$. Said another way, we want to be able to invert from state to an accurate TLE that correctly produces TLE$_{obs}$.\n",
Copy link
Member

Choose a reason for hiding this comment

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

I think there is a misunderstanding here. The point is only that: we have TLE_0, which would result in \vec{x}(t_{obs}) when propagated at t_{obs}. We want to find the TLE_{obs} that corresponds to that \vec{x}(t_{obs})

As you explain it, it seems that our objective is to match \vec{x}(t_0) and \vec{x}(t_{obs}), which is not the case

"\n",
"We then have: TLE$_0$, $\\vec{x}(t_0)$, and $\\vec{x}(t_{obs})$, but we want to find TLE$_{obs}$. Said with an example: Imagine we have some satellite with TLE$_0$. For TLE$_0$ we have all the orbital parameters required to define the satellite's orbit at $t_0$; inclination, right ascension of the ascending node, eccentricity, etc. Now we use TLE$_0$ as input to an orbital propagation model (SGP4) to compute the satellite's state vector at time 0 ($t_0$). This calculation gives us $\\vec{x}(t_0)$ which is the satellite's position and velocity in space. Now fast-forward a bit into the future to a new time ($t_{obs}$) where we again observe the satellite's actual position and velocity ($\\vec{x}(t_{obs})$). The problem is that our initial estimate $\\vec{x}(t_0) \\neq \\vec{x}(t_{obs})$. Our estimate was wrong. What we now want to do is to calculate TLE${_{obs}}$. TLE${_{obs}}$ is the TLE set that when applied at our new observation time **would** give us $\\vec{x}(t_{obs})$. Said another way, we want to be able to invert from state to an accurate TLE that correctly produces TLE$_{obs}$.\n",
"\n",
"This is where gradient descent comes into play. If you have no prior experience with gradient descent this is very likely going to be confusing. You can read more about it [here](https://www.khanacademy.org/math/multivariable-calculus/applications-of-multivariable-derivatives/optimizing-multivariable-functions/a/what-is-gradient-descent). The very high level description is that gradient descent is an optimization algorithm used to minimize a function by iteratively moving in the direction of the steepest decrease, as defined by the negative of the gradient. We use it in machine learning to iteratively refine model parameters, aiming to find the set of parameters that minimizes the cost function, typically representing the discrepancy between predicted and observed data. \n",
Copy link
Member

Choose a reason for hiding this comment

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

This is actually Newton's method, not gradient descent. It still uses the gradient, but it's formulated differently: https://en.wikipedia.org/wiki/Newton%27s_method (we are seeking F(x)=0 here)

"\n",
"This is where gradient descent comes into play. If you have no prior experience with gradient descent this is very likely going to be confusing. You can read more about it [here](https://www.khanacademy.org/math/multivariable-calculus/applications-of-multivariable-derivatives/optimizing-multivariable-functions/a/what-is-gradient-descent). The very high level description is that gradient descent is an optimization algorithm used to minimize a function by iteratively moving in the direction of the steepest decrease, as defined by the negative of the gradient. We use it in machine learning to iteratively refine model parameters, aiming to find the set of parameters that minimizes the cost function, typically representing the discrepancy between predicted and observed data. \n",
"\n",
"So how does gradient descent apply here? We can reformulate our problem, that is, how do we take $\\vec{x}(t_0)$ (that's the estimation made by SGP4) and get it so that it is as close as we can to $\\vec{x}(t_{obs})$ (the actual position of an object at time $t_{obs}$). This is where gradient descent comes in. We create a cost function:\n",
Copy link
Member

Choose a reason for hiding this comment

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

this is incorrect in our case, we are not updating x(t_0) to match x(t_obs), we are instead looking for the TLE at t_obs with parameters (called y) so that TLE_obs produces a state x(t_obs) that matches the one found from TLE_0. I will try to add a few sentences to make this clearer in the tutorial :)

Comment on lines +82 to +90
"- $no_{kozai}$: The mean motion of the satellite, adjusted for the Kozai correction. This represents the number of orbits the satellite completes in a day, adjusted for long-term perturbations in the orbit.\n",
"- $ecco$: The eccentricity of the orbit. This value defines the shape of the satellite's orbit, ranging from 0 (a perfect circle) to values close to 1 (highly elliptical orbits).\n",
"- $inclo$: The inclination of the orbit, measured in degrees. It indicates the angle between the satellite's orbital plane and the equatorial plane of the Earth.\n",
"- $mo$: The mean anomaly at the epoch. This is an angular measurement that specifies the satellite's position along its orbit at the specific time defined by the epoch of the TLE set.\n",
"- $argpo$: The argument of perigee. This angle indicates the orientation of the elliptical orbit in relation to the Earth's surface, specifying the point where the satellite passes closest to the Earth.\n",
"- $nodeo$: The right ascension of the ascending node (RAAN). This is the angle from a fixed reference direction, typically the vernal equinox, to the location where the satellite crosses the equatorial plane going northward.\n",
"- $n_{dot}$: The first derivative of the mean motion. It indicates how the satellite's mean motion changes over time, which is primarily due to atmospheric drag and gravitational perturbations.\n",
"- $n_{ddot}$: The second derivative of the mean motion. This value provides a refinement on the rate of change in the satellite's mean motion, offering a more precise prediction of its long-term orbital behavior.\n",
"- $B^*$: The ballistic coefficient. It relates to how the satellite responds to atmospheric drag, with a higher value indicating a greater effect of drag on the satellite's orbit.\n",
Copy link
Member

Choose a reason for hiding this comment

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

I already go over these in a separate tutorial: TLE Object

@grantcurell
Copy link
Author

No problem! I really appreciate your taking the time to write the feedback. I will read through it, read the paper again, go study some more, and try again!

This has been a very interesting free time project.

@Sceki Sceki closed this May 1, 2024
@Sceki
Copy link
Member

Sceki commented May 1, 2024

Thanks! Looking forward to it :) And closing this for now :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants