-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplot_events.py
More file actions
38 lines (34 loc) · 1.37 KB
/
plot_events.py
File metadata and controls
38 lines (34 loc) · 1.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import matplotlib.pyplot as plt
import rasterio.plot
import geopandas as gpd
from sqlalchemy import create_engine
from datetime import date, timedelta
def daterange(start_date, end_date):
for n in range(int((end_date - start_date).days)):
yield start_date + timedelta(n)
start_date = date(2022, 2, 24)
end_date = date(2023, 12, 19)
i = 0
db_connection_url = "postgresql://postgres:****************@localhost:5432/postgres"
con = create_engine(db_connection_url)
for single_date in daterange(start_date, end_date):
i = i + 1
now_date = single_date.strftime("%d.%m.%Y")
print(now_date)
raster = rasterio.open("back2.tiff")
fig, ax = plt.subplots(figsize=(16, 9))
rasterio.plot.show(raster, ax=ax)
plt.xlim([2299806.881, 4770718.883])
plt.ylim([5504132.188, 6894020.189])
plt.axis('off')
ax.text(4350000, 6800000, now_date, fontsize=20, color='black')
sql = '''select date,
0.1 + 0.9/(1 + 0.1 * (TO_DATE(\'''' + now_date + '''\', 'DD.MM.YYYY') - date)) as alpha,
geom
from events_all
where date <= TO_DATE(\'''' + now_date + '''\', 'DD.MM.YYYY');'''
df = gpd.GeoDataFrame.from_postgis(sql, con)
df.plot(ax=ax, markersize=7, color='red', edgecolor='none', alpha = df['alpha'])
plt.savefig('out/events_' + str(i).zfill(3) + '.png', bbox_inches='tight', pad_inches=0, dpi=207.8)
plt.cla()
plt.close()