1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105
|
from __future__ import annotations
import shutil
import subprocess
import pytest
from iotbx import ccp4_map
from scitbx.array_family import flex
def test_rs_mapper(dials_data, tmp_path):
result = subprocess.run(
[
shutil.which("dials.rs_mapper"),
dials_data("centroid_test_data", pathlib=True)
/ "imported_experiments.json",
'map_file="junk.ccp4"',
],
cwd=tmp_path,
capture_output=True,
)
assert not result.returncode and not result.stderr
assert (tmp_path / "junk.ccp4").is_file()
# load results
m = ccp4_map.map_reader(file_name=str(tmp_path / "junk.ccp4"))
assert len(m.data) == 7189057
assert m.header_min == 0.0
assert flex.min(m.data) == 0.0
assert m.header_max == 2052.75
assert flex.max(m.data) == 2052.75
assert m.header_mean == pytest.approx(0.018924040719866753, abs=1e-6)
assert flex.mean(m.data) == pytest.approx(0.01892407052218914, abs=1e-6)
def test_multi_panel(dials_data, tmp_path):
data_dir = dials_data("image_examples", pathlib=True)
image = data_dir / "DLS_I23_germ_13KeV_0001.cbf"
result = subprocess.run(
[
shutil.which("dials.rs_mapper"),
image,
'map_file="junk.ccp4"',
],
cwd=tmp_path,
capture_output=True,
)
assert not result.returncode and not result.stderr
assert (tmp_path / "junk.ccp4").is_file()
# load results
m = ccp4_map.map_reader(file_name=str(tmp_path / "junk.ccp4"))
assert len(m.data) == 7189057
assert m.header_min == 0.0
assert flex.min(m.data) == 0.0
assert m.header_max == 31342.25
assert flex.max(m.data) == 31342.25
assert m.header_mean == pytest.approx(0.05911629647016525, abs=1e-6)
assert flex.mean(m.data) == pytest.approx(0.05911629647016525, abs=1e-6)
def test_masked(dials_data, tmp_path):
subprocess.run(
[
shutil.which("dials.import"),
dials_data("image_examples", pathlib=True) / "dectris_eiger_master.h5",
],
cwd=tmp_path,
capture_output=True,
)
result = subprocess.run(
[shutil.which("dials.rs_mapper"), "imported.expt", "map_file=masked.ccp4"],
cwd=tmp_path,
capture_output=True,
)
assert not result.returncode and not result.stderr
assert (tmp_path / "masked.ccp4").is_file()
# Also check the ignore case (regressions here may indicate changes in mask handling)
result = subprocess.run(
[
shutil.which("dials.rs_mapper"),
"imported.expt",
"map_file=unmasked.ccp4",
"ignore_mask=True",
],
cwd=tmp_path,
capture_output=True,
)
assert not result.returncode and not result.stderr
assert (tmp_path / "unmasked.ccp4").is_file()
# Load results
masked = ccp4_map.map_reader(file_name=str(tmp_path / "masked.ccp4"))
unmasked = ccp4_map.map_reader(file_name=str(tmp_path / "unmasked.ccp4"))
assert masked.header_max < unmasked.header_max
assert masked.header_max == pytest.approx(289.11111)
assert unmasked.header_max == pytest.approx(65535.0)
|