Initial import
This commit is contained in:
commit
56a50eead3
820 changed files with 192077 additions and 0 deletions
69
scripts/lic_plot/lic.py
Normal file
69
scripts/lic_plot/lic.py
Normal file
|
@ -0,0 +1,69 @@
|
|||
#+
|
||||
# ARES/HADES/BORG Package -- ./scripts/lic_plot/lic.py
|
||||
# Copyright (C) 2014-2020 Guilhem Lavaux <guilhem.lavaux@iap.fr>
|
||||
# Copyright (C) 2009-2020 Jens Jasche <jens.jasche@fysik.su.se>
|
||||
#
|
||||
# Additional contributions from:
|
||||
# Guilhem Lavaux <guilhem.lavaux@iap.fr> (2023)
|
||||
#
|
||||
#+
|
||||
import numpy as np
|
||||
|
||||
|
||||
def lic_flow(vectors,len_pix=10):
|
||||
vectors = np.asarray(vectors)
|
||||
m,n,two = vectors.shape
|
||||
if two!=2:
|
||||
raise ValueError
|
||||
|
||||
result = np.zeros((2*len_pix+1,m,n,2),dtype=np.int32) # FIXME: int16?
|
||||
center = len_pix
|
||||
result[center,:,:,0] = np.arange(m)[:,np.newaxis]
|
||||
result[center,:,:,1] = np.arange(n)[np.newaxis,:]
|
||||
|
||||
for i in range(m):
|
||||
for j in range(n):
|
||||
y = i
|
||||
x = j
|
||||
fx = 0.5
|
||||
fy = 0.5
|
||||
for k in range(len_pix):
|
||||
vx, vy = vectors[y,x]
|
||||
print x, y, vx, vy
|
||||
if vx>=0:
|
||||
tx = (1-fx)/vx
|
||||
else:
|
||||
tx = -fx/vx
|
||||
if vy>=0:
|
||||
ty = (1-fy)/vy
|
||||
else:
|
||||
ty = -fy/vy
|
||||
if tx<ty:
|
||||
print "x step"
|
||||
if vx>0:
|
||||
x+=1
|
||||
fy+=vy*tx
|
||||
fx=0.
|
||||
else:
|
||||
x-=1
|
||||
fy+=vy*tx
|
||||
fx=1.
|
||||
else:
|
||||
print "y step"
|
||||
if vy>0:
|
||||
y+=1
|
||||
fx+=vx*ty
|
||||
fy=0.
|
||||
else:
|
||||
y-=1
|
||||
fx+=vx*ty
|
||||
fy=1.
|
||||
if x<0: x=0
|
||||
if y<0: y=0
|
||||
if x>=n: x=n-1
|
||||
if y>=m: y=m-1
|
||||
result[center+k+1,i,j,:] = y, x
|
||||
|
||||
|
||||
|
||||
return result
|
71
scripts/lic_plot/lic_demo.py
Normal file
71
scripts/lic_plot/lic_demo.py
Normal file
|
@ -0,0 +1,71 @@
|
|||
#+
|
||||
# ARES/HADES/BORG Package -- ./scripts/lic_plot/lic_demo.py
|
||||
# Copyright (C) 2014-2020 Guilhem Lavaux <guilhem.lavaux@iap.fr>
|
||||
# Copyright (C) 2009-2020 Jens Jasche <jens.jasche@fysik.su.se>
|
||||
#
|
||||
# Additional contributions from:
|
||||
# Guilhem Lavaux <guilhem.lavaux@iap.fr> (2023)
|
||||
#
|
||||
#+
|
||||
import numpy as np
|
||||
import pylab as plt
|
||||
|
||||
import lic_internal
|
||||
|
||||
dpi = 100
|
||||
size = 700
|
||||
video = False
|
||||
|
||||
vortex_spacing = 0.5
|
||||
extra_factor = 2.
|
||||
|
||||
a = np.array([1,0])*vortex_spacing
|
||||
b = np.array([np.cos(np.pi/3),np.sin(np.pi/3)])*vortex_spacing
|
||||
rnv = int(2*extra_factor/vortex_spacing)
|
||||
vortices = [n*a+m*b for n in range(-rnv,rnv) for m in range(-rnv,rnv)]
|
||||
vortices = [(x,y) for (x,y) in vortices if -extra_factor<x<extra_factor and -extra_factor<y<extra_factor]
|
||||
|
||||
|
||||
xs = np.linspace(-1,1,size).astype(np.float32)[None,:]
|
||||
ys = np.linspace(-1,1,size).astype(np.float32)[:,None]
|
||||
|
||||
vectors = np.zeros((size,size,2),dtype=np.float32)
|
||||
for (x,y) in vortices:
|
||||
rsq = (xs-x)**2+(ys-y)**2
|
||||
vectors[...,0] += (ys-y)/rsq
|
||||
vectors[...,1] += -(xs-x)/rsq
|
||||
|
||||
texture = np.random.rand(size,size).astype(np.float32)
|
||||
|
||||
plt.bone()
|
||||
frame=0
|
||||
|
||||
if video:
|
||||
kernellen = 31
|
||||
for t in np.linspace(0,1,16*5):
|
||||
kernel = np.sin(np.arange(kernellen)*np.pi/kernellen)*(1+np.sin(2*np.pi*5*(np.arange(kernellen)/float(kernellen)+t)))
|
||||
|
||||
kernel = kernel.astype(np.float32)
|
||||
|
||||
image = lic_internal.line_integral_convolution(vectors, texture, kernel)
|
||||
|
||||
plt.clf()
|
||||
plt.axis('off')
|
||||
plt.figimage(image)
|
||||
plt.gcf().set_size_inches((size/float(dpi),size/float(dpi)))
|
||||
plt.savefig("flow-%04d.png"%frame,dpi=dpi)
|
||||
frame += 1
|
||||
else:
|
||||
kernellen=31
|
||||
kernel = np.sin(np.arange(kernellen)*np.pi/kernellen)
|
||||
kernel = kernel.astype(np.float32)
|
||||
|
||||
image = lic_internal.line_integral_convolution(vectors, texture, kernel)
|
||||
|
||||
plt.clf()
|
||||
plt.axis('off')
|
||||
plt.figimage(image)
|
||||
plt.gcf().set_size_inches((size/float(dpi),size/float(dpi)))
|
||||
plt.savefig("flow-image.png",dpi=dpi)
|
||||
|
||||
|
6914
scripts/lic_plot/lic_internal.c
Normal file
6914
scripts/lic_plot/lic_internal.c
Normal file
File diff suppressed because it is too large
Load diff
100
scripts/lic_plot/lic_internal.pyx
Normal file
100
scripts/lic_plot/lic_internal.pyx
Normal file
|
@ -0,0 +1,100 @@
|
|||
#+
|
||||
# ARES/HADES/BORG Package -- ./scripts/lic_plot/lic_internal.pyx
|
||||
# Copyright (C) 2014-2020 Guilhem Lavaux <guilhem.lavaux@iap.fr>
|
||||
# Copyright (C) 2009-2020 Jens Jasche <jens.jasche@fysik.su.se>
|
||||
#
|
||||
# Additional contributions from:
|
||||
# Guilhem Lavaux <guilhem.lavaux@iap.fr> (2023)
|
||||
#
|
||||
#+
|
||||
|
||||
import numpy as np
|
||||
cimport numpy as np
|
||||
|
||||
cdef void _advance(float vx, float vy,
|
||||
int* x, int* y, float*fx, float*fy, int w, int h):
|
||||
cdef float tx, ty
|
||||
if vx>=0:
|
||||
tx = (1-fx[0])/vx
|
||||
else:
|
||||
tx = -fx[0]/vx
|
||||
if vy>=0:
|
||||
ty = (1-fy[0])/vy
|
||||
else:
|
||||
ty = -fy[0]/vy
|
||||
if tx<ty:
|
||||
if vx>=0:
|
||||
x[0]+=1
|
||||
fx[0]=0
|
||||
else:
|
||||
x[0]-=1
|
||||
fx[0]=1
|
||||
fy[0]+=tx*vy
|
||||
else:
|
||||
if vy>=0:
|
||||
y[0]+=1
|
||||
fy[0]=0
|
||||
else:
|
||||
y[0]-=1
|
||||
fy[0]=1
|
||||
fx[0]+=ty*vx
|
||||
if x[0]>=w:
|
||||
x[0]=w-1 # FIXME: other boundary conditions?
|
||||
if x[0]<0:
|
||||
x[0]=0 # FIXME: other boundary conditions?
|
||||
if y[0]<0:
|
||||
y[0]=0 # FIXME: other boundary conditions?
|
||||
if y[0]>=h:
|
||||
y[0]=h-1 # FIXME: other boundary conditions?
|
||||
|
||||
|
||||
#np.ndarray[float, ndim=2]
|
||||
def line_integral_convolution(
|
||||
np.ndarray[float, ndim=3] vectors,
|
||||
np.ndarray[float, ndim=2] texture,
|
||||
np.ndarray[float, ndim=1] kernel):
|
||||
cdef int i,j,k,x,y
|
||||
cdef int h,w,kernellen
|
||||
cdef int t
|
||||
cdef float fx, fy, tx, ty
|
||||
cdef np.ndarray[float, ndim=2] result
|
||||
|
||||
h = vectors.shape[0]
|
||||
w = vectors.shape[1]
|
||||
t = vectors.shape[2]
|
||||
kernellen = kernel.shape[0]
|
||||
if t!=2:
|
||||
raise ValueError("Vectors must have two components (not %d)" % t)
|
||||
result = np.zeros((h,w),dtype=np.float32)
|
||||
|
||||
for i in range(h):
|
||||
for j in range(w):
|
||||
x = j
|
||||
y = i
|
||||
fx = 0.5
|
||||
fy = 0.5
|
||||
|
||||
k = kernellen//2
|
||||
#print i, j, k, x, y
|
||||
result[i,j] += kernel[k]*texture[x,y]
|
||||
while k<kernellen-1:
|
||||
_advance(vectors[y,x,0],vectors[y,x,1],
|
||||
&x, &y, &fx, &fy, w, h)
|
||||
k+=1
|
||||
#print i, j, k, x, y
|
||||
result[i,j] += kernel[k]*texture[x,y]
|
||||
|
||||
x = j
|
||||
y = i
|
||||
fx = 0.5
|
||||
fy = 0.5
|
||||
|
||||
while k>0:
|
||||
_advance(-vectors[y,x,0],-vectors[y,x,1],
|
||||
&x, &y, &fx, &fy, w, h)
|
||||
k-=1
|
||||
#print i, j, k, x, y
|
||||
result[i,j] += kernel[k]*texture[x,y]
|
||||
|
||||
return result
|
||||
|
22
scripts/lic_plot/setup.py
Normal file
22
scripts/lic_plot/setup.py
Normal file
|
@ -0,0 +1,22 @@
|
|||
#+
|
||||
# ARES/HADES/BORG Package -- ./scripts/lic_plot/setup.py
|
||||
# Copyright (C) 2014-2020 Guilhem Lavaux <guilhem.lavaux@iap.fr>
|
||||
# Copyright (C) 2009-2020 Jens Jasche <jens.jasche@fysik.su.se>
|
||||
#
|
||||
# Additional contributions from:
|
||||
# Guilhem Lavaux <guilhem.lavaux@iap.fr> (2023)
|
||||
#
|
||||
#+
|
||||
from distutils.core import setup
|
||||
from distutils.extension import Extension
|
||||
from Cython.Distutils import build_ext
|
||||
import numpy
|
||||
|
||||
setup(
|
||||
cmdclass = {'build_ext': build_ext},
|
||||
ext_modules = [
|
||||
Extension("lic_internal", ["lic_internal.pyx"],
|
||||
include_dirs=[numpy.get_include()])
|
||||
],
|
||||
)
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue