def projectImageToSH(image) : """ Maps an array representing samples of a function defined in the surface of an sphere into spherical harmonics of the specified representation and order. Points are sampled at equal angular intervals for azimuth and elevation. (plate-carree projection). """ h,w = image.shape elevations, azimuths, sh = shGrid(h,w) cosines = np.cos(np.radians(elevations)).reshape(-1,1,1,1) sh = sh * cosines return image.reshape(w*h).dot(sh.reshape(w*h,-1)).reshape(sh.shape[2:])
def reloadData(self) : nelevations = self._parallelsSpin.value() nazimuths = self._meridiansSpin.value() if self.shProjections.shape[:2] != (nelevations, nazimuths) : print "Reshaping %ix%x..."%(nelevations, nazimuths) self.elevations, self.azimuths, self.shProjections = shGrid(nelevations, nazimuths) self.shProjections *= orthonormalization print "Reshape outputs..." self.sphericalPoints = np.array([ [self.elevations[ei], self.azimuths[ai], 0 ] for ei in xrange(nelevations) for ai in xrange(nazimuths) ]) self.indexes = np.array( [[ [i+nazimuths*j,i+nazimuths*(j+1)] for i in xrange(nazimuths) ] for j in xrange(nelevations-1) ] ).flatten() # taking coeficients from the knobs shMatrix = self.sphericalHarmonicsMatrix() self.data = self.shProjections.reshape(nazimuths*nelevations, shMatrix.size).dot( shMatrix.reshape(shMatrix.size ) ).reshape(self.shProjections.shape[:2]) self.sphericalPoints[:,2] = (5*self.data).reshape(nelevations*nazimuths) self.blobView.setEadPoints(self.sphericalPoints) xyzs = np.array([ead2xyz(e,a,abs(d)) for e,a,d in self.sphericalPoints]) self.blobView.scene()._vertices = xyzs self.blobView.scene()._normals = xyzs self.blobView.scene()._meshColors = np.array([ [1.,.0,.0, .6] if d<0 else [0.,0.,1., .9] for e,a,d in self.sphericalPoints]) self.blobView.scene()._indexes = self.indexes self.blobView.update() maxValue = abs(self.data).max() if maxValue > 1 : self.data /= maxValue self.synthetizedFunction.format(nazimuths, nelevations, ColorField.signedScale) self.synthetizedFunction.data()[:] = self.data/(2/255.)+127 self.synthetizedFunction.reload()