ogn-python/README.md

176 wiersze
6.5 KiB
Markdown
Czysty Zwykły widok Historia

2015-11-15 07:56:36 +00:00
# ogn-python
2015-10-24 21:13:21 +00:00
2017-09-16 07:19:21 +00:00
[![Build Status](https://travis-ci.org/glidernet/ogn-python.svg?branch=master)](https://travis-ci.org/glidernet/ogn-python)
[![Coverage Status](https://img.shields.io/coveralls/glidernet/ogn-python.svg)](https://coveralls.io/r/glidernet/ogn-python)
2015-11-15 08:26:09 +00:00
2016-03-18 21:56:59 +00:00
A database backend for the [Open Glider Network](http://wiki.glidernet.org/).
The ogn-python module saves all received beacons into a database with [SQLAlchemy](http://www.sqlalchemy.org/).
It connects to the OGN aprs servers with [python-ogn-client](https://github.com/glidernet/python-ogn-client).
2019-01-06 19:37:20 +00:00
It requires [PostgreSQL](http://www.postgresql.org/) and [PostGIS](http://www.postgis.net/).
For best performance you should use [TimescaleDB](https://www.timescale.com), which is based on PostgreSQL.
2016-01-12 18:31:08 +00:00
[Examples](https://github.com/glidernet/ogn-python/wiki/Examples)
## Installation and Setup
2016-01-12 18:31:08 +00:00
1. Checkout the repository
2019-01-24 18:44:19 +00:00
```
git clone https://github.com/glidernet/ogn-python.git
```
2016-01-12 18:31:08 +00:00
2. Install python requirements
```
pip install -r requirements.txt
```
2015-11-15 08:26:09 +00:00
2019-01-24 18:44:19 +00:00
3. Install [PostgreSQL](http://www.postgresql.org/) with [PostGIS](http://www.postgis.net/) Extension.
Create a database (use "ogn" as default, otherwise you have to modify the configuration, see below)
2016-06-16 08:58:03 +00:00
2019-01-24 18:44:19 +00:00
4. Optional: Install redis for asynchronous tasks (like takeoff/landing-detection)
```
apt-get install redis-server
```
2015-11-15 08:26:09 +00:00
2016-06-16 08:58:03 +00:00
5. Create database
```
2019-03-06 20:11:46 +00:00
./flask database init
```
2015-11-15 08:26:09 +00:00
2019-01-06 19:37:20 +00:00
6. Optional: Prepare tables for TimescaleDB
```
2019-03-06 20:11:46 +00:00
./flask database init_timescaledb
2019-01-06 19:37:20 +00:00
```
2019-01-24 18:44:19 +00:00
7. Optional: Import world border dataset (needed if you want to know the country a receiver belongs to, etc.)
Get the [World Borders Dataset](http://thematicmapping.org/downloads/world_borders.php) and unpack it.
Then import it into your database (we use "ogn" as database name).
```
shp2pgsql -s 4326 TM_WORLD_BORDERS-0.3.shp world_borders_temp | psql -d ogn
psql -d ogn -c "INSERT INTO countries SELECT * FROM world_borders_temp;"
psql -d ogn -c "DROP TABLE world_borders_temp;"
```
2019-03-17 14:09:01 +00:00
8. Get world elevation data (needed for AGL calculation)
Sources: There are many sources for DEM data. It is important that the spatial reference system (SRID) is the same as the database which is 4326.
2019-03-18 07:37:19 +00:00
The [GMTED2010 Viewer](https://topotools.cr.usgs.gov/gmted_viewer/viewer.htm) provides data for the world with SRID 4326. Just download the data you need.
2019-03-17 14:09:01 +00:00
For Europe we can get the DEM as GeoTIFF files from the [European Environment Agency](https://land.copernicus.eu/imagery-in-situ/eu-dem/eu-dem-v1.1).
Because the SRID of these files is 3035 and we want 4326 we have to convert them (next step)
2019-03-18 07:37:19 +00:00
9. Optional: Convert the elevation data into correct SRID
2019-03-17 14:00:43 +00:00
2019-03-17 14:09:01 +00:00
We convert elevation from one SRID (here: 3035) to target SRID (4326):
2019-01-24 18:44:19 +00:00
```
gdalwarp -s_srs "EPSG:3035" -t_srs "EPSG:4326" source.tif target.tif
```
2019-03-17 14:09:01 +00:00
10. Import the GeoTIFF into the elevation table:
2019-01-24 18:44:19 +00:00
```
raster2pgsql -s 4326 -c -C -I -M -t 100x100 elevation_data.tif public.elevation | psql -d ogn
2019-01-24 18:44:19 +00:00
```
There is also a [Vagrant](https://www.vagrantup.com/) environment for the development of ogn-python.
You can create and start this virtual machine with `vagrant up` and login with `vagrant ssh`.
The code of ogn-python will be available in the shared folder `/vagrant`.
## Usage
2016-01-12 18:31:08 +00:00
### Running the aprs client and task server
To schedule tasks like takeoff/landing-detection (`logbook.compute`),
[Celery](http://www.celeryproject.org/) with [Redis](http://www.redis.io/) is used.
The following scripts run in the foreground and should be deamonized
2015-11-15 08:26:09 +00:00
(eg. use [supervisord](http://supervisord.org/)).
- Start the aprs client
2016-01-12 18:31:08 +00:00
```
2019-03-06 20:11:46 +00:00
./flask gateway run
2016-01-12 18:31:08 +00:00
```
- Start a task server (make sure redis is up and running)
2015-11-15 08:26:09 +00:00
2016-01-12 18:31:08 +00:00
```
2019-03-10 14:58:10 +00:00
celery -A ogn_python.collect worker -l info
2016-01-12 18:31:08 +00:00
```
- Start the task scheduler (make sure a task server is up and running)
```
2019-03-10 14:58:10 +00:00
celery -A ogn_python.collect beat -l info
```
To load a custom configuration, create a file `myconfig.py` (see [config/default.py](config/default.py))
and set the environment variable `OGN_CONFIG_MODULE` accordingly.
```
touch myconfig.py
export OGN_CONFIG_MODULE="myconfig"
2019-03-06 20:11:46 +00:00
./flask gateway run
```
2019-03-06 20:11:46 +00:00
### Flask - Command Line Interface
2015-11-15 08:26:09 +00:00
```
2019-03-06 20:11:46 +00:00
Usage: flask [OPTIONS] COMMAND [ARGS]...
A general utility script for Flask applications.
Provides commands from Flask, extensions, and the application. Loads the
application defined in the FLASK_APP environment variable, or from a
wsgi.py file. Setting the FLASK_ENV environment variable to 'development'
will enable debug mode.
$ export FLASK_APP=app.py
$ export FLASK_ENV=development
$ flask run
Options:
--version Show the flask version
--help Show this message and exit.
Commands:
database Database creation and handling.
db Perform database migrations.
export Export data in several file formats.
flights Create 2D flight paths from data.
gateway Connection to APRS servers.
logbook Handling of logbook data.
routes Show the routes for the app.
run Runs a development server.
shell Runs a shell in the app context.
stats Handling of statistical data.
2015-11-15 08:26:09 +00:00
```
2019-03-06 20:11:46 +00:00
Most commands are command groups, so if you execute this command you will get further (sub)commands.
2015-11-15 08:26:09 +00:00
2019-03-06 20:11:46 +00:00
### Available tasks (deprecated - needs rework)
2015-11-15 08:26:09 +00:00
2017-12-16 21:18:04 +00:00
- `ogn.collect.database.import_ddb` - Import registered devices from the DDB.
- `ogn.collect.database.import_file` - Import registered devices from a local file.
- `ogn.collect.database.update_country_code` - Update country code in receivers table if None.
- `ogn.collect.database.update_devices` - Add/update entries in devices table and update foreign keys in aircraft beacons.
- `ogn.collect.database.update_receivers` - Add/update_receivers entries in receiver table and update receivers foreign keys and distance in aircraft beacons and update foreign keys in receiver beacons.
- `ogn.collect.logbook.update_logbook` - Add/update logbook entries.
- `ogn.collect.logbook.update_max_altitude` - Add max altitudes in logbook when flight is complete (takeoff and landing).
- `ogn.collect.stats.update_device_stats` - Add/update entries in device stats table.
- `ogn.collect.stats.update_receiver_stats` - Add/update entries in receiver stats table.
- `ogn.collect.takeoff_landing.update_takeoff_landing` - Compute takeoffs and landings.
If the task server is up and running, tasks could be started manually.
```
python3
>>>from ogn.collect.database import import_ddb
>>>import_ddb.delay()
```
2015-11-15 08:26:09 +00:00
2016-01-12 18:31:08 +00:00
## License
Licensed under the [AGPLv3](LICENSE).