@@ -0,0 +1,1893 @@
+import h5py%0Aimport bitshuffle.h5%0Afrom yamtbx.dataproc import cbf%0Afrom yamtbx.dataproc import eiger%0Aimport numpy%0Aimport os%0A%0Adef run(infile):%0A    h5 = h5py.File(infile, %22r%22)%0A%0A    if h5%5B%22/entry/instrument/detector/flatfield_correction_applied%22%5D.value:%0A        print %22Correction was already applied.%22%0A        return %0A%0A    ff = h5%5B%22/entry/instrument/detector/detectorSpecific/flatfield%22%5D%5B:%5D%0A%0A    outdir = %22flatfield_applied_%25s%22 %25 os.path.splitext(os.path.basename(infile))%5B0%5D%0A    if not os.path.exists(outdir): os.mkdir(outdir)%0A%0A    cbf.save_numpy_data_as_cbf((ff*1000).astype(numpy.uint32).flatten(), size1=ff.shape%5B1%5D, size2=ff.shape%5B0%5D, title=%22flatfield_x1000%22,%0A                               cbfout=os.path.join(outdir, %22flatfield.cbf%22))%0A%0A    for k in sorted(h5%5B%22/entry/data%22%5D.keys()):%0A        outfile = os.path.join(outdir, h5%5B%22/entry/data%22%5D.get(k, getlink=True).filename)%0A        ds = h5%5B%22/entry/data%22%5D%5Bk%5D%0A        %0A        h5o = h5py.File(outfile, %22w%22)%0A        h5o.create_group(%22/entry%22)%0A        h5o%5B%22/entry%22%5D.attrs%5B%22NX_class%22%5D = %22NXentry%22%0A        h5o.create_group(%22/entry/data%22)%0A        h5o%5B%22/entry/data%22%5D.attrs%5B%22NX_class%22%5D = %22NXdata%22%0A        dataset = h5o.create_dataset(%22/entry/data/data%22, ds.shape,%0A                                       compression=bitshuffle.h5.H5FILTER,%0A                                       compression_opts=(0, bitshuffle.h5.H5_COMPRESS_LZ4),%0A                                       chunks=ds.chunks, dtype=ds.dtype)%0A        dataset.attrs%5B%22image_nr_low%22%5D = ds.attrs%5B%22image_nr_low%22%5D%0A        dataset.attrs%5B%22image_nr_high%22%5D = ds.attrs%5B%22image_nr_high%22%5D%0A%0A        # Don't want to load all data to memory at the same time%0A        for i in xrange(ds.shape%5B0%5D):%0A            print %22processing %256d/%25d in %25s%22 %25 (i+1, ds.shape%5B0%5D, k)%0A            dataset%5Bi,%5D = ds%5Bi,%5D * ff + .5%0A%0A# run()%0A    %0A%0Aif __name__ == %22__main__%22:%0A    import sys%0A    masterh5 = sys.argv%5B1%5D%0A    run(masterh5)%0A

Add eiger_apply_flatfield_correction.py to apply flatfield correction to h5 Internal version: 0e2c12a7