def work(i): setupsml(tree, [x[i:i+chunksize] for x in pos], out=sml[i:i+chunksize])
def paint(self, ftype, color, luminosity, sml=None, camera=None, kernel=None, preserve=False, np=None, debug=False): """ paint field to CCD, returns C, L where C is the color of the pixel L is the exposure of the pixel Notice that if color is None, C will be undefined, L will still be the exposure. the return values can be normalized by nl_ or n_, then feed to imshow if preserve is True, do not clean the CCD and return None """ if np is None: np = self.np CCD = self.CCD if not preserve: CCD[...] = 0 if isinstance(ftype, Field): tree = None else: tree = self.T[ftype] if kernel is None: kernel='spline' locations, color, luminosity, sml = self._getcomponent(ftype, 'locations', color, luminosity, sml) x, y, z = locations.T if sml is None: #warnings.warn('sml is None and the on-the-fly calculation is buggy, will run field.smooth first, sml is overwritten') sml = numpy.empty_like(luminosity, dtype='f4') setupsml(tree, (x, y, z), out=sml) # self[ftype].smooth(tree) self[ftype]['sml'] = sml if 'densitykerneltype' in self.C: support = [2. , 3., 2.5] sml = sml * (2 / support[self.C['densitykerneltype']]) with sharedmem.MapReduce(np=np) as pool: for cam in self._mkcameras(camera): cams = cam.divide(int(pool.np ** 0.5 * 2 + 1), int(pool.np ** 0.5 * 2 + 1)) cams = cams.reshape(-1, 3) def work(i): cam, offx, offy = cams[i] smallCCD = numpy.zeros(cam.shape, dtype=('f8', 2)) cam.paint(x,y,z,sml,color,luminosity, kernel=kernel, out=smallCCD, tree=tree) # no race condition here. cameras are independent. if debug: smallCCD[0, :, :]= -1.0 smallCCD[:, 0, :]= -1.0 return i, smallCCD def reduce(i, smallCCD): cam, offx, offy = cams[i] CCD[offx:offx + cam.shape[0], offy:offy+cam.shape[1], :] += smallCCD pool.map(work, range(len(cams)), reduce=reduce) if not preserve: C, L = CCD[...,0], CCD[...,1] C = C / L return C, L else: return None
def paint(self, ftype, color, luminosity, sml=None, camera=None, kernel=None, preserve=False, np=None, debug=False): """ paint field to CCD, returns C, L where C is the color of the pixel L is the exposure of the pixel Notice that if color is None, C will be undefined, L will still be the exposure. the return values can be normalized by nl_ or n_, then feed to imshow if preserve is True, do not clean the CCD and return None """ if np is None: np = self.np CCD = self.CCD if not preserve: CCD[...] = 0 if isinstance(ftype, Field): tree = None else: tree = self.T[ftype] if kernel is None: kernel = 'spline' locations, color, luminosity, sml = self._getcomponent( ftype, 'locations', color, luminosity, sml) x, y, z = locations.T if sml is None: #warnings.warn('sml is None and the on-the-fly calculation is buggy, will run field.smooth first, sml is overwritten') sml = numpy.empty_like(luminosity, dtype='f4') setupsml(tree, (x, y, z), out=sml) # self[ftype].smooth(tree) self[ftype]['sml'] = sml if 'densitykerneltype' in self.C: support = [2., 3., 2.5] sml = sml * (2 / support[self.C['densitykerneltype']]) with sharedmem.MapReduce(np=np) as pool: for cam in self._mkcameras(camera): cams = cam.divide(int(pool.np**0.5 * 2 + 1), int(pool.np**0.5 * 2 + 1)) cams = cams.reshape(-1, 3) def work(i): cam, offx, offy = cams[i] smallCCD = numpy.zeros(cam.shape, dtype=('f8', 2)) cam.paint(x, y, z, sml, color, luminosity, kernel=kernel, out=smallCCD, tree=tree) # no race condition here. cameras are independent. if debug: smallCCD[0, :, :] = -1.0 smallCCD[:, 0, :] = -1.0 return i, smallCCD def reduce(i, smallCCD): cam, offx, offy = cams[i] CCD[offx:offx + cam.shape[0], offy:offy + cam.shape[1], :] += smallCCD pool.map(work, range(len(cams)), reduce=reduce) if not preserve: C, L = CCD[..., 0], CCD[..., 1] C = C / L return C, L else: return None
def work(i): setupsml(tree, [x[i:i + chunksize] for x in pos], out=sml[i:i + chunksize])