-1

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 ??

Mar
  • 419
  • 1
  • 7
  • 19
  • you should provide more detail on how your data looks like, e.g. how the 'time' is denoted. Furthermore, your approach seems a bit convoluted: have you considered using pandas to read in your data? – Daan Jun 03 '17 at 18:10
  • timestamp,heure,lat,lon,impact,type 2007-01-01 00:00:00,13:58:43,33.837,-9.205,10.3,1 2007-01-02 00:00:00,00:07:28,34.5293,-10.2384,17.7,1 2007-01-02 00:00:00,23:01:03,35.0617,-1.435,-17.1,2 2007-01-03 00:00:00,01:14:29,36.5685,0.9043,36.8,1 2007-01-03 00:00:00,05:03:51,34.1919,-12.5061,-48.9,1 – Mar Jun 04 '17 at 10:58

1 Answers1

0

I just found the solution of my question, i did this to obtain the number of the years i have in the csv file ,i divided the calculated density into NByears and it's working perfectly.

DateMax = data.index.year.max()
DateMin = data.index.year.min()
NByears = (DateMax - DateMin)
Mar
  • 419
  • 1
  • 7
  • 19