i have a csv file containing data of 6 years ( date, longitude, latitude,value ) i plotted the density map using histogramm2d and contourf per km ,i got a beautiful map, but i believe that i plotted the density per km per 6year, so i need to take into take consideration the criteria of knowing how many years do i have in the file and plot the density per km per year and not per 6 years. so here's the code i am using to achieve this :
with open('flash.csv') as f:
reader = csv.reader(f)
next(reader) # Ignore the header row.
lonMin, lonMax, dLon = -20.0, 5.0, 5
latMin, latMax, dLat = 18.0, 40.0, 5
for row in reader:
lat = float(row[2])
lon = float(row[3])
# filter lat,lons to (approximate) map view:
if lonMin <= lon <= lonMax and latMin <= lat <= latMax:
lats.append( lat )
lons.append( lon )
m = Basemap(llcrnrlon=min(lons), llcrnrlat=min(lats), urcrnrlon=max(lons), urcrnrlat=max(lats), projection='merc', resolution='f')
numcols = (max(lons)-min(lons)) * 100
numrows = (max(lats)-min(lats)) * 100
db = 1
lon_bins = np.linspace(min(lons)-db, max(lons)+db, numcols)
lat_bins = np.linspace(min(lats)-db, max(lats)+db, numrows)
h, xedges, yedges = (np.histogram2d(lats, lons,[lat_bins, lon_bins]))
xi, yi= m(*np.meshgrid(lon_bins, lat_bins))
#shape into continuous matrice
g = np.zeros(xi.shape)
g[:-1,:-1] = h
g[-1] = g[0] # copy the top row to the bottom
g[:,-1] = g[:,0] # copy the left column to the right
print g.shape,yi.shape,xi.shape
m.drawcoastlines()
m.drawstates()
g[g==0.0] = np.nan
cs = m.contourf(xi, yi, g)
cbar = plt.colorbar(cs, orientation='horizontal')
cbar.set_label('la densite des impacts foudre',size=18)
plt.gcf().set_size_inches(15,15)
plt.show()
Any ideas ??