This commit is contained in:
6
script/jep/jep1.py
Executable file
6
script/jep/jep1.py
Executable file
@@ -0,0 +1,6 @@
|
||||
a = call_jep("numpy", "ones", [(2,3)])
|
||||
print a.getDimensions(), a.getData()
|
||||
|
||||
|
||||
b = call_jep("numpy", "transpose", [a,])
|
||||
print b.getDimensions(), b.getData()
|
||||
14
script/jep/jepcall.py
Executable file
14
script/jep/jepcall.py
Executable file
@@ -0,0 +1,14 @@
|
||||
|
||||
|
||||
def call_cpython(module, function, args = []):
|
||||
j=__getJep()
|
||||
f = "function_" + j.hashCode()
|
||||
eval_cpython("from " + module + " import " + function + " as " + f)
|
||||
return j.invoke(f, args)
|
||||
|
||||
|
||||
|
||||
call_cpython("numpy", "ones", [(2,3)])
|
||||
|
||||
|
||||
|
||||
15
script/jep/jepscript.py
Executable file
15
script/jep/jepscript.py
Executable file
@@ -0,0 +1,15 @@
|
||||
import numpy
|
||||
from java.lang import System
|
||||
|
||||
def transpose(x):
|
||||
return numpy.transpose(x)
|
||||
|
||||
|
||||
for I in range(10):
|
||||
System.out.println(I)
|
||||
|
||||
b = numpy.ones((2,4))
|
||||
print b
|
||||
|
||||
#System.out.println(x)
|
||||
b
|
||||
47
script/jep/jepscript2.py
Executable file
47
script/jep/jepscript2.py
Executable file
@@ -0,0 +1,47 @@
|
||||
import numpy as np
|
||||
import matplotlib.pyplot as plt
|
||||
|
||||
# example data
|
||||
|
||||
x = np.arange(0.1, 4, 0.5)
|
||||
y = np.exp(-x)
|
||||
|
||||
# example variable error bar values
|
||||
yerr = 0.1 + 0.2*np.sqrt(x)
|
||||
xerr = 0.1 + yerr
|
||||
|
||||
# First illustrate basic pyplot interface, using defaults where possible.
|
||||
plt.figure()
|
||||
plt.errorbar(x, y, xerr=0.2, yerr=0.4)
|
||||
plt.title("Simplest errorbars, 0.2 in x, 0.4 in y")
|
||||
|
||||
# Now switch to a more OO interface to exercise more features.
|
||||
fig, axs = plt.subplots(nrows=2, ncols=2, sharex=True)
|
||||
ax = axs[0,0]
|
||||
ax.errorbar(x, y, yerr=yerr, fmt='o')
|
||||
ax.set_title('Vert. symmetric')
|
||||
|
||||
# With 4 subplots, reduce the number of axis ticks to avoid crowding.
|
||||
ax.locator_params(nbins=4)
|
||||
|
||||
ax = axs[0,1]
|
||||
ax.errorbar(x, y, xerr=xerr, fmt='o')
|
||||
ax.set_title('Hor. symmetric')
|
||||
|
||||
ax = axs[1,0]
|
||||
ax.errorbar(x, y, yerr=[yerr, 2*yerr], xerr=[xerr, 2*xerr], fmt='--o')
|
||||
ax.set_title('H, V asymmetric')
|
||||
|
||||
ax = axs[1,1]
|
||||
ax.set_yscale('log')
|
||||
# Here we have to be careful to keep all y values positive:
|
||||
ylower = np.maximum(1e-2, y - yerr)
|
||||
yerr_lower = y - ylower
|
||||
|
||||
ax.errorbar(x, y, yerr=[yerr_lower, 2*yerr], xerr=xerr,
|
||||
fmt='o', ecolor='g', capthick=2)
|
||||
ax.set_title('Mixed sym., log y')
|
||||
|
||||
fig.suptitle('Variable errorbars')
|
||||
|
||||
plt.show()
|
||||
45
script/jep/jepscript3.py
Executable file
45
script/jep/jepscript3.py
Executable file
@@ -0,0 +1,45 @@
|
||||
import numpy as np
|
||||
from scipy.fftpack import fft
|
||||
|
||||
def plot(x,y, block = True):
|
||||
import matplotlib.pyplot as plt
|
||||
plt.figure()
|
||||
plt.plot(x, y)
|
||||
plt.grid()
|
||||
#if show:
|
||||
plt.show(block=block)
|
||||
|
||||
|
||||
def get_f(N,T,F):
|
||||
x = np.linspace(0.0, N*T, N)
|
||||
y=0.0
|
||||
for (a,f) in F:
|
||||
y = y + a*np.sin(f * 2.0*np.pi*x)
|
||||
return (x,y)
|
||||
|
||||
def get_fft(x,y,T):
|
||||
N = len(x)
|
||||
yf = fft(y)
|
||||
xf = np.linspace(0.0, 1.0/(2.0*T), N / 2)
|
||||
yfp = 2.0/N * np.abs(yf[0:N/2])
|
||||
return (xf,yf,yfp)
|
||||
|
||||
def get_fft2(y):
|
||||
T = 1.0 / 800.0
|
||||
N = len(y)
|
||||
yf = fft(y)
|
||||
return yf
|
||||
xf = np.linspace(0.0, 1.0/(2.0*T), N/2)
|
||||
yfp = 2.0/N * np.abs(yf[0:N/2])
|
||||
return (xf,yf,yfp)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
N = 600 # Number of sample points
|
||||
T = 1.0 / 800.0 # sample spacing
|
||||
F = [(1.0,50.0), (0.5,80.0)] #Sinuoisids
|
||||
(x,y) = get_f(N,T,F)
|
||||
(xf,yf,yfp) = get_fft(x,y,T)
|
||||
|
||||
plot(x,y, False)
|
||||
plot(xf,yfp)
|
||||
27
script/jep/jepscript4.py
Executable file
27
script/jep/jepscript4.py
Executable file
@@ -0,0 +1,27 @@
|
||||
#from jeputils import *
|
||||
|
||||
eval_jep("import jepscript3")
|
||||
eval_jep("reload(jepscript3)")
|
||||
|
||||
|
||||
N = 600 # Number of sample points
|
||||
T = 1.0 / 800.0 # sample spacing
|
||||
F = [(1.0,50.0), (0.5,80.0)] #Sinuoisids
|
||||
(x,y) = call_jep("jepscript3", "get_f", [N,T,F])
|
||||
|
||||
|
||||
ret = call_jep("jepscript3", "get_fft2", [y,])
|
||||
print "---"
|
||||
print ret
|
||||
print "---"
|
||||
|
||||
"""
|
||||
ret = call_jep("jepscript3", "get_fft", [x,y,T])
|
||||
|
||||
|
||||
print ret
|
||||
(xf,yf,yfp) = ret
|
||||
|
||||
plot(y, xdata = x)
|
||||
plot(yfp, xdata = xf)
|
||||
"""
|
||||
27
script/jep/jeptest.py
Executable file
27
script/jep/jeptest.py
Executable file
@@ -0,0 +1,27 @@
|
||||
import jep.Jep as Jep
|
||||
|
||||
#if "j" in globals().keys():
|
||||
# j.close()
|
||||
|
||||
if not "j" in globals().keys():
|
||||
j = Jep(False)
|
||||
j.eval("from java.lang import System")
|
||||
j.eval("s = 'Hello World'")
|
||||
j.eval("System.out.println(s)")
|
||||
j.eval("print(s)")
|
||||
j.eval("print(s[1:-1])")
|
||||
|
||||
|
||||
|
||||
|
||||
j.eval("import numpy");
|
||||
j.eval("numpy.ones((1,2))")
|
||||
ret = j.getValue("_")
|
||||
|
||||
|
||||
|
||||
#j.close()
|
||||
#res= lscan(inp, sin, 0, 40, 10, 0.1)
|
||||
|
||||
|
||||
|
||||
12
script/jep/jeptest3.py
Executable file
12
script/jep/jeptest3.py
Executable file
@@ -0,0 +1,12 @@
|
||||
from jeputils import *
|
||||
import ch.psi.utils.Convert as Convert
|
||||
a = call_jep("numpy", "ones", [[400,200],'d'])
|
||||
|
||||
while(True):
|
||||
b = call_jep("numpy", "ones", [[400,200],'d'])
|
||||
a = call_jep("cpython", "add", [a,b])
|
||||
s = call_jep("cpython", "sum", [a,])
|
||||
print a.getData()[0], s
|
||||
sleep(0.01)
|
||||
|
||||
|
||||
19
script/jep/jeptest4.py
Executable file
19
script/jep/jeptest4.py
Executable file
@@ -0,0 +1,19 @@
|
||||
from jeputils import *
|
||||
|
||||
|
||||
import javax.swing.SwingUtilities as SwingUtilities
|
||||
import java.lang.Runnable as Runnable
|
||||
|
||||
#class MyRunnable (Runnable):
|
||||
# def run(self):
|
||||
# print "Starting"
|
||||
# run_jep("cpython6")
|
||||
# print "Started"
|
||||
#SwingUtilities.invokeLater(MyRunnable())
|
||||
|
||||
eval_jep("import matplotlib")
|
||||
eval_jep("matplotlib.use('TkAgg')")
|
||||
|
||||
#run_jep("cpython5")
|
||||
run_jep("cpython6")
|
||||
#exec_cpython("cpython6")
|
||||
Reference in New Issue
Block a user