Пример #1
0
def run_HT_file(h5f, v, dry_run):
    """
    Handle one file: h5f['00000']['pix10_5noise0'] and so
    """

    for track_key in h5f.keys():
        # h5save.create_group(track_key)
        if v > 1:
            print('  Starting', track_key, 'at', time.ctime())
        this_h5track = h5f[track_key]
        h5_to_pydict = {}
        pydict_to_pyobj = {}
        pyobj_to_h5 = {}

        pix_list = ['pix2_5noise0', 'pix10_5noise0']
        if (pix_list[0] not in this_h5track.keys()
                or pix_list[1] not in this_h5track.keys()):
            continue
        for _, pix_key in enumerate(pix_list):
            # if not pix_key.startswith('pix'):
            #     continue

            alg_name = 'python HT v1.5'
            alg_name2 = 'python HT v1.5a'
            if v > 2:
                print('    Starting', pix_key, 'at', time.ctime())
            this_h5pix = this_h5track[pix_key]
            if 'algorithms' not in this_h5pix.keys():
                continue
            if alg_name in this_h5pix['algorithms'].keys():
                continue
            if v > 3:
                print('      Building Track object...', time.ctime())
            this_track = trackdata.Track.from_hdf5(
                this_h5pix,
                h5_to_pydict=h5_to_pydict,
                pydict_to_pyobj=pydict_to_pyobj)
            if v > 3:
                print('      Running HybridTrack...', time.ctime())
            try:
                HTout, HTinfo = hybridtrack.reconstruct(
                    this_track.image, pixel_size_um=this_track.pixel_size_um)
                HTout2, HTinfo2 = hybridtrack2.reconstruct(
                    this_track.image, pixel_size_um=this_track.pixel_size_um)
            except Exception:  # hybridtrack.HybridTrackError, hybridtrack2.HybridTrackError:
                if v > 1:
                    print('      HybridTrackError on', track_key, 'at',
                          time.ctime())
                continue

            this_track.add_algorithm(alg_name,
                                     alpha_deg=HTinfo.alpha_deg,
                                     beta_deg=HTinfo.beta_deg,
                                     info=HTinfo)
            this_track.add_algorithm(alg_name2,
                                     alpha_deg=HTinfo2.alpha_deg,
                                     beta_deg=HTinfo2.beta_deg,
                                     info=HTinfo2)
            if v > 2:
                print('    Appending to file', pix_key, 'at', time.ctime())
            # append to same file
            if dry_run:
                continue
            trackio.write_object_to_hdf5(this_track.algorithms[alg_name],
                                         this_h5pix['algorithms'],
                                         alg_name,
                                         pyobj_to_h5=pyobj_to_h5)
            trackio.write_object_to_hdf5(this_track.algorithms[alg_name2],
                                         this_h5pix['algorithms'],
                                         alg_name2,
                                         pyobj_to_h5=pyobj_to_h5)
Пример #2
0
def run_HT_file(h5f, v, dry_run):
    """
    Handle one file: h5f['00000']['pix10_5noise0'] and so
    """

    for track_key in h5f.keys():
        # h5save.create_group(track_key)
        if v > 1:
            print('  Starting', track_key, 'at', time.ctime())
        this_h5track = h5f[track_key]
        h5_to_pydict = {}
        pydict_to_pyobj = {}
        pyobj_to_h5 = {}

        pix_list = ['pix2_5noise0', 'pix10_5noise0']
        if (pix_list[0] not in this_h5track.keys() or
                pix_list[1] not in this_h5track.keys()):
            continue
        for _, pix_key in enumerate(pix_list):
            # if not pix_key.startswith('pix'):
            #     continue

            alg_name = 'python HT v1.5'
            alg_name2 = 'python HT v1.5a'
            if v > 2:
                print('    Starting', pix_key, 'at', time.ctime())
            this_h5pix = this_h5track[pix_key]
            if 'algorithms' not in this_h5pix.keys():
                continue
            if alg_name in this_h5pix['algorithms'].keys():
                continue
            if v > 3:
                print('      Building Track object...', time.ctime())
            this_track = trackdata.Track.from_hdf5(
                this_h5pix,
                h5_to_pydict=h5_to_pydict, pydict_to_pyobj=pydict_to_pyobj)
            if v > 3:
                print('      Running HybridTrack...', time.ctime())
            try:
                HTout, HTinfo = hybridtrack.reconstruct(
                    this_track.image, pixel_size_um=this_track.pixel_size_um)
                HTout2, HTinfo2 = hybridtrack2.reconstruct(
                    this_track.image, pixel_size_um=this_track.pixel_size_um)
            except Exception:  # hybridtrack.HybridTrackError, hybridtrack2.HybridTrackError:
                if v > 1:
                    print('      HybridTrackError on', track_key,
                          'at', time.ctime())
                continue

            this_track.add_algorithm(
                alg_name,
                alpha_deg=HTinfo.alpha_deg, beta_deg=HTinfo.beta_deg,
                info=HTinfo)
            this_track.add_algorithm(
                alg_name2,
                alpha_deg=HTinfo2.alpha_deg, beta_deg=HTinfo2.beta_deg,
                info=HTinfo2)
            if v > 2:
                print('    Appending to file', pix_key, 'at', time.ctime())
            # append to same file
            if dry_run:
                continue
            trackio.write_object_to_hdf5(
                this_track.algorithms[alg_name],
                this_h5pix['algorithms'], alg_name,
                pyobj_to_h5=pyobj_to_h5)
            trackio.write_object_to_hdf5(
                this_track.algorithms[alg_name2],
                this_h5pix['algorithms'], alg_name2,
                pyobj_to_h5=pyobj_to_h5)
Пример #3
0
    eventname = 'event{:05d}'.format(i)
    if eventname in h5file:
        event = h5file[eventname]
        trackname = 'trackimage2.5'
        # print(trackname)
        # print(event)
        if trackname in event:
            this_image_object = event[trackname]
            this_image = np.zeros(this_image_object.shape)
            this_image_object.read_direct(this_image)
            aname = 'matlab_alpha'
            if aname in event[trackname].attrs:
                mat_alpha[i] = event[trackname].attrs[aname]
            try:
                # reverse the transpose MATLAB did during h5create
                __, info[i] = hybridtrack.reconstruct(this_image.T,
                                                      pixel_size_um=2.5)
                py_alpha[i] = info[i].alpha_deg
            except hybridtrack.InfiniteLoop:
                print('Infinite loop on event #{}'.format(i))
            except hybridtrack.NoEndsFound:
                print('No ends found on event #{}'.format(i))
            except Exception:
                print('Other error:')
                print(Exception)

    pbar.update(i)
pbar.finish()

np.savez('alpha2.5.npz', py_alpha=py_alpha, mat_alpha=mat_alpha)
Пример #4
0
for i in range(len(h5file)):
    eventname = "event{:05d}".format(i)
    if eventname in h5file:
        event = h5file[eventname]
        trackname = "trackimage2.5"
        # print(trackname)
        # print(event)
        if trackname in event:
            this_image_object = event[trackname]
            this_image = np.zeros(this_image_object.shape)
            this_image_object.read_direct(this_image)
            aname = "matlab_alpha"
            if aname in event[trackname].attrs:
                mat_alpha[i] = event[trackname].attrs[aname]
            try:
                # reverse the transpose MATLAB did during h5create
                __, info[i] = hybridtrack.reconstruct(this_image.T, pixel_size_um=2.5)
                py_alpha[i] = info[i].alpha_deg
            except hybridtrack.InfiniteLoop:
                print("Infinite loop on event #{}".format(i))
            except hybridtrack.NoEndsFound:
                print("No ends found on event #{}".format(i))
            except Exception:
                print("Other error:")
                print(Exception)

    pbar.update(i)
pbar.finish()

np.savez("alpha2.5.npz", py_alpha=py_alpha, mat_alpha=mat_alpha)