def sin(self,param,x,y=None): """ Y0 is an Y Offset A is the amplitude of the wave phi is the phase/shift """ p=[] for i in list(param): p.append(param[i].value) p=p[:4] Y0, A, f, phi = p if y is None: return (Y0 + A*numpy.sin((f*x)+phi)) return (Y0 + A*numpy.sin((f*x)+phi)) - y
def sin(self, param, x, y=None): """ Y0 is an Y Offset A is the amplitude of the wave phi is the phase/shift """ p = [] for i in list(param): p.append(param[i].value) p = p[:4] Y0, A, f, phi = p if y is None: return (Y0 + A * numpy.sin((f * x) + phi)) return (Y0 + A * numpy.sin((f * x) + phi)) - y
def render(): x = np.arange(0, np.pi * 3, .1) y = np.sin(x) fig = plt.figure() plt.plot(x, y) fig.show() svg_io = StringIO.StringIO() fig.savefig(svg_io, format='svg') svg_io.seek(0) # rewind the data return send_file(svg_io, mimetype='image/svg+xml')
def image_response(input): import matplotlib import matplotlib.pyplot as plt import io from matplotlib import numpy as np x = np.arange(0, np.pi * 3, .1) y = np.sin(x) fig = plt.figure() plt.plot(x, y) imgdata = io.StringIO() fig.savefig(imgdata, format='svg') return imgdata.getvalue()
def image_response(input): import matplotlib import matplotlib.pyplot as plt import io from matplotlib import numpy as np x = np.arange(0,np.pi*3,.1) y = np.sin(x) fig = plt.figure() plt.plot(x,y) imgdata = io.StringIO() fig.savefig(imgdata, format='svg') return imgdata.getvalue()
def image_response(input): import matplotlib import matplotlib.pyplot as plt import io from matplotlib import numpy as np import base64 x = np.arange(0,np.pi*3,.1) y = np.sin(x) fig = plt.figure() plt.plot(x,y) imgdata = io.StringIO() fig.savefig(imgdata, format='svg') return """<img src='data:image/svg+xml;charset=utf-8,%s'>""" % imgdata.getvalue()
def image_response(input): import matplotlib import matplotlib.pyplot as plt import io from matplotlib import numpy as np import base64 x = np.arange(0, np.pi * 3, .1) y = np.sin(x) fig = plt.figure() plt.plot(x, y) imgdata = io.StringIO() fig.savefig(imgdata, format='svg') return """<img src='data:image/svg+xml;charset=utf-8,%s'>""" % imgdata.getvalue( )
def fft2(image, invert=False): """ Perform a two-dimensional fft in an iterative way :param image: np array :param invert: true if ifft :return: processed image as np array """ shape = image.shape im = np.full(image.size, complex(0)) for i, each in enumerate(image.reshape(-1)): im[i] = complex(each) length = len(im) lg_n = 0 t = 1 << lg_n while t < length: lg_n += 1 t = 1 << lg_n for i in range(length): if i < rev(i, lg_n): ind = rev(i, lg_n) im[i], im[ind] = im[ind], im[i] ln = 2 while ln <= length: angle = 2 * np.pi * (-1 if invert else 1) wlen = np.complex(np.cos(angle), np.sin(angle)) for i in range(0, length, ln): w = np.complex(1) for j in range(ln // 2): v = np.real(im[i + j + ln // 2] * w) u = np.complex(np.real(im[i + j]), v) im[i + j] = np.real(u + v) im[i + j + ln // 2] = np.real(u - v) w *= wlen ln <<= 1 if invert: for i in range(length): im[i] /= length return im.reshape(shape)
def rotate_coords(self, x, y, theta, ox, oy): s, c = np.sin(theta), np.cos(theta) x, y = np.asarray(x) - ox, np.asarray(y) - oy return x * c - y * s + ox, x * s + y * c + oy
from matplotlib import numpy as np from matplotlib import pyplot as plt import scipy.optimize as opt def twoD_Gaussian((x, y), amplitude, xo, yo, sigma_x, sigma_y, theta, offset): xo = float(xo) yo = float(yo) a = (np.cos(theta)**2)/(2*sigma_x**2) + (np.sin(theta)**2)/(2*sigma_y**2) b = -(np.sin(2*theta))/(4*sigma_x**2) + (np.sin(2*theta))/(4*sigma_y**2) c = (np.sin(theta)**2)/(2*sigma_x**2) + (np.cos(theta)**2)/(2*sigma_y**2) g = offset + amplitude*np.exp( - (a*((x-xo)**2) + 2*b*(x-xo)*(y-yo) + c*((y-yo)**2))) return g.ravel() # Create x and y indices x = np.linspace(0, 200, 201) y = np.linspace(0, 200, 201) x, y = np.meshgrid(x, y) #create data data = twoD_Gaussian((x, y), 3, 100, 100, 20, 40, 0, 10) # plot twoD_Gaussian data generated above plt.figure() plt.imshow(data.reshape(201, 201)) plt.colorbar() # add some noise to the data and try to fit the data generated beforehand initial_guess = (3,100,100,20,40,0,10) data_noisy = data + 0.2*np.random.normal(size=data.shape)