def _id_from_xyti(self, x, y, t=None, i=0): """ Returns the pixel ID, given x, y, t and object index i. If i == 0xFFFFFFFF, we return the corresponding cell ID. """ if t is None: t = np.array(self.t0) ct = np.array((t - self.t0) / self.dt, np.uint64) # # Round to closest pixel # # TODO: This shouldn't strictly be necessary # (x, y) = bhpix.xy_center(x, y, self.xybits) # construct the 32bit ID prefix from the above # Prefix format: 10bit x + 10bit y + 12bit time npixhalf = 2**(self.xybits - 1) ix = np.array((1 + x) * npixhalf) iy = np.array((1 + y) * npixhalf) ix = ix.astype(np.uint64) iy = iy.astype(np.uint64) id = ix << (self.tbits + self.xybits) id |= iy << (self.tbits) id |= ct & ((u1 << self.tbits) - u1) id <<= u32 id |= np.uint64(i) & u0xFFFFFFFF if np.any(i == u0xFFFFFFFF): # If we're computing cell IDs, make sure to wipe out the # sub-pixel bits for the given level (otherwise we'd get # multiple cell_ids for the same cell, depending on where # in the cell the x,y were) id &= self.id2cell_mask # TODO: Transformation verification, remove when debugged if False: if np.any(i == u0xFFFFFFFF): ux, uy, ut = self._xyt_from_cell_id(id) ui = u0xFFFFFFFF (cx, cy) = bhpix.xy_center(x, y, self.level) else: ux, uy, ut, ui = self._xyti_from_id(id) (cx, cy) = bhpix.xy_center(x, y, self.xybits) ct = ct * self.dt + self.t0 ci = i if np.any(cx != ux) or np.any(cy != uy) or np.any( ct != ut) or np.any(ci != ui): print cc, "==", cu, ct, "==", ut raise Exception("**** Bug detected ****") return id
def _id_from_xyti(self, x, y, t=None, i = 0): """ Returns the pixel ID, given x, y, t and object index i. If i == 0xFFFFFFFF, we return the corresponding cell ID. """ if t is None: t = np.array(self.t0) ct = np.array((t - self.t0) / self.dt, np.uint64) # # Round to closest pixel # # TODO: This shouldn't strictly be necessary # (x, y) = bhpix.xy_center(x, y, self.xybits) # construct the 32bit ID prefix from the above # Prefix format: 10bit x + 10bit y + 12bit time npixhalf = 2**(self.xybits-1) ix = np.array((1 + x) * npixhalf) iy = np.array((1 + y) * npixhalf) ix = ix.astype(np.uint64) iy = iy.astype(np.uint64) id = ix << (self.tbits + self.xybits) id |= iy << (self.tbits) id |= ct & ((u1<<self.tbits) - u1) id <<= u32 id |= np.uint64(i) & u0xFFFFFFFF if np.any(i == u0xFFFFFFFF): # If we're computing cell IDs, make sure to wipe out the # sub-pixel bits for the given level (otherwise we'd get # multiple cell_ids for the same cell, depending on where # in the cell the x,y were) id &= self.id2cell_mask # TODO: Transformation verification, remove when debugged if False: if np.any(i == u0xFFFFFFFF): ux, uy, ut = self._xyt_from_cell_id(id) ui = u0xFFFFFFFF (cx, cy) = bhpix.xy_center(x, y, self.level) else: ux, uy, ut, ui = self._xyti_from_id(id) (cx, cy) = bhpix.xy_center(x, y, self.xybits) ct = ct * self.dt + self.t0 ci = i if np.any(cx != ux) or np.any(cy != uy) or np.any(ct != ut) or np.any(ci != ui): print cc, "==", cu, ct, "==", ut raise Exception("**** Bug detected ****") return id
def _path_to_cell_base_xy(self, x, y, level = None): # The only place in the code where we map from # (x, y) to cell base path if level is None: level = bhpix.get_pixel_level(x, y) path = []; for lev in xrange(1, level+1): (cx, cy) = bhpix.xy_center(x, y, lev) subpath = "%+g%+g" % (cx, cy) path.append(subpath) return '/'.join(path)
def _path_to_cell_base_xy(self, x, y, level=None): # The only place in the code where we map from # (x, y) to cell base path if level is None: level = bhpix.get_pixel_level(x, y) path = [] for lev in xrange(1, level + 1): (cx, cy) = bhpix.xy_center(x, y, lev) subpath = "%+g%+g" % (cx, cy) path.append(subpath) return '/'.join(path)
def _xyti_from_id(self, id): # Unpack x, y, t, i from ID. If i == 0, assume this # is a cell_id (and not object ID), and round the # x, y to our pixelization level. id = np.array(id, np.uint64) ci = id & u0xFFFFFFFF id >>= u32 ix = (id & self.mask_x32) >> (self.xybits + self.tbits) iy = (id & self.mask_y32) >> (self.tbits) it = (id & self.mask_t32) npixhalf = 2.**(self.xybits-1) cx = (ix + 0.5) / npixhalf - 1. cy = (iy + 0.5) / npixhalf - 1. ct = np.array(it, float) * self.dt + self.t0 # Special handling for cell IDs cellids = ci == u0xFFFFFFFF if np.any(cellids): assert np.all(cellids) (cx, cy) = bhpix.xy_center(cx, cy, self.level) return (cx, cy, ct, ci)
def _xyti_from_id(self, id): # Unpack x, y, t, i from ID. If i == 0, assume this # is a cell_id (and not object ID), and round the # x, y to our pixelization level. id = np.array(id, np.uint64) ci = id & u0xFFFFFFFF id >>= u32 ix = (id & self.mask_x32) >> (self.xybits + self.tbits) iy = (id & self.mask_y32) >> (self.tbits) it = (id & self.mask_t32) npixhalf = 2.**(self.xybits - 1) cx = (ix + 0.5) / npixhalf - 1. cy = (iy + 0.5) / npixhalf - 1. ct = np.array(it, float) * self.dt + self.t0 # Special handling for cell IDs cellids = ci == u0xFFFFFFFF if np.any(cellids): assert np.all(cellids) (cx, cy) = bhpix.xy_center(cx, cy, self.level) return (cx, cy, ct, ci)