added option for non-uniform weights

This commit is contained in:
Philip Eisenlohr 2016-03-27 17:54:49 -04:00
parent 7c72ede29d
commit fcddf9345e
1 changed files with 16 additions and 8 deletions

View File

@ -22,6 +22,10 @@ parser.add_option('-d','--data',
dest = 'data', dest = 'data',
type = 'string', metavar = 'string', type = 'string', metavar = 'string',
help = 'column heading for data') help = 'column heading for data')
parser.add_option('-w','--weights',
dest = 'weights',
type = 'string', metavar = 'string',
help = 'column heading for weights')
parser.add_option('--range', parser.add_option('--range',
dest = 'range', dest = 'range',
type = 'float', nargs = 2, metavar = 'float float', type = 'float', nargs = 2, metavar = 'float float',
@ -34,10 +38,11 @@ parser.add_option('-l', '--logarithmic',
dest = 'log', dest = 'log',
action = 'store_true', action = 'store_true',
help = 'logarithmically spaced bins') help = 'logarithmically spaced bins')
parser.set_defaults(data = None, parser.set_defaults(data = None,
range = None, weights = None,
N = None, range = None,
log = False, N = None,
log = False,
) )
(options,filenames) = parser.parse_args() (options,filenames) = parser.parse_args()
@ -77,7 +82,9 @@ for name in filenames:
errors = [] errors = []
remarks = [] remarks = []
if table.label_dimension(options.data) != 1: errors.append('data {} is not a scalar.'.format(options.data)) if table.label_dimension(options.data) != 1: errors.append('data {} are not scalar.'.format(options.data))
if options.weights and \
table.label_dimension(options.data) != 1: errors.append('weights {} are not scalar.'.format(options.weights))
if remarks != []: damask.util.croak(remarks) if remarks != []: damask.util.croak(remarks)
if errors != []: if errors != []:
@ -87,8 +94,7 @@ for name in filenames:
# --------------- read data ---------------------------------------------------------------- # --------------- read data ----------------------------------------------------------------
table.data_readArray(options.data) table.data_readArray([options.data,options.weights])
bincenter = np.zeros(options.N,'f')
# --------------- auto range --------------------------------------------------------------- # --------------- auto range ---------------------------------------------------------------
@ -102,7 +108,9 @@ for name in filenames:
count,edges = np.histogram(table.data[:,0], count,edges = np.histogram(table.data[:,0],
bins = reverse(forward(rangeMin) + np.arange(options.N+1) * bins = reverse(forward(rangeMin) + np.arange(options.N+1) *
(forward(rangeMax)-forward(rangeMin))/options.N), (forward(rangeMax)-forward(rangeMin))/options.N),
range = (rangeMin,rangeMax)) range = (rangeMin,rangeMax),
weights = None if options.weights is None else table.data[:,1],
)
bincenter = reverse(forward(rangeMin) + (0.5+np.arange(options.N)) * bincenter = reverse(forward(rangeMin) + (0.5+np.arange(options.N)) *
(forward(rangeMax)-forward(rangeMin))/options.N) # determine center of bins (forward(rangeMax)-forward(rangeMin))/options.N) # determine center of bins