File size: 2,075 Bytes
6a105a7
124701c
c0464cb
6a105a7
 
 
124701c
6a105a7
c0464cb
6a105a7
 
 
 
124701c
 
c0464cb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6a105a7
 
 
 
 
 
 
1352c88
 
6a105a7
1352c88
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
c0464cb
 
 
 
 
 
1352c88
c0464cb
1352c88
c0464cb
 
 
 
 
 
1352c88
c0464cb
 
 
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
"""
Cannabis Licenses | License Mao
Copyright (c) 2022-2023 Cannlytics

Authors:
    Keegan Skeate <https://github.com/keeganskeate>
    Candace O'Sullivan-Sutherland <https://github.com/candy-o>
Created: 9/22/2022
Updated: 9/19/2023
License: <https://github.com/cannlytics/cannabis-data-science/blob/main/LICENSE>

Description: 

    Map the adult-use cannabis retailers permitted in the United States:

    βœ“ Alaska
    βœ“ Arizona
    βœ“ California
    βœ“ Colorado
    βœ“ Connecticut
    βœ“ Delaware
    βœ“ Illinois
    βœ“ Maine
    βœ“ Massachusetts
    βœ“ Michigan
    βœ“ Missouri
    βœ“ Montana
    βœ“ Nevada
    βœ“ New Jersey
    X New York (Under development)
    βœ“ New Mexico
    βœ“ Oregon
    βœ“ Rhode Island
    βœ“ Vermont
    X Virginia (Expected 2024)
    βœ“ Washington

"""
# External imports.
import folium
import pandas as pd


def create_retailer_map(
        df,
        color='crimson',
        filename=None,
        lat='premise_latitude',
        long='premise_longitude',
    ):
    """Create a map of licensed retailers."""
    m = folium.Map(
        location=[39.8283, -98.5795],
        zoom_start=3,
        control_scale=True,
    )
    for _, row in df.iterrows():
        folium.Circle(
            radius=5,
            location=[row[lat], row[long]],
            color=color,
        ).add_to(m)
    if filename:
        m.save(filename)
    return m


# === Test ===
if __name__ == '__main__':

    # Read all licenses.
    data = pd.read_csv('../data/all/licenses-all-latest.csv')
    data = data.loc[
        (~data['premise_latitude'].isnull()) &
        (~data['premise_longitude'].isnull())
    ]

    # Create a map of all licenses.
    map_file = '../analysis/figures/cannabis-licenses-map.html'
    m = create_retailer_map(data, filename=map_file)
    print('Saved map to', map_file)

    # FIXME: Create a PNG image of the map.
    # import io
    # from PIL import Image

    # img_data = m._to_png(30)
    # img = Image.open(io.BytesIO(img_data))
    # img.save('../analysis/figures/cannabis-licenses-map.png')