idllib

Personal IDL library for M. Galloy

single page | use frames     summary     class     fields     routine details     file attributes

analysis/

mg_hist_nd.pro

includes main-level program

top source mg_hist_nd

result = mg_hist_nd(array [, bin_size=numeric] [, nbins=long] [, minimum=float/fltarr(n)] [, maximum=float/fltarr(n)] [, omin=float/fltarr(n)] [, omax=float/fltarr(n)] [, reverse_indices=lonarr] [, weights=numeric array] [, unweighted=same as return value] [, /l64])

Find the histogram of a set of n-dimensional points.

Return value

histogram of size n_1 by n_2 by .... by n_n

Parameters

array in required type=numeric array

array to find histogram of; ndims by npoints array

Keywords

bin_size in optional type=numeric

the size of bin to use; either an n element vector or a scalar to use for all dimensions; either BIN_SIZE or NBINS must be set

nbins in optional type=long

the number of bins to use; either an n element vector or a scalar to use for all dimensions; either BIN_SIZE or NBINS must be set

minimum in optional type=float/fltarr(n) default=min(array, dim

set to either a scalar value to use for the minimum of each dimension or a vector of values; if not specified, will use the natural minimum in each dimension

maximum in optional type=float/fltarr(n) default=max(array, dim

set to either a scalar value to use for the maximum of each dimension or a vector of values; if not specified, will use the natural maximum in each dimension

omin out optional type=float/fltarr(n)

set to a named variable to return the minimum values used in computing the histogram

omax out optional type=float/fltarr(n)

set to a named variable to return the maximum values used in computing the histogram

reverse_indices out optional type=lonarr

set to a named variable to get 1-dimensional vector representing the indices of the points that fall in a particular bin; to find the indices of the points in bin [i, j, k], use the same formular as when using REVERSE_INDICES with HISTOGRAM (after converting to single dimensional indexing):

ijk = [i + nx * j + nx * ny * k] ind = ri[ri[ijk]:ri[ijk + 1] - 1]
See ARRAY_INDICES for converting ind back to 3-dimensional indices.

weights in optional type=numeric array

array with same dimensions as array containing a weight for each point

unweighted out optional type=same as return value

set to a named variable to get the unweighted histogram

l64 in optional type=boolean

set to return long64 results

Examples

Try:

IDL> q = transpose([[0.1 * findgen(40)], [0.2 * findgen(40)]]) IDL> print, mg_hist_nd(q, bin_size=1, weight=q, unweighted=unweighted) 0.500000 0.00000 0.00000 0.00000 2.50000 0.00000 0.00000 0.00000 0.00000 4.00000 0.00000 0.00000 0.00000 6.50000 0.00000 0.00000 0.00000 0.00000 7.50000 0.00000 0.00000 0.00000 10.5000 0.00000 0.00000 0.00000 0.00000 11.0000 0.00000 0.00000 0.00000 14.5000 IDL> print, unweighted 5 0 0 0 5 0 0 0 0 5 0 0 0 5 0 0 0 0 5 0 0 0 5 0 0 0 0 5 0 0 0 5 IDL> print, mg_hist_nd(q, nbins=[4, 8], max=[4.0, 8.0]) 5 0 0 0 5 0 0 0 0 5 0 0 0 5 0 0 0 0 5 0 0 0 5 0 0 0 0 5 0 0 0 5
This example is in a main-level program at the end of this file. Run it with:
IDL> .run mg_hist_nd

Author information

History:

16 January 2008, written by Michael Galloy.

Code adapted from HIST_ND from David Fanning and HIST_ND_WEIGHT by Jeremy Bailin.

File attributes

Modification date: Fri Oct 28 16:13:37 2011
Lines: 204
Docformat: rst rst
Personal library of Michael Galloy
Contact me if you have enhancement requests or bug fixes.