use np.histogram2d, fixed list.append bug when using weight column
This commit is contained in:
parent
8c4767d58c
commit
ee322be870
|
@ -20,7 +20,7 @@ Produces a binned grid of two columns from an ASCIItable, i.e. a two-dimensional
|
|||
|
||||
parser.add_option('-d','--data',
|
||||
dest = 'data',
|
||||
type='string', nargs = 2, metavar = 'string string',
|
||||
type = 'string', nargs = 2, metavar = 'string string',
|
||||
help = 'column labels containing x and y ')
|
||||
parser.add_option('-w','--weight',
|
||||
dest = 'weight',
|
||||
|
@ -49,15 +49,15 @@ parser.add_option('-z','--zrange',
|
|||
parser.add_option('-i','--invert',
|
||||
dest = 'invert',
|
||||
action = 'store_true',
|
||||
help = 'invert probability density [%default]')
|
||||
help = 'invert probability density')
|
||||
parser.add_option('-r','--rownormalize',
|
||||
dest = 'normRow',
|
||||
action = 'store_true',
|
||||
help = 'normalize probability density in each row [%default]')
|
||||
help = 'normalize probability density in each row')
|
||||
parser.add_option('-c','--colnormalize',
|
||||
dest = 'normCol',
|
||||
action = 'store_true',
|
||||
help = 'normalize probability density in each column [%default]')
|
||||
help = 'normalize probability density in each column')
|
||||
|
||||
parser.set_defaults(bins = (10,10),
|
||||
type = ('linear','linear','linear'),
|
||||
|
@ -79,7 +79,8 @@ result = np.zeros((options.bins[0],options.bins[1],3),'f')
|
|||
|
||||
if options.data is None: parser.error('no data columns specified.')
|
||||
|
||||
labels = options.data
|
||||
labels = list(options.data)
|
||||
|
||||
|
||||
if options.weight is not None: labels += [options.weight] # prevent character splitting of single string value
|
||||
|
||||
|
@ -120,11 +121,10 @@ for name in filenames:
|
|||
|
||||
delta = minmax[:,1]-minmax[:,0]
|
||||
|
||||
for i in xrange(len(table.data)):
|
||||
x = int(options.bins[0]*(table.data[i,0]-minmax[0,0])/delta[0])
|
||||
y = int(options.bins[1]*(table.data[i,1]-minmax[1,0])/delta[1])
|
||||
if x >= 0 and x < options.bins[0] and y >= 0 and y < options.bins[1]:
|
||||
grid[x,y] += 1. if options.weight is None else table.data[i,2] # count (weighted) occurrences
|
||||
(grid,xedges,yedges) = np.histogram2d(table.data[:,0],table.data[:,1],
|
||||
bins=options.bins,
|
||||
range=minmax,
|
||||
weights=None if options.weight is None else table.data[:,2])
|
||||
|
||||
if options.normCol:
|
||||
for x in xrange(options.bins[0]):
|
||||
|
|
Loading…
Reference in New Issue