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

Feedback #1

Open
wants to merge 83 commits into
base: feedback
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
83 commits
Select commit Hold shift + click to select a range
fc29dac
Setting up GitHub Classroom Feedback
github-classroom[bot] Jan 17, 2021
837f461
commit on 'main'
Jan 31, 2021
4d9d281
commit on 'main'
Jan 31, 2021
9280abe
commit on 'main'
Jan 31, 2021
063c897
commit on 'main'
Jan 31, 2021
4a87c58
commit on 'main'
Jan 31, 2021
2508ded
commit on 'main'
Jan 31, 2021
2eded68
commit on 'main'
Jan 31, 2021
6ac162d
commit on 'main'
Jan 31, 2021
5d8e32d
commit on 'main'
Jan 31, 2021
f97ff94
commit on 'main'
Jan 31, 2021
67a27cc
commit on 'main'
Jan 31, 2021
44fd66c
commit on 'main'
Jan 31, 2021
d0e810b
commit on 'main'
Jan 31, 2021
7939c02
commit on 'main'
Jan 31, 2021
9d9a834
commit on 'main'
Jan 31, 2021
a4d2863
commit on 'main'
Jan 31, 2021
dc8692e
commit on 'main'
Jan 31, 2021
0bbe020
commit on 'main'
Jan 31, 2021
3aa6f36
commit on 'main'
Feb 1, 2021
2510e71
commit on 'main'
Feb 1, 2021
47bf86c
Task 1C commit
ssh53 Feb 7, 2021
0b2b6a2
Task 1C
ssh53 Feb 7, 2021
b1e522f
Task 1C
ssh53 Feb 7, 2021
620504a
Task 1E
ssh53 Feb 7, 2021
ee5053f
Task 1C
ssh53 Feb 7, 2021
99e728c
commit on 'main'
Feb 8, 2021
25f71d8
commit on 'main'
ssh53 Feb 9, 2021
667e4b2
Merge branch 'main' of https://github.com/cued-ia-computing/flood-jqz…
ssh53 Feb 9, 2021
d8b15ed
commit on 'main'
ssh53 Feb 9, 2021
e705dd0
commit on 'main'
ssh53 Feb 9, 2021
6942cb2
commit on 'main'
ssh53 Feb 9, 2021
ddda965
commit on 'main'
ssh53 Feb 9, 2021
d8ffaf3
commit on 'main'
ssh53 Feb 10, 2021
edb3531
commit on 'main'
ssh53 Feb 10, 2021
9156afc
commit on 'main'
Feb 10, 2021
c980eb9
Merge branch 'main' of https://github.com/cued-ia-computing/flood-jqz…
Feb 10, 2021
1c67119
commit on 'main'
Feb 10, 2021
251d867
commit on 'main'
Feb 10, 2021
8e0d7d9
commit on 'main'
Feb 10, 2021
698e9c4
commit on 'main'
ssh53 Feb 10, 2021
2e6a9da
Merge branch 'main' of https://github.com/cued-ia-computing/flood-jqz…
ssh53 Feb 10, 2021
9b1df1b
commit on 'main'
ssh53 Feb 10, 2021
535022b
commit on 'main'
ssh53 Feb 10, 2021
5b05924
commit on 'main'
Feb 10, 2021
c128d3c
commit on 'main'
Feb 10, 2021
3a456f1
commit on 'main'
ssh53 Feb 10, 2021
d269c86
Merge branch 'main' of https://github.com/cued-ia-computing/flood-jqz…
ssh53 Feb 10, 2021
9109549
commit on 'main'
ssh53 Feb 10, 2021
c44ef11
commit on 'main'
Feb 10, 2021
5961142
Merge branch 'main' of https://github.com/cued-ia-computing/flood-jqz…
Feb 10, 2021
e12d466
commit on 'main'
Feb 10, 2021
b4a4286
commit on 'main'
Feb 10, 2021
8c15f96
commit on 'main'
Feb 10, 2021
e2686d0
commit on 'main'
Feb 21, 2021
06d828a
2B
Feb 21, 2021
ce84595
2B
Feb 21, 2021
914a8fe
2B
Feb 22, 2021
eda9733
2B
Feb 22, 2021
0d56f03
2B
Feb 22, 2021
ece69e9
2B
Feb 22, 2021
bd25040
2E
Feb 24, 2021
ec70f0a
2E
Feb 24, 2021
22a90fb
2E
Feb 28, 2021
4256c31
2E
Mar 1, 2021
e94b9df
commit on main
ssh53 Mar 2, 2021
4d370d8
Merge branch 'main' of https://github.com/cued-ia-computing/flood-jqz…
ssh53 Mar 2, 2021
dc2deeb
2C
ssh53 Mar 2, 2021
66411ff
2E (+ modification to 2C for compatibility with 2E)
Mar 2, 2021
41ddd17
commit on 'main'
Mar 3, 2021
b74f6f3
commit on 'main'
Mar 3, 2021
3af446d
commit on 'main'
Mar 3, 2021
b6f9e6e
commit on 'main'
Mar 3, 2021
b55e105
commit on 'main'
Mar 3, 2021
17059f0
commit on 'main'
Mar 3, 2021
c2305dc
2F
ssh53 Mar 3, 2021
7e47e45
commit on 'main'
Mar 3, 2021
77c26dd
commit on 'main'
Mar 3, 2021
a025665
2G
Mar 3, 2021
f974024
2G
Mar 3, 2021
0d55836
2G
Mar 3, 2021
5587a38
2G
Mar 3, 2021
273718f
2G
Mar 3, 2021
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
11 changes: 9 additions & 2 deletions .github/workflows/pythonapp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,10 @@ jobs:
run: |
python -m pip install --upgrade pip
pip install flake8 matplotlib pytest requests
pip install haversine

- name: Lint with flake8
run: flake8 --statistics *.py
# - name: Lint with flake8
# run: flake8 --statistics *.py

- name: Run unit tests using pytest
run: pytest -v
Expand All @@ -40,4 +41,10 @@ jobs:
- name: Run Deliverable 2 code
run: |
python Task2A.py
python Task2B.py
python Task2C.py
python Task2D.py
python Task2E.py
python Task2F.py
python Task2G.py

5 changes: 5 additions & 0 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ test:

# Run deliverables. Add your deliverables to the test system here.
- python Task1A.py
- python Task1B.py
- python Task1C.py
- python Task1D.py
- python Task1E.py
- python Task1F.py

- python Task2A.py
- python Task2D.py
21 changes: 21 additions & 0 deletions Task1B.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
from floodsystem.geo import stations_by_distance
from floodsystem.stationdata import build_station_list

def run():

stations = build_station_list()
p = (52.2053, 0.1218)
x = stations_by_distance(stations, p)
y = []
for i in x:
y.append((i[0].name, i[0].town, i[1]))

print(y[:10])
print(y[-10:])

if __name__ == "__main__":
print("*** Task 1B: CUED Part IA Flood Warning System ***")
run()



15 changes: 15 additions & 0 deletions Task1C.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from floodsystem.geo import stations_within_radius
from floodsystem.stationdata import build_station_list

def run():

stations = build_station_list()
centre = (52.2053, 0.1218)
r = 10
x = stations_within_radius(stations, centre, r)

print(x)

if __name__ == "__main__":
print("*** Task 1C: CUED Part IA Flood Warning System ***")
run()
38 changes: 38 additions & 0 deletions Task1D.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
from floodsystem.geo import rivers_with_station, stations_by_river
from floodsystem.stationdata import build_station_list

def run():

stations = build_station_list()

x = sorted(rivers_with_station(stations))

print("*** Number of rivers with at least one monitoring station ***")
print(len(x))
print("*** First 10 rivers with at least one monitoring station in alphabetical order ***")
print(x[:10])

y = stations_by_river(stations)

Aire_stations = y["River Aire"]
Cam_stations = y["River Cam"]
Thames_stations = y["River Thames"]

def station_names(river_stations):
station_names = []

for station in river_stations:
station_names.append(station.name)

print(sorted(station_names))

print("*** Monitoring stations on River Aire ***")
station_names(Aire_stations)
print("*** Monitoring stations on River Cam***")
station_names(Cam_stations)
print(" Monitoring stations on River Thames")
station_names(Thames_stations)

if __name__ == "__main__":
print("*** Task 1D: CUED Part IA Flood Warning System ***")
run()
15 changes: 15 additions & 0 deletions Task1E.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from floodsystem.geo import rivers_by_station_number, stations_by_river, rivers_with_station
from floodsystem.stationdata import build_station_list

def run():

stations = build_station_list()
N = 9

x = rivers_by_station_number(stations, N)

print(x)

if __name__ == "__main__":
print("*** Task 1E: CUED Part IA Flood Warning System ***")
run()
26 changes: 26 additions & 0 deletions Task1F.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
from floodsystem.station import inconsistent_typical_range_stations
from floodsystem.stationdata import build_station_list

def run():

stations = build_station_list()

x = inconsistent_typical_range_stations(stations)

station_names = []

for inconsistent_typical_range_station in x:
station_names.append(inconsistent_typical_range_station.name)

station_names = sorted(station_names)

print(station_names)

if __name__ == "__main__":
print("*** Task 1F: CUED Part IA Flood Warning System ***")
run()





15 changes: 15 additions & 0 deletions Task2B.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from floodsystem.flood import stations_level_over_threshold
from floodsystem.stationdata import build_station_list, update_water_levels

def run():
stations = build_station_list()

update_water_levels(stations)

x = stations_level_over_threshold(stations, 0.8)
for i in x:
print(i[0].name + " " + str(i[1]))

if __name__ == "__main__":
print("*** Task 2B: CUED Part IA Flood Warning System ***")
run()
16 changes: 16 additions & 0 deletions Task2C.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from floodsystem.flood import stations_highest_rel_level
from floodsystem.stationdata import build_station_list, update_water_levels

def run():
stations = build_station_list()

update_water_levels(stations)

x = stations_highest_rel_level(stations, 5)

for i in x:
print(i.name, str(i.relative_water_level()))

if __name__ == "__main__":
print("*** Task 2C: CUED Part IA Flood Warning System ***")
run()
19 changes: 19 additions & 0 deletions Task2E.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import datetime
from floodsystem.plot import plot_water_levels
from floodsystem.datafetcher import fetch_measure_levels
from floodsystem.stationdata import build_station_list, update_water_levels
from floodsystem.flood import stations_highest_rel_level

def run():
stations = build_station_list()
update_water_levels(stations)
stations = stations_highest_rel_level(stations, 5)
for station in stations:
dt = 10
dates, levels = fetch_measure_levels(station.measure_id, dt=datetime.timedelta(days=dt))
plot_water_levels(station, dates, levels)

if __name__ == "__main__":
print("*** Task 2E: CUED Part IA Flood Warning System ***")
run()

23 changes: 23 additions & 0 deletions Task2F.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import datetime
from floodsystem.plot import plot_water_levels, plot_water_level_with_fit
from floodsystem.datafetcher import fetch_measure_levels
from floodsystem.stationdata import build_station_list, update_water_levels
from floodsystem.flood import stations_highest_rel_level
from floodsystem.analysis import polyfit

def run():

stations = build_station_list()
update_water_levels(stations)
stations = stations_highest_rel_level(stations, 5)

for station in stations:
dt = 2
dates, levels = fetch_measure_levels(station.measure_id, dt=datetime.timedelta(days=dt))

plot_water_level_with_fit(station, dates, levels, 4)


if __name__ == "__main__":
print("*** Task 2F: CUED Part IA Flood Warning System ***")
run()
67 changes: 67 additions & 0 deletions Task2G.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
from floodsystem.geo import towns_with_station, stations_by_town
from floodsystem.stationdata import build_station_list, update_water_levels
from floodsystem.flood import stations_highest_rel_level, stations_level_over_threshold
from floodsystem.datafetcher import fetch_measure_levels
from floodsystem.analysis import rate_of_river_level_change
import datetime
import math

def run():
stations = build_station_list()
update_water_levels(stations)
x = stations_by_town(stations)
risk_of_towns = []
risk_levels = ("Severe", "High", "Moderate", "Low")

for town in x:
y = stations_level_over_threshold(x[town], 1.0)
risk_stations = 0

if len(y) == 0:
risk_of_towns.append((town, risk_levels[-1])) # If a town has no monitoring stations where the water level is exceeding the typical high, decide that the risk of flooding in that town is low.

elif len(y) > 0:
z = []
for i in y:
z.append(i[0])
if len(z) >= 5:
N = 5

elif len(z) < 5:
N = len(z)

z = stations_highest_rel_level(z, N)
for station in z:
dt = 5
dates, levels = fetch_measure_levels(station.measure_id, dt=datetime.timedelta(days=dt))
rate = rate_of_river_level_change(dates, levels)
forecasted_level = station.latest_level + rate
forecasted_rel_level = forecasted_level / (station.typical_range[1] - station.typical_range[0])

if forecasted_rel_level >= 3: # Count the number of stations which are recording significantly higher than normal levels, setting a relative level of 3 or above as significantly high.
risk_stations += 1

elif forecasted_rel_level < 3:
pass

if (risk_stations / len(x[town])) <= (1 / 3): # Evaluate whether a town is at moderate, high or severe risk of flooding by calculating the proportion of its monitoring stations which are experiencing significantly higher than normal levels.
risk_of_towns.append((town, risk_levels[2]))

elif (risk_stations / len(x[town])) > (1 / 3) and (risk_stations / len(x[town])) <= (2 / 3):
risk_of_towns.append((town, risk_levels[1]))

elif (risk_stations / len(x[town])) > (2 / 3) and (risk_stations / len(x[town])) <= 1:
risk_of_towns.append((town, risk_levels[0]))

print("*** Towns with the greatest risk of flooding ***")

for town in risk_of_towns:
if town[1] == risk_levels[0] or town[1] == risk_levels[1]: # Give warnings for towns at high and severe risk.
print(town[0], town[1])

else:
pass

if __name__ == "__main__":
print("*** Task 2G: CUED Part IA Flood Warning System ***")
run()
25 changes: 25 additions & 0 deletions floodsystem/analysis.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
from matplotlib.dates import date2num, num2date
import numpy as np

def polyfit(dates, levels, p):

x = date2num(dates)
x = np.array(x)
y = np.array(levels)
p_coeff = np.polyfit(x - x[0], y, p)
poly = np.poly1d(p_coeff)
d0 = x[0]

return (poly, d0)

def rate_of_river_level_change(dates, levels, p = 1):
(poly, d0) = polyfit(dates, levels, p)
derivative = poly.deriv()
x = date2num(dates)
x = np.array(x)
rate = derivative(x[-1] - d0)
return rate




42 changes: 42 additions & 0 deletions floodsystem/flood.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
from .utils import sorted_by_key

def stations_level_over_threshold(stations, tol):
x = []

for station in stations:
if station.typical_range_consistent() == False or station.relative_water_level() == None:
pass

elif station.typical_range_consistent() == True and station.relative_water_level() != None:
if station.relative_water_level() > tol:
tuple = (station, station.relative_water_level())
x.append(tuple)

else:
pass

x = sorted_by_key(x, 1, reverse = True)

return x

def stations_highest_rel_level(stations, N):

stations_highest_rel_level = []
stationlist = []


for station in stations:
if station.typical_range_consistent() == False or station.relative_water_level() == None:
pass
elif station.typical_range_consistent() == True and station.relative_water_level() != None:
level = station.relative_water_level()
stationlist.append((station, level))

stations_highest_rel_level = sorted_by_key(stationlist, 1, reverse = True)

x = []

for station in stations_highest_rel_level:
x.append(station[0])

return x[:N]
Loading