mikgroup/sigpy

Unexpected acceleration with sigpy.mri.poisson

ad12 opened this issue · 2 comments

ad12 commented

Describe the bug
Output masks produced by sigpy.mri.poisson are not within the expected +/-0.1 bounds of the expected acceleration (passed in as an argument). We also see this in cases where crop_corner=False and in the trivial case acceleration=1.0.

To Reproduce

# desired acceleration
desired_accel = 1.0  # also tried with 4.0 and 6.0

mask = sigpy.mri.poisson(
            (512, 80), 
            accel=desired_accel,
            calib=(16, 16),
            dtype=np.bool,
            crop_corner=False,
        )

acc = 512 * 80 / mask.sum()   # between 7.2-7.6 depending on the seed

Expected behavior
The output mask should correspond to an acceleration closer to the desired_accel

Desktop (please complete the following information):

  • OS: Ubuntu 20.04
  • SigPy Version: 0.1.20
ad12 commented

Results from a more exhaustive search. The Expected Acceleration is the acceleration passed into the the poisson function.

Results

Mask Shape Calibration Size Crop Corner? Expected Acceleration Acceleration
0 (512, 80) (16, 16) False 1 7.38284
1 (512, 80) (16, 16) True 1 8.9218
2 (512, 80) (16, 16) False 4 7.38284
3 (512, 80) (16, 16) True 4 8.9218
4 (512, 80) (16, 16) False 6 7.38284
5 (512, 80) (16, 16) True 6 8.9218
6 (512, 80) (16, 16) False 12 11.9104
7 (512, 80) (16, 16) True 12 12.0719
8 (320, 256) (20, 20) False 1 1.44702
9 (320, 256) (20, 20) True 1 1.7772
10 (320, 256) (20, 20) False 4 4.074
11 (320, 256) (20, 20) True 4 4.04344
12 (320, 256) (20, 20) False 6 6.06276
13 (320, 256) (20, 20) True 6 5.97128
14 (320, 256) (20, 20) False 12 12.0987
15 (320, 256) (20, 20) True 12 11.9434

To Reproduce

import numpy as np
import pandas as pd
from sigpy.mri import poisson
from tabulate import tabulate

N = 1
data = []

for img_shape, calib_size in zip([(512, 80), (320, 256)], [(16, 16), (20, 20)]):
    for accel in [1.0, 4.0, 6.0, 12.0]:
        for crop_corner in [False, True]:
            outputs = []
            for i in range(N):
                mask = poisson(img_shape, accel, calib=calib_size, dtype=np.bool, crop_corner=crop_corner)
                outputs.append(np.product(img_shape) / mask.sum())
            avg_accel = np.mean(outputs)
            data.append({"Image Shape": str(img_shape), "Calibration Size": str(calib_size), "Crop Corner?": crop_corner, "Expected Acceleration": accel, "Acceleration": avg_accel})
            print(data[-1])

import pdb; pdb.set_trace()
data = pd.DataFrame(data)
print(tabulate(data, headers=data.columns, tablefmt="github"))

This is fixed in 08bef3c.
accel=1 is still not supported, and the function will now throw an exception (cd27418)

Here's an instance of running the above code:

Image Shape Calibration Size Crop Corner? Expected Acceleration Acceleration
0 (512, 80) (16, 16) False 4 3.97516
1 (512, 80) (16, 16) True 4 3.94605
2 (512, 80) (16, 16) False 6 6.06635
3 (512, 80) (16, 16) True 6 6.04576
4 (512, 80) (16, 16) False 12 11.9556
5 (512, 80) (16, 16) True 12 12.04
6 (320, 256) (20, 20) False 4 3.94472
7 (320, 256) (20, 20) True 4 3.93354
8 (320, 256) (20, 20) False 6 5.91181
9 (320, 256) (20, 20) True 6 6.00234
10 (320, 256) (20, 20) False 12 12.0012
11 (320, 256) (20, 20) True 12 11.9347