1
|
|
|
#!/usr/bin/env python3 |
2
|
|
|
|
3
|
|
|
import sys |
4
|
|
|
import os |
5
|
|
|
|
6
|
|
|
import numpy |
7
|
|
|
|
8
|
|
|
sys.path.append('../nsmaps') |
9
|
|
|
|
10
|
|
|
import nsmaps |
11
|
|
|
from nsmaps.logger import logger |
12
|
|
|
|
13
|
|
|
|
14
|
|
|
DATA_DIR = './website/nsmaps-data' |
15
|
|
|
|
16
|
|
|
|
17
|
|
|
def test(): |
18
|
|
|
stations = nsmaps.station.Stations(DATA_DIR) |
19
|
|
|
|
20
|
|
|
departure_station_name = 'Utrecht Centraal' |
21
|
|
|
departure_station = stations.find_station(departure_station_name) |
22
|
|
|
assert os.path.exists(os.path.join(DATA_DIR, 'contours/')) |
23
|
|
|
|
24
|
|
|
# test_config = nsmaps.contourmap.ContourPlotConfig() |
25
|
|
|
test_config = nsmaps.contourmap.TestConfig() |
26
|
|
|
test_config.print_bounding_box() |
27
|
|
|
|
28
|
|
|
create_contours_for_station(departure_station, stations, test_config, overwrite_existing=True) |
29
|
|
|
|
30
|
|
|
|
31
|
|
|
def create_contours_for_station(departure_station, stations, config, overwrite_existing=False, use_saved_data=False): |
32
|
|
|
logger.info(departure_station) |
33
|
|
|
max_level = 180 |
34
|
|
|
filepaths = [] |
35
|
|
|
contourmap = nsmaps.contourmap.Contour(departure_station, stations, config) |
36
|
|
|
|
37
|
|
|
filepath_geojson = os.path.join(DATA_DIR, 'contours/' + departure_station.get_code() + '.geojson') |
38
|
|
|
if not overwrite_existing and os.path.exists(filepath_geojson): |
39
|
|
|
print('WARNING: skipping station ' + departure_station.get_code() + ', files already exist.') |
40
|
|
|
return |
41
|
|
|
filepaths.append(filepath_geojson) |
42
|
|
|
if use_saved_data: |
43
|
|
|
contourmap.load() |
44
|
|
|
else: |
45
|
|
|
contourmap.create_contour_data() |
46
|
|
|
contourmap.save() |
47
|
|
|
levels_minor = numpy.linspace(0, max_level, num=37) |
48
|
|
|
contourmap.create_geojson(filepath_geojson, stroke_width=4, levels=levels_minor, overwrite=overwrite_existing) |
49
|
|
|
|
50
|
|
|
|
51
|
|
|
def create_all(): |
52
|
|
|
stations = nsmaps.station.Stations(DATA_DIR) |
53
|
|
|
|
54
|
|
|
# config = nsmaps.contourmap.TestConfig() |
55
|
|
|
config = nsmaps.contourmap.ContourPlotConfig() |
56
|
|
|
|
57
|
|
|
for departure_station in stations: |
58
|
|
|
if departure_station.has_travel_time_data(): |
59
|
|
|
# if departure_station.get_type() == 'megastation': |
60
|
|
|
create_contours_for_station(departure_station, stations, config, overwrite_existing=False, use_saved_data=False) |
61
|
|
|
|
62
|
|
|
|
63
|
|
|
if __name__ == "__main__": |
64
|
|
|
# test() |
65
|
|
|
create_all() |