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

Add a script to download TLEs and store them to a database #56

Merged
merged 28 commits into from
Feb 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
644023a
Remove "bin" from ignored files
pnuu Jan 29, 2020
a1a8759
Add pre-commit config
pnuu Jan 29, 2020
65c1b06
Add a script for downloading TLEs and storing them to sqlite database
pnuu Jan 29, 2020
f81f839
Fix pre-commit complaints
pnuu Jan 29, 2020
0a91206
Move Downloader and SQLiteTLE classes inside pyorbital package
pnuu Jan 29, 2020
8f4675f
Install fetch_tles.py, fix pre-commit complaints
pnuu Jan 29, 2020
2630e04
Fixing style errors.
stickler-ci Jan 29, 2020
f1258e1
Fix pre-commit error, add execute permission
pnuu Jan 29, 2020
9b45eee
Fix stickler complaints
pnuu Jan 29, 2020
8e2a591
Fix pre-commit complaints
pnuu Jan 29, 2020
af3d0bd
Fix docstring in Downloader.parse_tles()
pnuu Jan 29, 2020
fe2cddc
Add tests for Downloader class
pnuu Jan 29, 2020
f6bcebd
Test method fetching data from Space-Track
pnuu Jan 29, 2020
37da2bd
Merge branch 'feature-tle-download-db' of https://github.com/pnuu/pyo…
pnuu Jan 29, 2020
5e5020b
Fix adding a single filename where TLEs are read
pnuu Jan 29, 2020
16503db
Add a error log message if a file wasn't found
pnuu Jan 29, 2020
c0214c2
Add tests for Downloader.read_tle_files()
pnuu Jan 29, 2020
54dbe13
Add error handling when parsing TLE
pnuu Jan 29, 2020
120b03c
Add tests for Downloader.parse_tles()
pnuu Jan 29, 2020
ad03c7f
Remove unused value_exists() function
pnuu Jan 30, 2020
730bf31
Store update time in ISO string format
pnuu Jan 30, 2020
1b759bd
Add tests for tlefile.SQLiteTLE
pnuu Jan 30, 2020
964bd46
Re-wrap a long line
pnuu Jan 30, 2020
aa56a09
Add some documentation on TLE downloading and database
pnuu Jan 30, 2020
94575ec
Merge branch 'master' into feature-tle-download-db
pnuu Jan 30, 2020
e66e091
Remove Python 2.7 and 3.6 from Travis tests, add 3.7 and 3.8
pnuu Jan 30, 2020
dc7d575
Log the age of saved TLE data
pnuu Jan 30, 2020
9854128
Use the ISO time format from tlefile
pnuu Jan 30, 2020
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: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ dist
build
eggs
parts
bin
var
sdist
develop-eggs
Expand All @@ -39,4 +38,4 @@ nosetests.xml
.pydevproject

# rope
.ropeproject
.ropeproject
8 changes: 8 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
exclude: '^$'
fail_fast: false
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v2.2.3
hooks:
- id: flake8
additional_dependencies: [flake8-docstrings, flake8-debugger, flake8-bugbear]
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
language: python
python:
- '2.7'
- '3.6'
- '3.7'
- '3.8'
install:
- pip install dask[array] xarray
- pip install .
Expand Down
53 changes: 53 additions & 0 deletions bin/fetch_tles.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#!/usr/bin/env python

"""Script to download and store satellite TLE data."""

import sys
import logging
import logging.config

import yaml
from pyorbital.tlefile import Downloader, SQLiteTLE


def read_config(config_fname):
"""Read and parse config file."""
with open(config_fname, 'r') as fid:
config = yaml.load(fid, Loader=yaml.SafeLoader)
return config


def main():
"""Run TLE downloader."""
config = read_config(sys.argv[1])
if 'logging' in config:
logging.config.dictConfig(config['logging'])
else:
logging.basicConfig(level=logging.INFO)

downloader = Downloader(config)
db = SQLiteTLE(config['database']['path'], config['platforms'],
config['text_writer'])

logging.info("Start downloading TLEs")
for dl_ in config['downloaders']:
fetcher = getattr(downloader, dl_)
tles = fetcher()
if isinstance(tles, dict):
for source in tles:
for tle in tles[source]:
db.update_db(tle, source)
else:
source = 'file'
if "spacetrack" in dl_:
source = 'spacetrack'
for tle in tles:
db.update_db(tle, source)

db.write_tle_txt()
db.close()
logging.info("TLE downloading finished")


if __name__ == "__main__":
main()
15 changes: 15 additions & 0 deletions doc/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,21 @@ Pyorbital has a module for parsing NORAD TLE-files
99.043499999999995

If no path is given pyorbital tries to read the earth observation TLE-files from celestrak.com

TLE download and database
~~~~~~~~~~~~~~~~~~~~~~~~~

There is also a script, ``fetch_tles.py``, that can be used to collect
TLE data from several locations. Then currently supported locaions
are:

* generic network locations without login
* Space-Track (login credentials needed)
* local files

The data are saved in a SQLite3 database, and can be written to a file
after each run. To see configuration options, see the example
configuration in ``examples/tle.yaml``.

Computing satellite position
----------------------------
Expand Down
63 changes: 63 additions & 0 deletions examples/tle.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# Settings for the TLE dataset
database:
# Path to the dataset where all the data are saved.
path: /tmp/tle.db

text_writer:
# Directory to save to. Created if missing.
output_dir: "/tmp/%Y-%m"
# Pattern of the filenames to write.
filename_pattern: "tle_%Y%m%d_%H%M.txt"
# Write the platform name before the TLE data. Default: False.
write_name: False
# Write the text file after every invocation. Default: False
write_always: False

platforms:
# Satellite NORAD ID numbers and corresponding platform names
# Only IDs listed here will be added to database and saved to text files
25338: NOAA-15
28654: NOAA-18
33591: NOAA-19
37849: Suomi-NPP
43013: NOAA-20
29499: Metop-A
38771: Metop-B
43689: Metop-C

downloaders:
fetch_plain_tle:
eumetsat: # This is a name used for the source in logs
- http://oiswww.eumetsat.int/metopTLEs/html/data_out/latest_m02_tle.txt
- http://oiswww.eumetsat.int/metopTLEs/html/data_out/latest_m01_tle.txt
- http://oiswww.eumetsat.int/metopTLEs/html/data_out/latest_m03_tle.txt
- http://oiswww.eumetsat.int/metopTLEs/html/data_out/latest_n15_tle.txt
- http://oiswww.eumetsat.int/metopTLEs/html/data_out/latest_n18_tle.txt
- http://oiswww.eumetsat.int/metopTLEs/html/data_out/latest_n19_tle.txt
- http://oiswww.eumetsat.int/metopTLEs/html/data_out/latest_npp_tle.txt
celestrak: # This is a name used for the source in logs
- https://www.celestrak.com/NORAD/elements/weather.txt
fetch_spacetrack:
user: <username>
password: <password>
read_tle_files:
# For "kickstarting" the database, local files can also be added
paths:
- /path/to/a/file/tle.txt
- /path/to/many/files/tle*.txt

logging:
version: 1
formatters:
fmt:
format: '[%(asctime)s %(levelname)-8s %(name)s] %(message)s'
handlers:
console:
class: logging.StreamHandler
level: DEBUG
formatter: fmt
# stream: ext://sys.stdout
root:
level: DEBUG
propagate: false
handlers: [console]
Loading