Ejemplo n.º 1
0
    if args.list:
        logging.info('Reading file names in list %s' % args.condor_fname)
        with open(args.condor_fname, 'r') as f:
            flist = [fname.rstrip() for fname in f.readlines()]
        logging.info
    else:
        flist = [args.condor_fname]

    # Read meta information from condor CXI file
    with h5py.File(flist[0], 'r') as f:
        wavelength = f['source/wavelength'][...]
        nx = f['detector/nx'][0]
        ny = f['detector/ny'][0]
        
    emcwriter = writeemc.EMC_writer('%s/%s.emc' % (output_folder, os.path.splitext(os.path.basename(args.condor_fname))[0]), nx*ny)

    for fname in flist:
        f = h5py.File(fname, 'r')
        dset = f['entry_1/data_1/data']
        mask = f['entry_1/data_1/mask']
        num_frames = dset.shape[0]
        if not args.list:
            logging.info('Converting %d frames in %s' % (num_frames, args.condor_fname))

        for i in range(num_frames):
            photons = dset[i] * (~(mask[i]==512))
            photons[photons<0] = 0
            emcwriter.write_frame(photons.flatten())
            if not args.list:
                sys.stderr.write('\rFinished %d/%d' % (i+1, num_frames))
Ejemplo n.º 2
0
        logging.error('Data file %s not found. Exiting.' % args.h5_name)
        sys.exit()

    if args.list:
        logging.info('Reading file names in list %s' % args.h5_name)
        with open(args.h5_name, 'r') as f:
            flist = [
                os.path.realpath(fname.rstrip()) for fname in f.readlines()
            ]
        logging.info
    else:
        flist = [args.h5_name]

    if args.out_fname is None:
        emcwriter = writeemc.EMC_writer(
            '%s/%s.emc' %
            (output_folder, os.path.splitext(os.path.basename(
                args.h5_name))[0]), pm['dets_x'] * pm['dets_y'])
    else:
        emcwriter = writeemc.EMC_writer(args.out_fname,
                                        pm['dets_x'] * pm['dets_y'])

    for fnum, fname in enumerate(flist):
        f = h5py.File(fname, 'r')
        dset = get_dset(f, args)
        if dset is None:
            continue

        ind, num_frames = get_indices(f, dset, args)

        curr_num_data += num_frames
        if not args.list:
Ejemplo n.º 3
0
    out = array.reshape(s[0] / bs, bs, s[1] / bs, bs).sum(axis=(1, 3))
    return out


tag = ''
if len(sys.argv) > 2:
    binsize = int(sys.argv[2])
    tag = '_%d' % binsize

num_pix = (1700 / binsize)**2
print num_pix, 'pixels in detector'

flist = np.loadtxt(sys.argv[1], dtype='S')
print len(flist), 'files in list'
emcwriter = writeemc.EMC_writer(
    ['temp.po', 'temp.pm', 'temp.cm'], 'data/%s%s.emc' %
    (os.path.splitext(os.path.basename(sys.argv[1]))[0], tag), num_pix)

i = 1
for fname in flist:
    f = h5py.File(fname, 'r')
    pattern = (f['data/data'][:] * 1.e-8).astype('i4')
    #pattern = f['data/data'][:].astype('i4')
    pattern = binimg(pattern, binsize)
    #pattern[pattern > 1] = 1
    f.close()

    emcwriter.write_frame(pattern.flatten())
    sys.stderr.write('\rFinished %d/%d' % (i, len(flist)))
    i += 1
Ejemplo n.º 4
0
        sys.exit()

    f = h5py.File(args.h5_name, 'r')
    if args.dset_name is None:
        for name, obj in f['photonConverter'].items():
            try:
                temp = obj.keys()
                dset = obj['photonCount']
                break
            except AttributeError:
                pass
        logging.info('Converting data in '+ dset.name)
    else:
        dset = f[args.dset_name]
        logging.info('Converting data in '+ args.dset_name)
    frames = dset[:]
    ind = range(len(frames))
    num_frames = len(ind)
    logging.info('%d frames in %s' % (num_frames, args.h5_name))

    emcwriter = writeemc.EMC_writer('data/%s.emc' % os.path.splitext(os.path.basename(sys.argv[1]))[0],
                                    pm['dets_x']*pm['dets_y'])

    for i in range(num_frames):
        emcwriter.write_frame(frames[i].flatten().astype('i4'))
        sys.stderr.write('\rFinished %d/%d' % (i+1, num_frames))

    f.close()
    sys.stderr.write('\n')
    emcwriter.finish_write()
Ejemplo n.º 5
0
print ind.shape, 'single hits'

if len(sys.argv) > 3:
    binsize = int(sys.argv[3])
    tag += '_%d' % binsize

f = h5py.File(sys.argv[1], 'r')
num_frames = f['dataPhotons/back/index'].shape[0]
print num_frames, "frames in h5 file"
index = f['dataPhotons/back/index']
count = f['dataPhotons/back/photonCount']
ix = f['dataPhotons/back/iX'][:].flatten()
iy = f['dataPhotons/back/iY'][:].flatten()

emcwriter = writeemc.EMC_writer(
    'data/%s_%s.emc' %
    (os.path.splitext(os.path.basename(sys.argv[1]))[0], tag),
    1028 * 1040 / binsize / binsize)

j = 0
for i in ind:
    pattern = np.zeros((1028, 1040), dtype='i4')
    place = index[i]
    pattern[iy[place], ix[place]] = count[i]
    if binsize > 1:
        pattern = binimg(pattern, binsize)

    emcwriter.write_frame(pattern.flatten())
    sys.stderr.write('\rFinished %d/%d' % (j + 1, len(ind)))
    j += 1

f.close()