Skip to content

Monitoring the tidal stretch of the Thames

Notifications You must be signed in to change notification settings

zeevox/thamestides

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Thames Tides

GitHub last commit Maintainability Codacy Badge

Introduction

  • The Port of London Authority maintains 12 tide gauges along the tidal stretch of the Thames and provides live readings, updated every minute and predicted tidal information.
  • ThamesTides.org.uk provides tide times and height predictions for locations between Chiswick and Richmond Lock, namely Putney, Chiswick, Strand-on-the-Green, Brentford.
  • The UK Hydrographic Office provides tide times and height predictions for locations along the Thames, namely Albert Bridge, Chelsea Bridge, Hammersmith Bridge and Kew Bridge (among others).
  • The Environment Agency provides Kingston flow gauge data, updated every 15 minutes.

Coding project outline

  • Scrape data and aggregate it using Python:
    • Fetch tidal gauge data every minute and save it into a SQL database
    • Fetch tide times and height predictions and save it into a SQL database
  • Serve the collected data through PHP on my web server:
    • Calculate Above Ordnance Datum land heights where necessary
    • Calculate current tide rise speed
    • Calculate whether the Thames Barrier is closed based on the difference between the readings on the Silvertown and Charlton PLA tide gauges
    • Output this information in JSON format
  • Add tidal information to my Home Assistant dashboard (it parses JSON)
  • [TBC] create a pretty HTML page that fetches the JSON from my PHP script using Javascript and neatly presents the information

Installation and usage

git clone https://github.com/ZeevoX/thamestides.git && cd thamestides

Python data collection server

Dependencies

python3 -m pip install pytz requests apscheduler beautifulsoup4

Usage

Quick start (Linux):

./thamestides

Command line options:

~/thamestides$ python3 server/main.py -h
usage: main.py [-h] [-l LOGLEVEL] [-o LOGFILE]

Monitor the tidal stretch of the River Thames

optional arguments:
  -h, --help            show this help message and exit
  -l LOGLEVEL, --log LOGLEVEL
                        Set the logging level {DEBUG,INFO,WARNING,ERROR,CRITICAL}
  -o LOGFILE, --output LOGFILE
                        Output to a log file

Starting the data collector as a daemon (Linux)

NB: supervisord required

# create a process configuration file, enable the daemon and start it
./daemon enable

# check whether the daemon is currently running
./daemon status

# open the daemon's log file (scrollable; uses `less`)
./daemon log

# self-explanatory
./daemon start
./daemon stop
./daemon restart

# stop the daemon and remove its configuration files
./daemon disable

PHP JSON API

This repository does not document how to set up a PHP web server. Make sure the thamestides directory is accessible through your web server of choice for this to work. I test this project on Apache/2.4.41 with PHP 7.4.3.

NB: Requires PHP >= 7.0

API reference

If you send bad JSON or request invalid data the server will attempt to respond with an appropriate response code and error message, but this is not guaranteed.

URL parameter Since Type Description
predictions 0.0.1 any if set, fetch predicted data for the requested stations
readings 0.0.1 any if set, fetch historical measurements for the requested stations
station 0.0.1 string name of tidal station for which to fetch data; equivalent to stations with one item; this parameter overrides stations if both station and stations are set
stations 0.0.1 string comma-delimited, spaceless string list of tidal stations for which to fetch data or all to get all available stations
last_n 0.0.1 int positive integer representing the maximum number of rows of data to output from the database
start 0.0.1 datetime optional parsable datetime string representing the start time of the period of data to fetch; to be used in conjunction with end; default = 24 hours ago
end 0.0.1 datetime optional parsable datetime string representing the end time of the period of data to fetch; to be used in conjunction with start; default = now
filter_non_null 0.0.1 any if set, remove NULL values from measurements (e.g. when data unavailable for that time period or gauge was offline)