if 0 <= args.res < 2:
    post_tag = ['_lowq.h5', '_medq.h5'][args.res]
    # Module order matches geometry file
    modules = [[3, 4, 8, 15], [2, 3, 4, 5, 9, 8, 15, 14],
               np.arange(16)][args.res]
    subset = [128, 256, 0][args.res]
    num_pix = [4 * 128 * 128, 4 * 256 * 256, 4 * 512 * 512][args.res]
else:
    print('"res" parameter can only have values 0, 1')
    sys.exit(1)

allqdet = detector.Detector(
    '/gpfs/exfel/exp/SPB/201901/p002316/scratch/benedikt/aux/det_allq.h5')
allqfile = os.path.join(args.path, 'r%04d.h5' % args.run)
print('Cropping the following files:', allqfile)
allq_emc = reademc.EMCReader(allqfile, allqdet)

det = detector.Detector(
    '/gpfs/exfel/exp/SPB/201901/p002316/scratch/benedikt/aux/det' + post_tag)
emcfile = os.path.join(args.path, post_tag[1:-3] + "/r%04d.h5" % (args.run))
print("Saving to new emc file: ", emcfile)
emc = writeemc.EMCWriter(emcfile, num_pix)

for i in range(allq_emc.num_frames):
    frame = allq_emc.get_frame(i, raw=True).reshape((16, 512, 128))
    emc.write_frame(frame[modules, -subset:].ravel().astype('i4'))
    sys.stderr.write('\r%d/%d' % (i + 1, allq_emc.num_frames))
sys.stderr.write('\n')
emc.finish_write()

print('copying ids/scores from: %s' % allqfile)
Beispiel #2
0
    type=str,
    help='Path to detector file',
    default=
    '/gpfs/exfel/exp/SPB/201802/p002145/scratch/benedikt/aux/det_lowq.h5')
parser.add_argument('-t',
                    '--threshold',
                    type=int,
                    help='hit selection threshold',
                    default=105)
args = parser.parse_args()

# Read all events
det = detector.Detector(args.detector)
allfile = os.path.join(args.path, 'r%04d.h5' % args.run)
print('Reading from file:', allfile)
allemc = reademc.EMCReader(allfile, det)

# Load cells and scores
with sparse.Run(allfile) as r:
    cells = r.cellIds
    score = r.litpixel
goodcells = np.ones(len(cells), dtype=np.bool)
goodcells[cells == 0] = False
if args.run <= 577:
    goodcells[cells >= 142] = False

# Save hits only
hitfile = os.path.join(args.output, "r%04d.h5" % (args.run))
print("Saving to new emc file: ", hitfile)
hitemc = writeemc.EMCWriter(hitfile, det.raw_mask.shape)
Beispiel #3
0
parser = argparse.ArgumentParser(description='Merge sparse file chunks into single file')
parser.add_argument('run', type=int, help='Run number')
parser.add_argument('-p', '--path', type=str, help='Path to chunked sparse files',
                    default='/gpfs/exfel/exp/SPB/201802/p002145/scratch/sparse/chunks')
parser.add_argument('-o', '--out_folder', help='Path to output folder',
                    default='/gpfs/exfel/exp/SPB/201802/p002145/scratch/sparse/')
parser.add_argument('-d', '--delete', action='store_false', default=True, 
                    help='Use this option for not deleting the chunks afterwards')
args = parser.parse_args()

# Merge sparse data
det = detector.Detector('/gpfs/exfel/exp/SPB/201802/p002160/scratch/ayyerkar/det/det_2160_allq2.h5')
chunked_flist = sorted(glob.glob(os.path.join(args.path, 'r%04d' %args.run, '*r%04d_*'%args.run)))
print('Merging %d chunked files' %len(chunked_flist))
chunked_emc = reademc.EMCReader(chunked_flist, det)
emcfile = os.path.join(args.out_folder, "r%04d.h5" %(args.run))
combined_emc = writeemc.EMCWriter(emcfile, det.raw_mask.shape)
for i in range(chunked_emc.num_frames):
    combined_emc.write_frame(chunked_emc.get_frame(i, raw=True))
    sys.stderr.write('\r%d/%d'%(i+1, chunked_emc.num_frames))
sys.stderr.write('\n')
nframes = chunked_emc.num_frames
combined_emc.finish_write()
print("Merged %d frames into %s" %(nframes, emcfile))

# Merge train, cell, pulse id
train_ids, cell_ids, pulse_ids = [], [], []
for filename in sorted(chunked_flist):
    with h5py.File(filename, 'r') as f:
        train_ids = np.hstack([train_ids, f['id/trains'][:]])