def coordinateGrid_sanity(self): x = np.arange(5) y = np.arange(10) + 10. z = np.arange(2) + 100. g = fuf.coordinateGrid(x, y, z) self.assertEqual(g[0, 0, 0, 0], 0.0) self.assertEqual(g[0, 0, 0, 1], 10.0) self.assertEqual(g[0, 0, 0, 2], 100.0) self.assertEqual(g[1, 0, 1, 0], 1.0) self.assertEqual(g[1, 2, 1, 1], 12.0) self.assertEqual(g[1, 2, 1, 2], 101.0)
def coordinateGrid_sanity(self): x = np.arange(5) y = np.arange(10) + 10. z = np.arange(2) + 100. g = fuf.coordinateGrid(x, y, z) self.assertEqual(g[0,0,0,0], 0.0) self.assertEqual(g[0,0,0,1], 10.0) self.assertEqual(g[0,0,0,2], 100.0) self.assertEqual(g[1,0,1,0], 1.0) self.assertEqual(g[1,2,1,1], 12.0) self.assertEqual(g[1,2,1,2], 101.0)
def sanity_coordinateGridExample(self): from PyAstronomy import funcFit as fuf import numpy as np # Constructing the two individual coordinate axes x = np.linspace(-2.,2.,50) y = np.linspace(-2.,2.,50) # Applying funcFit's "coordinateGrid" helper function # to built appropriate array-index -> coordinate mapping # needed for nD fitting. g = fuf.coordinateGrid(x, y) print "(x, y) coordinates at index (11, 28): ", g[11,28]
def sanity_2dGaussFit(self): from PyAstronomy import funcFit as fuf import numpy as np import matplotlib.pylab as plt # Constructing the individual coordinate axes x = np.linspace(-2.,2.,50) y = np.linspace(-2.,2.,50) # Applying funcFit's "coordinateGrid" helper function # to built appropriate array-index -> coordinate mapping # needed for nD fitting. g = fuf.coordinateGrid(x, y) # Create the 2d-Gaussian model and assign # some model parameters. gf = fuf.GaussFit2d() gf["sigx"] = 0.75 gf["sigy"] = 0.4 gf["A"] = 1.0 gf["rho"] = 0.4 # Get the "data" by evaluating the model # and adding some noise. Note that the coordinate # mapping (array g) is passed to evaluate here. im = gf.evaluate(g) im += np.reshape(np.random.normal(0.0, 0.1, 2500), (50,50)) err = np.ones((50,50))*0.1 # Thaw parameters and fit gf.thaw(["A", "rho"]) gf.fit(g, im, yerr=err) # Show the resulting parameter values ... gf.parameterSummary() # ... and plot the result. plt.title("Image data") plt.imshow(np.transpose(im), origin="lower") # plt.show() plt.title("Residuals") plt.imshow(np.transpose(im - gf.evaluate(g)), origin="lower")