COVID-Geographical-analysis

Ujjayanta Bhaumik
2 min readApr 27, 2020

A geographical analysis of COVID-19 using Folium library

Coronavirus disease (COVID-19) is an infectious disease caused by a newly discovered coronavirus.

Heatmaps

A heat map showing the effect of the novel coronavirus is shown here.

The data used here is available at: https://github.com/jojo96/COVID-Geographical-analysis

# Import libraries
#Heat map of COVID Deaths on April 14,2020
import pandas as pd
import folium
import cv2 as cv
from matplotlib import pyplot as plt
from folium.plugins import HeatMap
data = (r'C:\Users\admin\Desktop\Computational Neuroscience\statistical-gis-boundaries-london\corona-virus-report\covid_19_clean_complete.csv')
data = pd.read_csv(data)
df = []
for i in range(data.shape[0]):
if data['Date'][i]=='3/14/20':
df.append(data.iloc[i])
df = pd.DataFrame(df)
df
# mark each station as a point
m = folium.Map(location=[24, -12], zoom_start=2)
#initialize map
#the initial map is shown here
#im1 = cv.imread(r'C:\Users\admin\Desktop\Computational Neuroscience\statistical-gis-boundaries-london\m2.png')#
#img2 = im1[:,:,::-1]
plt.figure(figsize=(20,40))
plt.imshow(m2)
plt.title('folium.Map(location=[24, -12], zoom_start=2)')
plt.show()
#create HeatMap
HeatMap(data=df[['Lat', 'Long', 'Deaths']], radius=8, max_zoom=13).add_to(m)
#the Heatmap is shown here
#im1 = cv.imread(r'C:\Users\admin\Desktop\Computational Neuroscience\statistical-gis-boundaries-london\m1.png')
#img2 = im1[:,:,::-1]
#plt.figure(figsize=(20,40))
plt.imshow(m1)
plt.title('folium.Map(location=[24, -12], zoom_start=2)')
plt.show()

Additional (Coverting HTML to JPEG)

#https://stackoverflow.com/questions/38568804/python-open-html-file-take-screenshot-crop-and-save-as-image from selenium import webdriver  driver = webdriver.Chrome(r"C:\Users\admin\Desktop\Computational Neuroscience\statistical-gis-boundaries-london/chromedriver.exe")#path to the html file(which is to be converted to jpeg or png) 
temp_name = r'C:\Users\admin\Desktop\Computational Neuroscience\statistical-gis-boundaries-london\my_map.html'
options = webdriver.ChromeOptions()
options.add_argument('headless')
#download chromedriver.exe from https://chromedriver.chromium.org/downloads; check if the version of chromedriver
#matches the chrome browser version or is at least close
driver = webdriver.Chrome(executable_path=r"C:\Users\admin\Desktop\Computational Neuroscience\statistical-gis-boundaries-london/chromedriver.exe", chrome_options=options)
driver.get(temp_name)#path where you want to save the file save_name = r'C:\Users\admin\Desktop\Computational Neuroscience\statistical-gis-boundaries-london\my_map.html\1' + '.png'driver.save_screenshot(r'C:\Users\admin\Desktop\Computational Neuroscience\statistical-gis-boundaries-london\1.png')# this block of code converts all the html files in a folder to jpegs
import os
import glob
ind = 10
for file in glob.glob(r"C:\Users\admin\Desktop\Computational Neuroscience\statistical-gis-boundaries-london\heatsc/*.html"):
#print(file)
driver.get(file)
save_name = r'C:\Users\admin\Desktop\Computational Neuroscience\statistical-gis-boundaries-london\heatsimc\\' +str(ind)+ '.png'
driver.save_screenshot(save_name)
ind += 1

Code can be found at https://github.com/jojo96/COVID-Geographical-analysis

--

--

Ujjayanta Bhaumik

MSc Computer Vision, Graphics and Imaging, University College London