smo_ea_hydrology 0.2.0 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +28 -0
- data/LICENSE +21 -0
- data/README.md +168 -0
- data/lib/smo_ea_hydrology/version.rb +1 -1
- metadata +7 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 353263bcd7551f25829f397ae50eac76a4fc384b3e09798a45036dbb9aa7b524
|
|
4
|
+
data.tar.gz: 33b5fe42bc2b23698c94a9f75c5486bad6e2298e6ab7a21a6dd997fac421fbab
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 5e60f58e1d33e515586a4a314d622c9a7df2392cbf93157052760783f84ec55b5e9b5954ded8b701910a7e1ad1e44ee525569cce558e5e5c953531eac2de0c76
|
|
7
|
+
data.tar.gz: d4b8b1ee8cdcf3ec6c0684bb6fdfb1b7db819e3a9fc69b426ef66c5bf402454e80d0abb7bb4e14e1c429d1ff87127f34cd7d5cfbedfdc3fc8886479ea2793c20
|
data/CHANGELOG.md
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
|
|
5
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
6
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
|
+
|
|
8
|
+
## [Unreleased]
|
|
9
|
+
|
|
10
|
+
## [0.2.0] - 2026-05-04
|
|
11
|
+
|
|
12
|
+
### Added
|
|
13
|
+
- `batch_download` for downloading readings from multiple stations to individual CSV files
|
|
14
|
+
- `rainfall_15min_inventory` and `rainfall_15min_inventory_to_csv` for full station inventory with coverage dates
|
|
15
|
+
- `find_stations` for searching stations by name or reference
|
|
16
|
+
- `rainfall_15min_stations_with_coverage` for stations with earliest/latest reading dates
|
|
17
|
+
|
|
18
|
+
## [0.1.0] - 2026-05-04
|
|
19
|
+
|
|
20
|
+
### Added
|
|
21
|
+
- `SmoEaHydrology::Client` for the Environment Agency Hydrology API
|
|
22
|
+
- `rainfall_15min_stations` — fetches all active 15-min rainfall stations
|
|
23
|
+
- `measures` — fetches 15-min rainfall measures for a station
|
|
24
|
+
- `readings` — fetches timestamped readings over a date range
|
|
25
|
+
- `readings_to_csv` — exports readings to CSV
|
|
26
|
+
- `Station`, `Measure`, `Reading`, and `InventoryEntry` data classes
|
|
27
|
+
- `ApiError` and `ParseError` error classes
|
|
28
|
+
- Test suite with comprehensive assertions
|
data/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Sebastian Madrid Ontiveros
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
# smo_ea_hydrology
|
|
2
|
+
|
|
3
|
+
Pure Ruby client for the [Environment Agency Hydrology API](https://environment.data.gov.uk/hydrology/doc/reference) — fetches active 15-minute rainfall stations, their coverage dates, and timestamped readings over any date range.
|
|
4
|
+
|
|
5
|
+
No external dependencies. Uses only Ruby stdlib (`net/http`, `uri`, `json`, `date`, `time`).
|
|
6
|
+
Compatible with **InfoWorks ICM 2027** embedded Ruby.
|
|
7
|
+
|
|
8
|
+
[](https://rubygems.org/gems/smo_ea_hydrology)
|
|
9
|
+
|
|
10
|
+
---
|
|
11
|
+
|
|
12
|
+
## Installation
|
|
13
|
+
|
|
14
|
+
```bash
|
|
15
|
+
gem install smo_ea_hydrology
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
Or add to your Gemfile:
|
|
19
|
+
|
|
20
|
+
```ruby
|
|
21
|
+
gem "smo_ea_hydrology"
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
---
|
|
25
|
+
|
|
26
|
+
## Quick start
|
|
27
|
+
|
|
28
|
+
```ruby
|
|
29
|
+
require "smo_ea_hydrology"
|
|
30
|
+
|
|
31
|
+
client = SmoEaHydrology::Client.new
|
|
32
|
+
|
|
33
|
+
# List active 15-min rainfall stations
|
|
34
|
+
stations = client.rainfall_15min_stations
|
|
35
|
+
puts stations.first.label # "Ulpha Duddo"
|
|
36
|
+
puts stations.first.station_reference # "589359"
|
|
37
|
+
puts stations.first.measure_label # "Rainfall 15min Total (mm)"
|
|
38
|
+
|
|
39
|
+
# Find a station by name or reference
|
|
40
|
+
matches = client.find_stations("Cosford")
|
|
41
|
+
station = matches.first
|
|
42
|
+
|
|
43
|
+
# Fetch readings for a date range
|
|
44
|
+
measure = client.measures(station.station_reference).first
|
|
45
|
+
readings = client.readings(measure.id, from: "2024-06-01", to: "2024-06-07")
|
|
46
|
+
puts readings.size # 672
|
|
47
|
+
puts readings.first.value # 0.0 mm
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
---
|
|
51
|
+
|
|
52
|
+
## Features
|
|
53
|
+
|
|
54
|
+
### Stations
|
|
55
|
+
|
|
56
|
+
```ruby
|
|
57
|
+
stations = client.rainfall_15min_stations
|
|
58
|
+
# Returns Array<Station> — no coverage dates (fast)
|
|
59
|
+
|
|
60
|
+
stations = client.rainfall_15min_stations_with_coverage
|
|
61
|
+
# Returns Array<Station> with coverage_from / coverage_to populated (slow — 2 API calls per station)
|
|
62
|
+
|
|
63
|
+
matches = client.find_stations("Dartmoor") # partial name match
|
|
64
|
+
matches = client.find_stations("589359") # exact reference match
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
Each `Station` has:
|
|
68
|
+
|
|
69
|
+
| Field | Description |
|
|
70
|
+
|---|---|
|
|
71
|
+
| `label` | Station name |
|
|
72
|
+
| `station_reference` | Unique reference e.g. `"589359"` |
|
|
73
|
+
| `lat` / `long` | WGS84 coordinates |
|
|
74
|
+
| `easting` / `northing` | OSGB36 coordinates |
|
|
75
|
+
| `date_opened` | e.g. `"1990-10-04"` |
|
|
76
|
+
| `measure_label` | `"Rainfall 15min Total (mm)"` |
|
|
77
|
+
| `measure_id` | Full URI of the 15-min measure |
|
|
78
|
+
| `coverage_from` | `Time` of earliest reading (nil unless fetched) |
|
|
79
|
+
| `coverage_to` | `Time` of latest reading (nil unless fetched) |
|
|
80
|
+
|
|
81
|
+
### Readings
|
|
82
|
+
|
|
83
|
+
```ruby
|
|
84
|
+
measures = client.measures("589359")
|
|
85
|
+
readings = client.readings(measures.first.id, from: "2024-06-01", to: "2024-06-07")
|
|
86
|
+
|
|
87
|
+
# Time-of-day filtering (times are UTC)
|
|
88
|
+
readings = client.readings(measures.first.id,
|
|
89
|
+
from: "2024-06-01 09:00",
|
|
90
|
+
to: "2024-06-01 17:00")
|
|
91
|
+
|
|
92
|
+
# Date / Time objects also accepted
|
|
93
|
+
readings = client.readings(measures.first.id,
|
|
94
|
+
from: Date.new(2024, 6, 1),
|
|
95
|
+
to: Time.utc(2024, 6, 7, 23, 45))
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
Each `Reading` has: `datetime` (Time), `value` (Float, mm), `quality` (String), `completeness` (String).
|
|
99
|
+
|
|
100
|
+
### Download to CSV
|
|
101
|
+
|
|
102
|
+
```ruby
|
|
103
|
+
# Single station
|
|
104
|
+
count = client.readings_to_csv(
|
|
105
|
+
station_reference: "589359",
|
|
106
|
+
from: "2024-06-01",
|
|
107
|
+
to: "2024-06-07",
|
|
108
|
+
path: "ulpha_june2024.csv"
|
|
109
|
+
)
|
|
110
|
+
|
|
111
|
+
# Batch — multiple stations to individual files
|
|
112
|
+
results = client.batch_download(
|
|
113
|
+
from: "2024-06-01",
|
|
114
|
+
to: "2024-06-07",
|
|
115
|
+
output_dir: "rainfall_data",
|
|
116
|
+
refs: %w[589359 1712 603111] # nil = all stations
|
|
117
|
+
)
|
|
118
|
+
|
|
119
|
+
# Full inventory with coverage dates
|
|
120
|
+
client.rainfall_15min_inventory_to_csv("inventory.csv")
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
### Inventory
|
|
124
|
+
|
|
125
|
+
```ruby
|
|
126
|
+
entries = client.rainfall_15min_inventory
|
|
127
|
+
# Array<InventoryEntry> — station + measure + coverage_from + coverage_to
|
|
128
|
+
# Makes 2 API calls per station — use rainfall_15min_inventory_to_csv for bulk export
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
---
|
|
132
|
+
|
|
133
|
+
## Examples
|
|
134
|
+
|
|
135
|
+
| Script | What it does |
|
|
136
|
+
|---|---|
|
|
137
|
+
| `examples/01_stations.rb` | List stations with coverage dates |
|
|
138
|
+
| `examples/02_readings.rb` | Fetch readings and show daily totals |
|
|
139
|
+
| `examples/03_inventory.rb` | Full inventory export to CSV |
|
|
140
|
+
| `examples/04_single_download.rb` | Download one station to CSV (edit variables at top) |
|
|
141
|
+
| `examples/05_batch_download.rb` | Batch download multiple stations (edit variables at top) |
|
|
142
|
+
|
|
143
|
+
Run any example:
|
|
144
|
+
|
|
145
|
+
```bash
|
|
146
|
+
ruby examples/01_stations.rb
|
|
147
|
+
ruby examples/04_single_download.rb # edit STATION / FROM / TO at the top first
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
---
|
|
151
|
+
|
|
152
|
+
## API coverage
|
|
153
|
+
|
|
154
|
+
| EA API endpoint | Method |
|
|
155
|
+
|---|---|
|
|
156
|
+
| `/id/stations?observedProperty=rainfall` | `rainfall_15min_stations` |
|
|
157
|
+
| `/id/measures?periodName=15min` | `measures(station_reference)` |
|
|
158
|
+
| `/id/measures/{id}/readings` | `readings(measure_id, from:, to:)` |
|
|
159
|
+
| Flood Monitoring `latestReading` | `rainfall_15min_stations_with_coverage` |
|
|
160
|
+
|
|
161
|
+
---
|
|
162
|
+
|
|
163
|
+
## License
|
|
164
|
+
|
|
165
|
+
MIT — see [LICENSE](LICENSE).
|
|
166
|
+
|
|
167
|
+
Built by [Sebastian Madrid Ontiveros](https://github.com/Sebasmadridmx).
|
|
168
|
+
If this gem saves you time, [buy me a coffee ☕](https://buymeacoffee.com/smadrid)
|
metadata
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: smo_ea_hydrology
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.2.
|
|
4
|
+
version: 0.2.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Sebastian Madrid Ontiveros
|
|
8
8
|
bindir: bin
|
|
9
9
|
cert_chain: []
|
|
10
|
-
date: 2026-
|
|
10
|
+
date: 2026-06-10 00:00:00.000000000 Z
|
|
11
11
|
dependencies: []
|
|
12
12
|
description: |
|
|
13
13
|
Developed by Sebastian Madrid Ontiveros. Pure Ruby client for the Environment Agency
|
|
@@ -18,11 +18,15 @@ description: |
|
|
|
18
18
|
Compatible with InfoWorks ICM 2027 embedded Ruby.
|
|
19
19
|
If this gem saves you time, consider buying Sebastian a coffee at
|
|
20
20
|
https://buymeacoffee.com/smadrid
|
|
21
|
-
email:
|
|
21
|
+
email:
|
|
22
|
+
- sebasmadrid20@hotmail.com
|
|
22
23
|
executables: []
|
|
23
24
|
extensions: []
|
|
24
25
|
extra_rdoc_files: []
|
|
25
26
|
files:
|
|
27
|
+
- CHANGELOG.md
|
|
28
|
+
- LICENSE
|
|
29
|
+
- README.md
|
|
26
30
|
- lib/smo_ea_hydrology.rb
|
|
27
31
|
- lib/smo_ea_hydrology/client.rb
|
|
28
32
|
- lib/smo_ea_hydrology/errors.rb
|