예제 #1
0
def run(logger, args, extra_argv=None):
    try:
        os.makedirs(args.out_dir)
    except OSError as e:
        if e.errno != errno.EEXIST:
            sys.exit('Cannot create output dir: %s' % e)
    tag, ext = os.path.splitext(os.path.basename(args.in_fn))
    out_fn = os.path.join(args.out_dir, '%s_features%s' % (tag, ext))
    logger.info('writing to %s', out_fn)
    with open(out_fn, 'w') as fout:
        writer = AvroFileWriter(fout, out_schema)
        with open(args.in_fn) as fin:
            reader = AvroFileReader(fin)
            for r in reader:
                p = BioImgPlane(r)
                pixels = p.get_xy()
                logger.info('processing %r', [p.z, p.c, p.t])
                kw = {
                    'long': args.long,
                    'w': args.width,
                    'h': args.height,
                    'dx': args.delta_x,
                    'dy': args.delta_y,
                    'ox': args.offset_x,
                    'oy': args.offset_y,
                }
                for fv in calc_features(pixels, p.name, **kw):
                    out_rec = to_avro(fv)
                    for name in 'img_path', 'series', 'z', 'c', 't':
                        out_rec[name] = getattr(p, name)
                    writer.write(out_rec)
        writer.close()
    return 0
예제 #2
0
 def map(self, ctx):
     p = BioImgPlane(ctx.value)
     pixels = p.get_xy()
     # TODO: support tiling
     out_rec = to_avro(calc_features(pixels, p.name))
     for name in 'img_path', 'series', 'z', 'c', 't':
         out_rec[name] = getattr(p, name)
     ctx.emit(None, out_rec)
예제 #3
0
 def map(self, ctx):
     p = BioImgPlane(ctx.value)
     pixels = p.get_xy()
     bn = '%s-z%04d-c%04d-t%04d.npy' % (p.name, p.z, p.c, p.t)
     fn = hdfs.path.join(self.out_dir, p.name, bn)
     with hdfs.open(fn, 'w') as fo:
         np.save(fo, pixels)
     ctx.emit(fn, '%s\t%s' % (p.dimension_order, pixels.shape))
예제 #4
0
 def map(self, ctx):
     p = BioImgPlane(ctx.value)
     pixels = p.get_xy()
     bn = '%s-z%04d-c%04d-t%04d.npy' % (p.name, p.z, p.c, p.t)
     fn = hdfs.path.join(self.out_dir, p.name, bn)
     with hdfs.open(fn, 'w') as fo:
         np.save(fo, pixels)
     ctx.emit(fn, '%s\t%s' % (p.dimension_order, pixels.shape))
예제 #5
0
 def map(self, ctx):
     p = BioImgPlane(ctx.value)
     pixels = p.get_xy()
     # TODO: support tiling
     out_rec = to_avro(calc_features(pixels, p.name))
     for name in 'img_path', 'series', 'z', 'c', 't':
         out_rec[name] = getattr(p, name)
     ctx.emit(None, out_rec)
예제 #6
0
파일: calc.py 프로젝트: IDR/pydoop-features
def run(logger, args, extra_argv=None):
    try:
        os.makedirs(args.out_dir)
    except OSError as e:
        if e.errno != errno.EEXIST:
            sys.exit('Cannot create output dir: %s' % e)
    tag, ext = os.path.splitext(os.path.basename(args.in_fn))
    out_fn = os.path.join(args.out_dir, '%s_features%s' % (tag, ext))
    logger.info('writing to %s', out_fn)
    zsubset, csubset, tsubset = get_subsets(args)
    with open(out_fn, 'w') as fout:
        writer = AvroFileWriter(fout, out_schema)
        with open(args.in_fn) as fin:
            reader = AvroFileReader(fin)
            for r in reader:
                p = BioImgPlane(r)
                if zsubset and p.z not in zsubset:
                    continue
                if csubset and p.c not in csubset:
                    continue
                if tsubset and p.t not in tsubset:
                    continue
                pixels = p.get_xy()
                logger.info('processing %r', [p.z, p.c, p.t])
                kw = {
                    'long': args.long,
                    'w': args.width,
                    'h': args.height,
                    'dx': args.delta_x,
                    'dy': args.delta_y,
                    'ox': args.offset_x,
                    'oy': args.offset_y,
                }
                for fv in calc_features(pixels, p.name, **kw):
                    out_rec = to_avro(fv)
                    for name in 'img_path', 'series', 'z', 'c', 't':
                        out_rec[name] = getattr(p, name)
                    writer.write(out_rec)
        writer.close()
    return 0
 def map(self, ctx):
     p = BioImgPlane(ctx.value)
     if len(self.img_set) >= SET_SIZE:
         self.__process_current_set(ctx)
         self.img_set = []
     self.img_set.append(p)
예제 #8
0
def iterplanes(avro_file):
    with open(avro_file, 'rb') as f:
        reader = AvroFileReader(f)
        for r in reader:
            yield BioImgPlane(r)