|
""" |
|
Cannabis Licenses | License Mao |
|
Copyright (c) 2022 Cannlytics |
|
|
|
Authors: |
|
Keegan Skeate <https://github.com/keeganskeate> |
|
Candace O'Sullivan-Sutherland <https://github.com/candy-o> |
|
Created: 9/22/2022 |
|
Updated: 10/8/2022 |
|
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 |
|
β Illinois |
|
β Maine |
|
β Massachusetts |
|
β Michigan |
|
β Montana |
|
β Nevada |
|
β New Jersey |
|
x New Mexico (FIXME) |
|
β Oregon |
|
β Rhode Island |
|
β Vermont |
|
β Washington |
|
|
|
""" |
|
|
|
from datetime import datetime |
|
import json |
|
import os |
|
|
|
|
|
import folium |
|
import pandas as pd |
|
|
|
|
|
|
|
DATA_DIR = '../' |
|
|
|
|
|
with open('../subsets.json', 'r') as f: |
|
SUBSETS = json.loads(f.read()) |
|
|
|
|
|
def aggregate_retailers( |
|
datafiles, |
|
index_col=0, |
|
lat='premise_latitude', |
|
long='premise_longitude', |
|
): |
|
"""Aggregate retailer license data files, |
|
keeping only those with latitude and longitude.""" |
|
data = [] |
|
for filename in datafiles: |
|
data.append(pd.read_csv(filename, index_col=index_col)) |
|
data = pd.concat(data) |
|
return data.loc[(~data[lat].isnull()) & (~data[long].isnull())] |
|
|
|
|
|
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 |
|
|
|
|
|
|
|
if __name__ == '__main__': |
|
|
|
|
|
subsets = list(SUBSETS.values()) |
|
datafiles = [DATA_DIR + x['data_url'] for x in subsets] |
|
retailers = aggregate_retailers(datafiles) |
|
|
|
|
|
map_file = '../analysis/figures/cannabis-licenses-map.html' |
|
m = create_retailer_map(retailers, filename=map_file) |
|
|
|
|
|
timestamp = datetime.now().isoformat()[:19].replace(':', '-') |
|
retailers.to_csv(f'{DATA_DIR}/data/all/licenses-{timestamp}.csv', index=False) |
|
|