コード例 #1
0
def test_find_entries_empty_file(tmp_path):
    h5_file = tmp_path / "tmp.nxs"
    with h5py.File(h5_file, "w"):
        pass

    with h5py.File(h5_file, "r") as fr:
        entries = nexus.find_entries(fr)
        assert len(entries) == 0
コード例 #2
0
 def understand(image_file):
     import h5py
     is_nexus_still = False
     try:
         from dxtbx.format.nexus import find_entries, find_class
         # Get the file handle
         handle = h5py.File(image_file, 'r')
         for entry in find_entries(handle, "/"):
             for sample in find_class(entry, "NXsample"):
                 if 'depends_on' not in sample:
                     is_nexus_still = True
     except IOError:
         return False
     return is_nexus_still
コード例 #3
0
ファイル: FormatNexus.py プロジェクト: cctbx/dxtbx
    def understand(image_file):
        is_nexus_still = False
        try:
            # Get the file handle
            with h5py.File(image_file, "r") as handle:
                if "/entry/sample/goniometer/omega_increment" in handle:
                    return False

                for entry in nexus.find_entries(handle):
                    for sample in nexus.find_class(entry, "NXsample"):
                        if "depends_on" not in sample:
                            is_nexus_still = True
        except IOError:
            return False
        return is_nexus_still
コード例 #4
0
def test_find_entries_no_entry(tmp_path):
    h5_file = tmp_path / "tmp.nxs"
    with h5py.File(h5_file, "w") as fw:
        # NX_class == NXdata
        group = fw.create_dataset("data", (100, ))
        group.attrs["NX_class"] = "NXdata"
        # NX_class == NXentry but no definition provided - skip this entry
        group = fw.create_group("no_definition")
        group.attrs["NX_class"] = "NXentry"
        # NX_class == NXentry but definition != NXmx
        group = fw.create_group("wrong_definition")
        group.attrs["NX_class"] = "NXentry"
        group["definition"] = "NXmagic"

    with h5py.File(h5_file, "r") as fr:
        entries = nexus.find_entries(fr)
        assert len(entries) == 0
コード例 #5
0
def test_find_entries(nexus_file):
    with h5py.File(nexus_file, "r") as fr:
        entries = nexus.find_entries(fr)
        assert len(entries) == len(entry_names)
        assert set(entry.name for entry in entries) == set(entry_names)