-
Notifications
You must be signed in to change notification settings - Fork 0
/
viz.py
54 lines (43 loc) · 1.66 KB
/
viz.py
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
from yaml import load, Loader
import logging
import json
import pandas as pd
import plotly.express as px
logging.basicConfig(format='%(levelname)s - %(message)s')
logging.getLogger().setLevel(logging.INFO)
with open('config.yaml', 'r') as f:
config = load(f, Loader=Loader)
logging.info("Reading config...")
file_name = config['file_name']
if not ".json" in file_name:
logging.error("The records file must be a json file. Please check that you have added the file extension to the file name in the config.yaml file.")
exit()
# Read the records
logging.info("Reading records... This may take a moment.")
try:
file = open(file=file_name, mode='r').read()
except FileNotFoundError:
logging.error(f"The file {file_name} does not exist. Please check the file name in the config.yaml file.")
exit()
# Parse the records
logging.info("Parsing json... This may take a moment.")
try:
records = json.loads(file)
except json.JSONDecodeError:
logging.error("The file is not a valid json file.")
exit()
logging.info("Generating map...")
# Extract the latitude and longitude from the records
lat_lon_records = []
for location_record in records["locations"]:
lat = location_record["latitudeE7"] / 10**7
lon = location_record["longitudeE7"] / 10**7
lat_lon_records.append((lat, lon))
# Create a dataframe from the records
df = pd.DataFrame(lat_lon_records, columns=["Latitude", "Longitude"])
# Create a map
fig = px.scatter_mapbox(df, lat="Latitude", lon="Longitude", zoom=10)
if config['heatmap'] == True:
fig = px.density_mapbox(df, lat="Latitude", lon="Longitude", radius=2, zoom=10)
fig.update_layout(mapbox_style="open-street-map")
fig.show()