python - Referencing Data From a 2D Histogram -


i have following code reads data csv file , creates 2d histogram:

import numpy np import pandas pd import matplotlib mpl import matplotlib.pyplot plt  #read in csv data filename = 'complete_storms_all_us_only.csv' df = pd.read_csv(filename)  min_85 = df.min85 min_37 = df.min37 verification = df.one_min_15  #numbers x = min_85 y = min_37 h = verification  #estimate 2d histogram nbins = 33 h, xedges, yedges = np.histogram2d(x,y,bins=nbins)  #rotate , flip h h = np.rot90(h) h = np.flipud(h)  #mask zeros hmasked = np.ma.masked_where(h==0,h)  #calculate averages avgarr = np.zeros((nbins, nbins)) xbins = np.digitize(x, xedges[1:-1]) ybins = np.digitize(y, yedges[1:-1]) xb, yb, v in zip(xbins, ybins, verification):   avgarr[yb, xb] += v divisor = h.copy() divisor[divisor==0.0] = np.nan avgarr /= divisor binavg = np.around((avgarr * 100), decimals=1) binper = np.ma.array(binavg, mask=np.isnan(binavg))  #plot 2d histogram using pcolor fig1 = plt.figure() plt.pcolormesh(xedges,yedges,binper) plt.title('1 minute @ +/- 0.15 degrees') plt.xlabel('min 85 ghz pct (k)') plt.ylabel('min 37 ghz pct (k)') cbar = plt.colorbar() cbar.ax.set_ylabel('probability of cg lightning (%)')  plt.show() 

each pixel in histogram contains probability of lightning given range of temperatures @ 2 different frequencies on x , y axis (min_85 on x axis , min_37 on y axis). trying reference probability of lightning histogram based on wide range of temperatures vary on individual basis given storm. each storm has min_85 , min_37 corresponds probability 2d histogram. know there brute-force method can create ridiculous amount of if statements, 1 each pixel, tedious , inefficient when trying incorporate on multiple 2d histograms. there more efficient way reference probability histogram based on given min_85 , min_37? have separate file min_85 , min_37 data large amount of storms, need assign corresponding probability of lightning histogram each one.

it sounds need turn min_85 , min_37 values indices. work:

# min85data , min37data file dx = xedges[1] - xedges[0] dy = yedges[1] - yedges[0] min85inds = np.floor((min85data - yedges[1]) / dx).astype(np.int) min37inds = np.floor((min37data - yedges[0]) / dy).astype(np.int)  # pretend didn't flipping of h, or make copy of first hvals = h_orig[min85inds, min37ends] 

but make sure resulting indices valid before extract them.


Comments

Popular posts from this blog

javascript - how to protect a flash video from refresh? -

visual studio 2010 - Connect to informix database windows form application -

android - Associate same looper with different threads -