def makemap(dataloc): """ This function is not used in the web app. I need to move it to its own file. It is used to generate the initial map of rides per day. """ # Generate a sub grid of latitudes and longitudes latvec, longvec = loadutil.grid() nlat = len(latvec) nlong = len(longvec) # get the mask mask = loadutil.getmask(dataloc) #import matplotlib.pyplot as plt #extent = [longvec.min(), longvec.max(), latvec.min(), latvec.max()] #plt.imshow(mask, extent=extent, origin='lower') ##plt.scatter(biglong, biglat) #plt.show() # load the data loaddata = loadutil.load(dataloc) popemp = loaddata[0] mbta = loaddata[1] station = loaddata[2] zipscale = loaddata[3] stationscale = loaddata[4] subwayscale = loaddata[5] stationfeatures = loaddata[6] nrides = [] latlist = [] longlist = [] for i in range(nlat): ilat = latvec[i] for j in range(nlong): ilong = longvec[j] #print("we're actually doing something!") iride = getride(ilat, ilong, popemp, mbta, station, zipscale, stationscale, subwayscale, stationfeatures, dataloc) if iride > 10: print(i, j, ilat, ilong, iride) nrides.append(iride) latlist.append(ilat) longlist.append(ilong) nrides = np.array(nrides) nrides *= (1 - mask) nrides = list(nrides) ridedatadict = { 'nrides': nrides, 'latitude': latlist, 'longitude': longlist } ridedata = pd.DataFrame(ridedatadict) ridedata.to_csv(dataloc + 'nridesmap.csv')
def makemap(dataloc): """ This function is not used in the web app. I need to move it to its own file. It is used to generate the initial map of rides per day. """ # Generate a sub grid of latitudes and longitudes latvec, longvec = loadutil.grid() nlat = len(latvec) nlong = len(longvec) # get the mask mask = loadutil.getmask(dataloc) #import matplotlib.pyplot as plt #extent = [longvec.min(), longvec.max(), latvec.min(), latvec.max()] #plt.imshow(mask, extent=extent, origin='lower') ##plt.scatter(biglong, biglat) #plt.show() # load the data loaddata = loadutil.load(dataloc) popemp = loaddata[0] mbta = loaddata[1] station = loaddata[2] zipscale = loaddata[3] stationscale = loaddata[4] subwayscale = loaddata[5] stationfeatures = loaddata[6] nrides = [] latlist = [] longlist = [] for i in range(nlat): ilat = latvec[i] for j in range(nlong): ilong = longvec[j] #print("we're actually doing something!") iride = getride(ilat, ilong, popemp, mbta, station, zipscale, stationscale, subwayscale, stationfeatures, dataloc) if iride > 10: print(i, j, ilat, ilong, iride) nrides.append(iride) latlist.append(ilat) longlist.append(ilong) nrides = np.array(nrides) nrides *= (1 - mask) nrides = list(nrides) ridedatadict = {'nrides': nrides, 'latitude': latlist, 'longitude': longlist} ridedata = pd.DataFrame(ridedatadict) ridedata.to_csv(dataloc + 'nridesmap.csv')
def remakemap(ilat, ilong, dataloc): """ Remake the map for a subgrid of 10x10 cells, since after adding a single station the impact on the predicted daily rides should be localalized. """ # Generate a sub grid of latitudes and longitudes latvec, longvec = loadutil.grid() # Generate a sub grid of latitudes and longitudes sublatvec, sublongvec = loadutil.subgrid(ilat, ilong, nsub=10) # load the data loaddata = loadutil.load(dataloc) popemp = loaddata[0] mbta = loaddata[1] station = loaddata[2] zipscale = loaddata[3] stationscale = loaddata[4] subwayscale = loaddata[5] stationfeatures = loaddata[6] # read in ride map from previous iteration nrides = pd.read_csv(dataloc + 'nridesmap.csv') # monitor how long this recomputing the subgrid takes import time currenttime = time.time() ngrid = len(nrides) for i in range(ngrid): ilat = nrides['latitude'][i] ilong = nrides['longitude'][i] # skip this latitude if it isn't present in the subgrid if ilat < sublatvec.min(): continue if ilat > sublatvec.max(): continue # skip this longitude if it isn't present in the subgrid if ilong < sublongvec.min(): continue if ilong > sublongvec.max(): continue # compute predicted rides per day given the new station iride = getride(ilat, ilong, popemp, mbta, station, zipscale, stationscale, subwayscale, stationfeatures, dataloc) # store the result in the nrides dataframe nrides['nrides'][i] = iride # make sure the Charles river is still masked out mask = loadutil.getmask(dataloc) nrides['nrides'] *= (1 - mask) # how long did it take? should be 5-10 seconds newtime = time.time() runtime = newtime - currenttime print("Took %d seconds to re-process the map." % runtime) nrides.to_csv(dataloc + 'nridesmap.csv', index=False)