Load the morph for source estimates from a file. Parameters ---------- fname : path-like Path to the file containing the morph source estimates. Returns ------- source_morph : instance of SourceMorph The loaded morph.
(fname)
| 850 | |
| 851 | |
| 852 | def read_source_morph(fname): |
| 853 | """Load the morph for source estimates from a file. |
| 854 | |
| 855 | Parameters |
| 856 | ---------- |
| 857 | fname : path-like |
| 858 | Path to the file containing the morph source estimates. |
| 859 | |
| 860 | Returns |
| 861 | ------- |
| 862 | source_morph : instance of SourceMorph |
| 863 | The loaded morph. |
| 864 | """ |
| 865 | read_hdf5, _ = _import_h5io_funcs() |
| 866 | vals = read_hdf5(fname) |
| 867 | if vals["pre_affine"] is not None: # reconstruct |
| 868 | from dipy.align.imaffine import AffineMap |
| 869 | |
| 870 | affine = vals["pre_affine"] |
| 871 | vals["pre_affine"] = AffineMap(None) |
| 872 | vals["pre_affine"].__dict__ = affine |
| 873 | if vals["sdr_morph"] is not None: |
| 874 | from dipy.align.imwarp import DiffeomorphicMap |
| 875 | |
| 876 | morph = vals["sdr_morph"] |
| 877 | vals["sdr_morph"] = DiffeomorphicMap(None, []) |
| 878 | vals["sdr_morph"].__dict__ = morph |
| 879 | # Backward compat with when it used to be a list |
| 880 | if isinstance(vals["vertices_to"], np.ndarray): |
| 881 | vals["vertices_to"] = [vals["vertices_to"]] |
| 882 | # Backward compat with when it used to be a single array |
| 883 | if isinstance(vals["src_data"].get("inuse", None), np.ndarray): |
| 884 | vals["src_data"]["inuse"] = [vals["src_data"]["inuse"]] |
| 885 | # added with compute_vol_morph_mat in 0.22: |
| 886 | vals["vol_morph_mat"] = vals.get("vol_morph_mat", None) |
| 887 | return SourceMorph(**vals) |
| 888 | |
| 889 | |
| 890 | ############################################################################### |