(fname)
| 855 | |
| 856 | |
| 857 | def _read_dipole_bdip(fname): |
| 858 | name = None |
| 859 | nfree = None |
| 860 | with open(fname, "rb") as fid: |
| 861 | # Which dipole in a multi-dipole set |
| 862 | times = list() |
| 863 | pos = list() |
| 864 | amplitude = list() |
| 865 | ori = list() |
| 866 | gof = list() |
| 867 | conf = dict(vol=list()) |
| 868 | khi2 = list() |
| 869 | has_errors = None |
| 870 | while True: |
| 871 | num = np.frombuffer(fid.read(4), ">i4") |
| 872 | if len(num) == 0: |
| 873 | break |
| 874 | times.append(np.frombuffer(fid.read(4), ">f4")[0]) |
| 875 | fid.read(4) # end |
| 876 | fid.read(12) # r0 |
| 877 | pos.append(np.frombuffer(fid.read(12), ">f4")) |
| 878 | Q = np.frombuffer(fid.read(12), ">f4") |
| 879 | amplitude.append(np.linalg.norm(Q)) |
| 880 | ori.append(Q / amplitude[-1]) |
| 881 | gof.append(100 * np.frombuffer(fid.read(4), ">f4")[0]) |
| 882 | this_has_errors = bool(np.frombuffer(fid.read(4), ">i4")[0]) |
| 883 | if has_errors is None: |
| 884 | has_errors = this_has_errors |
| 885 | for key in _BDIP_ERROR_KEYS: |
| 886 | conf[key] = list() |
| 887 | assert has_errors == this_has_errors |
| 888 | fid.read(4) # Noise level used for error computations |
| 889 | limits = np.frombuffer(fid.read(20), ">f4") # error limits |
| 890 | for key, lim in zip(_BDIP_ERROR_KEYS, limits): |
| 891 | conf[key].append(lim) |
| 892 | fid.read(100) # (5, 5) fully describes the conf. ellipsoid |
| 893 | conf["vol"].append(np.frombuffer(fid.read(4), ">f4")[0]) |
| 894 | khi2.append(np.frombuffer(fid.read(4), ">f4")[0]) |
| 895 | fid.read(4) # prob |
| 896 | fid.read(4) # total noise estimate |
| 897 | return Dipole(times, pos, amplitude, ori, gof, name, conf, khi2, nfree) |
| 898 | |
| 899 | |
| 900 | def _write_dipole_bdip(fname, dip): |
no test coverage detected