def img_iter(node_range, ptn_range, ts0, ts1, exp_count_per_pixel, exp_pixel): if ts0: ts0 = str(ts0) else: ts0 = None if ts1: ts1 = str(ts1) else: ts1 = None print "Checking IMG iter | node_range: '%s', ptn_range: '%s', " \ "ts0: '%s', ts1: '%s'" % (node_range, ptn_range, ts0, ts1) biq = bquery.bimgquery_create(bstore, node_range, ptn_range, ts0, ts1, "3600-1", None) assert biq n = 0 rc = bquery.biq_first_entry(biq) pixels = [] while rc == 0 and n < 10: p = bquery.biq_entry_get_pixel(biq) pixels.append(p) rc = bquery.biq_next_entry(biq) while n: rc = bquery.biq_prev_entry(biq) assert (rc == 0) p = bquery.biq_entry_get_pixel(biq) _p = pixels.pop() assert (p == _p) n = n - 1
def img_query(node_range, ptn_range, ts0, ts1, exp_count_per_pixel, exp_pixel): if ts0: ts0 = str(ts0) else: ts0 = None if ts1: ts1 = str(ts1) else: ts1 = None print "Checking IMG query | node_range: '%s', ptn_range: '%s', " \ "ts0: '%s', ts1: '%s'" % (node_range, ptn_range, ts0, ts1) biq = bquery.bimgquery_create(bstore, node_range, ptn_range, ts0, ts1, "3600-1", None) assert biq biq_count = 0 rc = bquery.biq_first_entry(biq) while rc == 0: biq_count = biq_count + 1 p = bquery.biq_entry_get_pixel(biq) if p.count != exp_count_per_pixel: print "<ptn_id: %d, sec: %d, comp_id: %d, count: %d>: " \ "count in correct (expecting %d)" % \ (p.ptn_id, p.sec, p.comp_id, p.count, exp_count_per_pixel) exit(-1) rc = bquery.biq_next_entry(biq) if (exp_pixel != biq_count): print "Expecting %d pixels, but got: %d pixels" % (exp_pixel, biq_count) exit(-1)
def get_img2(self, img_store, ts_begin, host_begin, spp, npp, width, height, ptn_ids=None): """ Prepare image2 data for to be fetched by `fetch_img2()`. NOTE0: if `ts_begin` is not aligned with `spp`, it will automatically be aligned in this function. NOTE1: if `host_begin` is not aligned with `npp`, it will automatically be aligned in this function. """ if type(npp) != int: raise TypeError("npp must be an `int`") if type(spp) != int: raise TypeError("spp must be an `int`") # this creates 1-D array like `int pxls[height*width]` in C self._pxls = [0]*(width*height) self._idx = 0 ts0 = align(ts_begin, spp) ts1 = ts0 + width*spp - 1 h0 = align(host_begin, npp) h1 = h0 + height*npp - 1 q = bquery.bimgquery_create( self.bstore, "%d-%d" % (h0, h1), list2csv(ptn_ids), strnone(ts0), strnone(ts1), img_store, None ) rc = bquery.biq_first_entry(q) while rc == 0: p = bquery.biq_entry_get_pixel(q) xidx = int((p.sec - ts0) / spp) yidx = int((p.comp_id - h0) / npp) try: self._pxls[yidx*width + xidx] += p.count except Exception as e: logger.warn("len: %d", len(self._pxls)) logger.warn("yidx: %d", yidx) logger.warn("xidx: %d", xidx) logger.warn("idx: %d", yidx*width+xidx) logger.warn("ts0: %d", ts0) logger.warn("ts1: %d", ts1) logger.warn("sec: %d", p.sec) logger.warn("h0: %d", h0) logger.warn("h1: %d", h1) logger.warn("comp_id: %d", p.comp_id) logger.warn("spp: %d", spp) logger.warn("npp: %d", npp) logger.warn("width: %d", width) logger.warn("height: %d", height) raise rc = bquery.biq_next_entry(q) pass
def fetch_img(self, n=None): if not self.imgq: raise Exception("no imgq: get_img() error or not called") pxls = [] i = 0 # self.imgq set to first entry in self.get_img() while (self.imgq_rc == 0): if n and i>=n: break p = bquery.biq_entry_get_pixel(self.imgq) pxl = Pixel(p.sec, p.comp_id, p.ptn_id, p.count) pxls.append(pxl) i = i + 1 self.imgq_rc = bquery.biq_next_entry(self.imgq) return pxls