from mpl_toolkits.basemap import Basemap import matplotlib.pyplot as plt import matplotlib.pylab as pylab import numpy as np import string import matplotlib.cm as cm import csv from datetime import datetime as dt #2014-11-13 06:18:09 tf="%Y-%m-%d %H:%M:%S" startTime=dt.strptime("2015-02-05 06:00:00", tf) endTime=dt.strptime("2015-02-21 22:00:00", tf) twogx=[] #longitudes twogy=[] #latitudes threegx=[] #longitudes threegy=[] #latitudes fourgx=[] #longitudes fourgy=[] #latitudes nagx=[] #longitudes nagy=[] #latitudes d1x=[] d1y=[] d2x=[] d2y=[] cy=[] cx=[] cities=[] errorlist=[] maxlon=-180.0 minlon=180.0 maxlat=-85.0 minlat=85.0 fi=open(r'data/.log','r') csvlog=csv.DictReader(fi, delimiter=',') for row in csvlog: try: timestamp=dt.strptime(row["system_time"],tf) if timestamp > startTime and timestamp < endTime: try: stype=row["mobile1_service_type"] row_x=float(row["gnss1_longitude"]) row_y=float(row["gnss1_latidude"]) provider=row["mobile1_network"] if row_x == 0.0 or row_y == 0.0: raise NameError('NoGPsFix') if stype=="EDGE": twogx.append(row_x) twogy.append(row_y) elif stype=="HSPA+" or stype=="HSDPA" or stype=="UMTS": threegx.append(row_x) threegy.append(row_y) elif stype=="LTE": fourgx.append(row_x) fourgy.append(row_y) else: nagx.append(row_x) nagy.append(row_y) if provider=="Vodafone.de": d2x.append(row_x) d2y.append(row_y) elif provider=="Telekom.de": d1x.append(row_x) d1y.append(row_y) if row_x > maxlon : maxlon=row_x if row_x < minlon : minlon=row_x if row_y > maxlat : maxlat=row_y if row_y < minlat : minlat=row_y except: errorlist.append(row["system_time"]) except: errorlist.append(row["system_time"]) fi.close() fi=open(r'data/cities.csv','r') citycsv=csv.DictReader(fi, delimiter=',') for row in citycsv: try: name=row["city"] row_x=float(row["lon"]) row_y=float(row["lat"]) cy.append(row_y) cx.append(row_x) cities.append(name) except: print "Error Cities" fi.close middlelat=maxlat-minlat middlelon=maxlon-minlon ma=middlelat mo=middlelon print "lon" print maxlon print minlon print "lat" print maxlat print minlat print min(threegx) print max(threegy) print mo print ma print middlelat print middlelon m= Basemap(llcrnrlon=(minlon-(mo*0.1)),llcrnrlat=(minlat-(ma*0.1)),urcrnrlon=(maxlon+(mo*0.1)),urcrnrlat=(maxlat+(ma*0.1)),lat_ts=20, resolution='h',projection='merc',lon_0=-7.95,lat_0=48.48,epsg=3857) m.drawmapboundary(fill_color='white') # fill to edge #m.drawmapscale(lon=(minlon+(middlelon*0.05)), lat=(minlat+(middlelat*0.05)),length=100,lat0=middlelat,lon0=middlelon,barstyle="fancy" ) print("getting wms image") m.wmsimage("http://irs.gis-lab.info/?layers=osm&",layers=["osm"],xpixels=3200,format="png" ) print("received wma image") twogx1,twogy1=m(twogx,twogy) threegx1,threegy1=m(threegx,threegy) fourgx1,fourgy1=m(fourgx,fourgy) nagx1,nagy1=m(nagx,nagy) d1x1,d1y1=m(d1x,d1y) d2x1,d2y1=m(d2x,d2y) cx1,cy1=m(cx,cy) #m.scatter(d1x1,d1y1,s=20,c='m',marker="D", alpha=1, edgecolors='none',label="Telekom.de ") #m.scatter(d2x1,d2y1,s=20,c='r',marker="D", alpha=1, edgecolors='none',label="Vodafone.de") m.scatter(nagx1,nagy1,s=20,c='r',marker="D", alpha=0.5, edgecolors='none' ,label="No Signal") m.scatter(twogx1,twogy1,s=20,c='b',marker="D", alpha=1, edgecolors='none',label="2G GSM/EDGE") m.scatter(threegx1,threegy1,s=20,c='y',marker="D", alpha=1, edgecolors='none',label="3G UMTS/HSPA+" ) m.scatter(fourgx1,fourgy1,s=20,c='g',marker="D", alpha=1, edgecolors='none' ,label="4G LTE") # some cities m.scatter(cx1,cy1,s=80,c='w',marker="o", alpha=1, edgecolors='k' ) # print city name for city, xc, yc in zip(cities, cx1, cy1): #draw the city name in a yellow (shaded) box plt.text(xc+200, yc, city, bbox=dict(facecolor='white', alpha=1)) plt.legend() plt.title("NetModule test drive from " + startTime.strftime(tf) + " until " + endTime.strftime(tf) ) # might want to change this! plt.savefig(dt.now().strftime("%Y%m%d_%H%M%S.png"),dpi=200) plt.show()