1

I have a dataset containing values in a 200x200x38 3D space. The data is centered at [100,100,z] where z is height, and the first two values are horizontal x and y coordinates. I am trying to create a visualization of a cross section that averages the values in the dataset along a radial and at each height (making a height-radius average).

Most efficient way to calculate radial profile This post describes how to do a radial average for a 2D dataset,̶b̶u̶t̶ ̶I̶ ̶d̶o̶n̶'̶t̶ ̶q̶u̶i̶t̶e̶ ̶u̶n̶d̶e̶r̶s̶t̶a̶n̶d̶ ̶h̶o̶w̶ ̶t̶h̶e̶y̶ ̶d̶i̶d̶ ̶t̶h̶e̶y̶ ̶b̶i̶n̶n̶e̶d̶ ̶t̶h̶e̶i̶r̶ ̶d̶a̶t̶a̶ ̶i̶n̶t̶o̶ ̶d̶i̶f̶f̶e̶r̶e̶n̶t̶ ̶r̶a̶d̶i̶i̶ ̶e̶i̶t̶h̶e̶r̶ ̶s̶i̶n̶c̶e̶.̶ ̶ ̶I̶'̶v̶e̶ ̶d̶e̶f̶i̶n̶e̶d̶ ̶f̶u̶n̶c̶t̶i̶o̶n̶s̶ ̶f̶o̶r̶ ̶r̶a̶d̶i̶i̶ ̶a̶n̶d̶ ̶a̶n̶g̶l̶e̶ ̶f̶r̶o̶m̶ ̶c̶e̶n̶t̶e̶r̶,̶ ̶b̶u̶t̶ ̶d̶o̶n̶'̶t̶ ̶k̶n̶o̶w̶ ̶h̶o̶w̶ ̶t̶o̶ ̶c̶o̶n̶v̶e̶r̶t̶ ̶m̶y̶ ̶C̶a̶r̶t̶e̶s̶i̶a̶n̶ ̶d̶a̶t̶a̶ ̶i̶n̶t̶o̶ ̶a̶ ̶c̶y̶l̶i̶n̶d̶r̶i̶c̶a̶l̶ ̶c̶o̶o̶r̶d̶i̶n̶a̶t̶e̶ ̶s̶h̶a̶p̶e̶.̶

def radial_profile(data, center):
    y, x = np.indices((data.shape))
    r = np.sqrt((x - center[0])**2 + (y - center[1])**2)
    r = r.astype(np.int)

    tbin = np.bincount(r.ravel(), data.ravel())
    nr = np.bincount(r.ravel())
    radialprofile = tbin / nr
    return radialprofile 
Cent=[100,100]
Rav=[]
for i in range(37):
    B=ref[:,:,i,0]
    if B == -999.9:
        B=np.nan
    RRR=radial_profile(B,Cent)
    Rav.append(RRR)
plt.imshow(Rav, vmin=-15, vmax=70)
plt.colorbar();
plt.show()

Using this I've been able to plot it, but have to figure out a way to remove the -999.9 values from the average. I have tried to assign it as null, but to no success. The plot otherwise works.

atmosking
  • 11
  • 4
  • If you don't understand the accepted answer to that question, then what are you actually asking? A good answer to your question would essentially build on that one... – Mad Physicist Jun 02 '19 at 01:52
  • When asking a question, people will be better able to provide help if you provide code that they can easily understand and use to reproduce the problem. Can you please post sample data and/or code? – Kapocsi Jun 02 '19 at 01:56

1 Answers1

0
def radial_profile(data, center):
    y, x = np.indices((data.shape))
    r = np.sqrt((x - center[0])**2 + (y - center[1])**2)
    r = r.astype(np.int)

    tbin = np.bincount(r.ravel(), data.ravel())
    nr = np.bincount(r.ravel())
    radialprofile = tbin / nr
    return radialprofile 
Cent=[100,100]
Rav=[]
for i in range(37):
    dbz=np.array(ref)
    dbz[dbz == -999.9]=np.nan
    B=dbz[:,:,i,0]
    RRR=radial_profile(B,Cent)
    Rav.append(RRR)
plt.imshow(Rav, vmin=-15, vmax=70)
plt.colorbar();
plt.show()

My apologies, I should have taken a harder look at trying to understand the post I was referring to in my question.

If anyone has any more clean or efficient solutions I would appreciate it

atmosking
  • 11
  • 4