Skip to content

Instantly share code, notes, and snippets.

@crackwitz
Created August 2, 2020 14:34
Show Gist options
  • Save crackwitz/358ded8b3a69549962e21eb4b55f81d2 to your computer and use it in GitHub Desktop.
Save crackwitz/358ded8b3a69549962e21eb4b55f81d2 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
import sys
import numpy as np
from scipy.interpolate import interp1d, interp2d
np.set_printoptions(suppress=True, linewidth=120)
k = 10
source1d = np.float64([0]*(2*k-1) + [1]*(2*k-1))
source2d = np.float64([source1d] * (2*k-1))
edge = 2*k-1 - 0.5
sampler1d = interp1d(x=np.arange(4*k-2), y=source1d, kind='cubic') # linear, cubic, quintic
sampler2d = interp2d(x=np.arange(4*k-2), y=np.arange(2*k-1), z=source2d, kind='cubic') # linear, cubic, quintic
samplepoints = edge + np.arange(-k, k+0.5, 0.5)
samples1d = sampler1d(samplepoints)
samples2d = sampler2d(samplepoints, k-1)
print(np.vstack([samplepoints - edge, samples1d, samples2d]).T)
# [[-10. 0.00000072 0.00000072]
# [ -9.5 -0. 0. ]
# [ -9. -0.00000267 -0.00000267]
# [ -8.5 -0. -0. ]
# [ -8. 0.00000996 0.00000996]
# [ -7.5 0. 0. ]
# [ -7. -0.00003719 -0.00003719]
# [ -6.5 -0. -0. ]
# [ -6. 0.00013879 0.00013879]
# [ -5.5 0. 0. ]
# [ -5. -0.00051796 -0.00051796]
# [ -4.5 0. -0. ]
# [ -4. 0.00193304 0.00193304]
# [ -3.5 0. 0. ]
# [ -3. -0.00721421 -0.00721421]
# [ -2.5 0. -0. ]
# [ -2. 0.02692379 0.02692379]
# [ -1.5 0. 0. ]
# [ -1. -0.10048095 -0.10048095]
# [ -0.5 -0. -0. ]
# [ 0. 0.5 0.5 ]
# [ 0.5 1. 1. ]
# [ 1. 1.10048095 1.10048095]
# [ 1.5 1. 1. ]
# [ 2. 0.97307621 0.97307621]
# [ 2.5 1. 1. ]
# [ 3. 1.00721421 1.00721421]
# [ 3.5 1. 1. ]
# [ 4. 0.99806696 0.99806696]
# [ 4.5 1. 1. ]
# [ 5. 1.00051796 1.00051796]
# [ 5.5 1. 1. ]
# [ 6. 0.99986121 0.99986121]
# [ 6.5 1. 1. ]
# [ 7. 1.00003719 1.00003719]
# [ 7.5 1. 1. ]
# [ 8. 0.99999004 0.99999004]
# [ 8.5 1. 1. ]
# [ 9. 1.00000267 1.00000267]
# [ 9.5 1. 1. ]
# [ 10. 0.99999928 0.99999928]]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment