Skip to content

Commit

Permalink
Bug fixes for converting array data to Data() object
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Marley committed Sep 17, 2018
1 parent 1d78e7e commit 66c27f2
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions python/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def __init__(self):

def data2list(data,weights=None,normed=False,binning=1):
"""Convert array of data into dictionary of information matching 'hist2list' """
data,bins = np.histogram(data,bins=binning,weights=weights,density=normed)
data,bins = np.histogram(data,bins=binning,weights=weights,normed=normed)

results = Data()
results.content = data
Expand All @@ -94,20 +94,20 @@ def data2list2D(data,weights=None,normed=False,binning=1):
x = data[0]
y = data[1]

data,bins_x,bins_y = np.histogram2d(x,y,bins=binning,density=normed,weights=weights)
data,bins_x,bins_y = np.histogram2d(x,y,bins=binning,normed=normed,weights=weights)


# create dummy binning
bins_x = midpoints(bins_x) # get midpoints of bins given the bin edges
bins_y = midpoints(bins_y)
xbins = binsx.repeat(len(bins_y))
ybins = np.tile(bins_y, (1,len(bins_x)) )[0]
mbins_x = midpoints(bins_x) # get midpoints of bins given the bin edges
mbins_y = midpoints(bins_y)
xbins = mbins_x.repeat(len(mbins_y))
ybins = np.tile(mbins_y, (1,len(mbins_x)) )[0]

results = Data()
results.content = data.flatten() # data is a ndarray (nxbins,nybins)
results.error = np.sqrt(data)
results.bins = {'x':np.array(bins_x),'y':np.array(bins_y)}
results.center = {'x':binnsx,'y':binnsy}
results.center = {'x':xbins,'y':ybins}
results.width = {'x':0.5*(bins_x[:-1]-bins_x[1:]),
'y':0.5*(bins_y[:-1]-bins_y[1:])}

Expand Down Expand Up @@ -319,4 +319,4 @@ def betterColors():

return {'linecolors':lc,'linestyles':ls}

## THE END
## THE END

0 comments on commit 66c27f2

Please sign in to comment.