Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Number density distribution of an 1D-array - 2 different attempts

I have an large array of elements that I call RelDist (In which dimensionally, is a unit of distance) in a simulated volume. I am attempting to determine the distribution for the "number of values per unit volume" which is also number density. It should be similar to this diagram:

I am aware that the axis is scaled log base 10, the plot of the set should definitely drop off. enter image description here

Mathematically, I set it up as two equivalent equations:

enter image description here

where N is the number of elements in the array being differentiated in respect to the natural log of the distances. It can also be equivalently re-written in the form of a regular derivative by introducing another factor of r.

Equivalently,

enter image description here

So for ever increasing r, I want to count the change in N of elements per logarithmic bin of r.

As of now, I have trouble setting up the frequency counting in the histogram while accommodating the volume along side it.


Attempt 1

This is using the dN/dlnr/volume equations

def n(dist, numbins):

    logdist= np.log(dist)
    hist, r_array = np.histogram(logdist, numbins)
    dlogR = r_array[1]-r_array[0]

    x_array = r_array[1:] - dlogR/2

    ## I am condifent the above part of this code is correct.
    ## The succeeding portion does not work.

    dR = r_array[1:] - r_array[0:numbins] 
    dN_dlogR = hist * x_array/dR

    volume = 4*np.pi*dist*dist*dist

    ## The included volume is incorrect

    return [x_array, dN_dlogR/volume]

Plotting this does not even properly show a distribution like the first plot I posted above and it only works when I choose the bin number to be the same shape as my input array. The bun number should arbitrary, should it not?


Attempt 2

This is using the equivalent dN/dr/volume equation.

numbins = np.linspace(min(RelDist),max(RelDist), 100)
hist, r_array = np.histogram(RelDist, numbins)

volume = 4*np.float(1000**2)

dR = r_array[1]-r_array[0]
x_array = r_array[1:] - dR/2


y = hist/dR

A little bit easier, but without including the volume term, I get a sort of histogram distribution, which is at least a start.

With this attempt, how would include the volume term with the array?

Example

Start at a distance R value of something like 10, counts the change in number in respect to R, then increasing to a distance value R of 20, counts the change, increase to value of 30, counts the change, and so on so forth.


Here is a txt file of my array if you are interested in re-creating it

https://www.dropbox.com/s/g40gp88k2p6pp6y/RelDist.txt?dl=0

like image 381
iron2man Avatar asked Jun 15 '17 08:06

iron2man


1 Answers

Since no one was able to help answer, I will provide my result in case someone wants to use it for future use:

def n_ln(dist, numbins):
    log_dist = np.log10(dist)
    bins = np.linspace(min(log_dist),max(log_dist), numbins)
    hist, r_array = np.histogram(log_dist, bins)

    dR = r_array[1]-r_array[0]    
    x_array = r_array[1:] - dR/2
    volume =  [4.*np.pi*i**3. for i in 10**x_array[:] ]

    return [10**x_array, hist/dR/volume]
like image 192
iron2man Avatar answered Oct 13 '22 23:10

iron2man