@@ -634,13 +634,14 @@ class TestLogImageSummary:
634634 """Tests for log_image_summary()."""
635635
636636 def test_3d_summary (self , nifti_3d : Path , caplog : pytest .LogCaptureFixture ) -> None :
637- """3D input logs shape, dtype, voxel size, orientation, and spaces."""
637+ """3D input logs shape, dtype, size, voxel size, orientation, spaces."""
638638 caplog .set_level (logging .INFO , logger = "rbc.core.nifti" )
639639 log_image_summary (nifti_3d , label = "Anatomical T1w" )
640640 text = "\n " .join (caplog .messages )
641641 assert "Anatomical T1w" in text
642642 assert "shape=(5, 6, 7)" in text
643643 assert "dtype=float64" in text
644+ assert "uncompressed size=1.6 KiB" in text # 5*6*7 * 8 = 1680 bytes
644645 assert "voxel size=1 x 1 x 1 mm" in text
645646 assert "orientation=RAS" in text
646647 assert "sform=MNI" in text
@@ -663,18 +664,30 @@ def test_4d_summary_includes_volumes_and_tr(
663664 log_image_summary (nifti_4d , label = "Functional BOLD" )
664665 text = "\n " .join (caplog .messages )
665666 assert "shape=(5, 6, 7, 10)" in text
667+ assert "uncompressed size=16.4 KiB" in text # 5*6*7*10 * 8 bytes
666668 assert "volumes=10" in text
667669 assert "slices=7" in text
668670 assert "header TR=2 s" in text
669671
670- def test_dtype_reflects_on_disk_type (
672+ def test_dtype_and_size_reflect_on_disk_type (
671673 self , tmp_path : Path , caplog : pytest .LogCaptureFixture
672674 ) -> None :
673- """Logged dtype is the on-disk dtype, not float from get_fdata()."""
675+ """Logged dtype/size use the on-disk dtype, not float64 get_fdata()."""
674676 path = _make_nifti (tmp_path , "int16.nii.gz" , (4 , 5 , 6 ), dtype = np .int16 )
675677 caplog .set_level (logging .INFO , logger = "rbc.core.nifti" )
676678 log_image_summary (path )
677- assert any ("dtype=int16" in m for m in caplog .messages )
679+ text = "\n " .join (caplog .messages )
680+ assert "dtype=int16" in text
681+ assert "uncompressed size=240 B" in text # 4*5*6 * 2 bytes
682+
683+ def test_size_uses_binary_units (
684+ self , tmp_path : Path , caplog : pytest .LogCaptureFixture
685+ ) -> None :
686+ """Uncompressed size scales to binary units."""
687+ path = _make_nifti (tmp_path , "big.nii.gz" , (64 , 64 , 64 ), dtype = np .int16 )
688+ caplog .set_level (logging .INFO , logger = "rbc.core.nifti" )
689+ log_image_summary (path )
690+ assert any ("uncompressed size=512.0 KiB" in m for m in caplog .messages )
678691
679692 def test_emitted_at_info_level (
680693 self , nifti_3d : Path , caplog : pytest .LogCaptureFixture
0 commit comments