Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

# Plotly 3d vedo equivalent

See original GitHub issue

After familiarizing myself with the python plotly module, I find that the rendering is rather slow; especially for iso volumes. To evaluate this I shall include some code, the effect becomes more apparent as the value of n, a power of two in this instance, is increased.

Perhaps you’re able to provide the equivalent code using vedo, then I might make a comparison; this will also add to your examples.

If possible, a render to screen, rather than the web browser, as this may be faster; though this may also be sent to a web page through some vedo code that I’m not familiar with.

``````

#   Three volume plots ; using subplots.
#   Some from a 3d array .
#   Now using 3d array and fftn, fftshift, ifftn .

import plotly.offline as py  # attempting to speed up render.

import plotly.graph_objects as go
from plotly.subplots import make_subplots

import numpy as np
from scipy.fftpack import fftn, ifftn, fftshift
import scipy.signal as sg

# ------------------------------------------------------------------

# np.ndarray(shape=(2,2), dtype=float, order='F')

n=64
m=n
p=n

# arr = np.ndarray(shape=(n,m,p), dtype=float)
# Generate data
p1=p
m1=m
n1=n
p1=int(p1/4)
m1=int(m1/9)
n1=int(n1/5)

X, Y, Z = np.mgrid[:n, :m, :p]
vol = np.zeros((n, m, p))

x1=X.flatten()
y1=Y.flatten()
z1=Z.flatten()

for k in range(p1):
for j in range(m1):
for i in range(n1):
vol[i,j,k]=1
#vol[i,j,k]=k*m1*n1 + j*n1 + i

# ------------------------------

vol /= vol.max()

volf = fftn(vol) # spectra .
volg = volf # unaltered, for further processes, possibly ifftn .
# other code here  .

volg = ifftn(volg)
volg = volg.real

# Preprocess spectra before 3d graph .

volf = abs(volf)
volf = fftshift(volf) # for centered spectra.
volf /= volf.max()
Ag=10^6
volf = np.log(Ag*volf +1)/np.log(Ag+1) # to bring out detail .

# ------------------------- Graphing results ---------------------------
# Make figure with subplots

fig = make_subplots(
rows=3, cols=1,
specs=[[{'type': 'Volume'}], [{'type': 'Volume'}],
[{'type': 'Volume'}]])

# Initialize figure with 3 3D subplots

#subplot_titles=("data 3d", "3d log|fft|", "3d Real(ifft)")
# )

# ------------------------------------------------------------------

go.Volume(
x=x1,
y=y1,
z=z1,
value=vol.flatten(),
isomin=0.1,
isomax=1.0,
opacity=0.1, # needs to be small to see through all surfaces
surface_count=17 # needs to be a large number for good volume rendering
),
row=1, col=1
)

go.Volume(
x=x1,
y=y1,
z=z1,
value=volf.flatten(),
isomin=0.1,
isomax=1.0,
opacity=0.1, # needs to be small to see through all surfaces
surface_count=17 # needs to be a large number for good volume rendering
),
row=2, col=1
)

go.Volume(
x=x1,
y=y1,
z=z1,
value=volg.flatten(),
isomin=0.1,
isomax=1.0,
opacity=0.1, # needs to be small to see through all surfaces
surface_count=17 # needs to be a large number for good volume rendering
),
row=3, col=1
)

fig.update_layout(
title_text='3D subplots with different colorscales',
height=1800,
width=1024
)

#fig.show()
# plot offline

py.plot(fig, filename='isosurface.html')

# ------------------------------------------------------------------

quit()

``````

### Issue Analytics

• State:
• Created 3 years ago

1reaction
edmontzcommented, Jun 7, 2021

Continuing the theme of 2d Discrete Fourier Transform.

These are examples of the use of sub arrays and DFTs to evaluate a larger DFT. There’s more to do before this is in a familiar format, in particular OFT(), should be more like a standard dft.

``````

'''
Edward Montague

Extended Discrete Fourier Transform.

1. Choose size Nx, Ny of array, A
2. Choose size nx, ny of sub array, a and sub DFT on a.
dx=Nx/nx , dy=Ny/ny

3. Loop through A and copy to sub array, a for appropriate indexes.
5. Multiply a by appropriate A row and column, also requires a summation ?
6. Return a to A or do a summation firstly on a ?
7.

FT(A[j,k]) = sum(sum(exp(2*np.pi.%i*((j*u)/Nx + (k*v)/Ny)*A[u,v],v,0,Ny-1),u,0,Nx-1)

OFT(a[j,k]) = sum(sum(exp(2*np.pi.%i*((j*u)/nx + (k*v)/ny)*a[u,v],v,0,ny-1),u,0,nx-1)

FT(A[j,k]) = sum(sum(omega_x(j,jp,Nx)*omega_y(k,kp,Ny)*OFT(idex(A,j,k,u,v,dx,dy),nx,ny,jp,kp),kp,0,dy-1),jp,0,dx-1)

FT(A[j,k]) = sum(sum(omega_x(j,jp,Nx)*omega_y(k,kp,Ny)*OFT(a,nx,ny,jp,kp),kp,0,dy-1),jp,0,dx-1)

'''

import numpy as np
import math

#     Functions.

def gen_a(a,nx,ny):
for k in range(ny):
for j in range(nx):
a[j,k]=j + k*9

return a

def gen_data(A,Nx,Ny):
for k in range(Ny):
for j in range(Nx):
A[j,k]=j + k*Nx

return A

def print_p(P,px,py):
for k in range(py):
print("  ")
for j in range(px):
v=P[j,k].real
v=math.floor(v*100)/100
w=P[j,k].imag
w=math.floor(w*100)/100
print(v,"+",w,'j',end=' ')
print("   ")
print("   ")

def print_s(S):
v=S.real
v=math.floor(v*100)/100
w=S.imag
w=math.floor(w*100)/100
print(v,"+",w,'j',end=' ')
print("   ")
print("   ")

# Discrete Fourier Transform, returns same values as np.fft.fftn()
def FT(A,Nx,Ny,j,k):
s=0
for u in range(Nx):
for v in range(Ny):
c=complex(0,2*np.pi*((j*u)/Nx + (k*v)/Ny))
c=np.exp(c)
s=s+c*A[u,v]
return s

def OFT(a,nx,ny,j,k):
s=0
for u in range(nx):
for v in range(ny):
c=complex(0,2*np.pi*((j*u)/nx + (k*v)/ny))
c=np.exp(c)
s=s + c*a[u,v]
return s

def idex(a,A,jp,kp,dx,dy,nx,ny):
for up in range(nx):
for vp in range(ny):
a[up,vp]=A[jp+up*dx,kp+vp*dy]
return a

def omega_x(j,jp,Nx):
return np.exp(complex(0,2*np.pi*(j)*(jp)/Nx))

def omega_y(k,kp,Ny):
return np.exp(complex(0,2*np.pi*(k)*(kp)/Ny))

def FT1(A,j,k,dx,dy,nx,ny,Nx,Ny):
s=0
for jp in range(dx):
for kp in range(dy):
for up in range(nx):
for vp in range(ny):
es=np.exp(complex(0,2*np.pi*(((k)*(dy*(vp)+kp))/Ny+((j)*(dx*(up)+jp))/Nx)))
s=s+A[dx*(up)+jp,dy*(vp)+kp]*es
return s

def xOFT(A,j,k,jp,kp,nx,ny,dx,dy):
s=0
for up in range(nx):
for vp in range(ny):
exprx=np.exp(complex(0,2*np.pi*(j*up/nx+k*vp/ny)))
exprx=exprx*A[jp+up*dx,kp+vp*dy]
s=s+exprx
return s

def FT3(A,j,k,dx,dy,nx,ny,Nx,Ny):
s=0
for jp in range(dx):
for kp in range(dy):
expr2=np.exp(complex(0,2*np.pi*((j*jp)/Nx+(k*kp)/Ny)))
expr2=expr2*xOFT(A,j,k,jp,kp,nx,ny,dx,dy)
s=s+expr2
return s

def FT4(A,j,k,dx,dy,nx,ny,Nx,Ny):
s=0
for jp in range(dx):
for kp in range(dy):
expr1=omega_x(j,jp,Nx)*omega_y(k,kp,Ny)
expr2=expr1*xOFT(A,j,k,jp,kp,nx,ny,dx,dy)
s=s+expr2

return s

def FT5(A,a,j,k,dx,dy,nx,ny,Nx,Ny):
s=0
for jp in range(dx):
for kp in range(dy):
a=idex(a,A,jp,kp,dx,dy,nx,ny) # copy from A[] to a[]
expr1=omega_x(j,jp,Nx)*omega_y(k,kp,Ny)
expr2=expr1*OFT(a,nx,ny,j,k)
s=s+expr2

return s

# ------------------------------------------------------------
Nx=9
Ny=9
nx=3
ny=3
dx=int(Nx/nx)
dy=int(Ny/ny)
#
#
a = np.ndarray([nx,ny],np.complex)
b = np.ndarray([nx,ny],np.complex)
#
a = gen_a(a,nx,ny)
print_p(a,nx,ny)
b= np.fft.fftn(a)
print_p(b,nx,ny)

print("----------------=========--------------------")
print("  ")

A = np.ndarray([Nx,Ny],np.complex)

A=gen_data(A,Nx,Ny)
# print_p(A,Nx,Ny)
B = np.fft.fftn(A)
print("fftn")
# print_p(B,Nx,Ny)
y=B[0,1]
print_s(y)

y=FT(A,Nx,Ny,0,1)
print("FT")
print_s(y)

y=FT1(A,0,1,dx,dy,nx,ny,Nx,Ny)
print("FT1")
print_s(y)

y=FT3(A,0,1,dx,dy,nx,ny,Nx,Ny)
print("FT3")
print_s(y)

y=FT4(A,0,1,dx,dy,nx,ny,Nx,Ny)
print("FT4")
print_s(y)

y=FT5(A,a,0,1,dx,dy,nx,ny,Nx,Ny)
print("FT5")
print_s(y)

quit()

# -----------------------------------------------------------------------

``````
1reaction
edmontzcommented, Nov 22, 2020

You don’t need to import numba to run the last few examples, if you don’t then comment out all instances of the @jit function decorator. Bound to run slower after this.

Calls to fft routines use 10% of the process time, vedo appears to use most of the rest.

#### Top Results From Across the Web

3d surface plots in Python - Plotly
Detailed examples of 3D Surface Plots including changing color, size, log axes, and more in Python.
Plotly express in Python
The plotly.express module (usually imported as px ) contains functions that can create entire figures at once, and is referred to as Plotly...
Intro to 3D Visualization | Dash for Python Documentation | Plotly
The view is a 3D View that can do Geometry rendering for meshes or Volume rendering for 3D images. The view can be...
3d axes in Python - Plotly
Detailed examples of 3D Axes including changing color, size, log axes, and more in Python. ... How to format axes of 3d plots...
Plotly 3D plot in python - Stack Overflow
I want to make 3D plot in python using plotly. Actually its the first step of an animation but first I need to...

#### Troubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free