2017-06-02 8 views
-1

私は6年(日付、経度、緯度、値)のデータを含むcsvファイルを持っています私はhistogramm2dとcontourfをkmで使って密度マップをプロットしました。 6年ごとに1km当たりの密度をプロットしたので、ファイルに何年保存するかを知る基準を考慮し、6年ごとではなく1年あたりの密度をプロットする必要があります。 ので、ここで私はこれを達成するために使用していたコードです:km2当たりの密度マッププロット

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() 

任意のアイデア?

+0

などのデータの詳細を入力する必要があります。どのように '時間'が表示されます。さらに、あなたのアプローチはちょっと複雑です:パンダを使ってあなたのデータを読むことを考えましたか? – Daan

+0

タイムスタンプ、ヒーロー、緯度、経度、インパクト、タイプ 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 –

答えて

0

私はちょうど私の質問の解決策を見つけた、私はcsvファイルで持っている年の数を得るためにこれをやった、私は計算密度をNByearsに分割し、それは完全に働いている。

DateMax = data.index.year.max() 
DateMin = data.index.year.min() 
NByears = (DateMax - DateMin)