コード例 #1
0
ファイル: test_six_adjoint.py プロジェクト: szho42/SIRF
def test_main(rec=False, verb=False, throw=True):

    pet.MessageRedirector()

    for scheme in ("file", "memory"):
        pet.AcquisitionData.set_storage_scheme(scheme)

        original_verb = pet.get_verbosity()
        pet.set_verbosity(False)
        # create an acq_model that is explicitly a RayTracingMatrix
        am = pet.AcquisitionModelUsingRayTracingMatrix()
        # load sample data
        data_path = pet.examples_data_path('PET')
        raw_data_file = pet.existing_filepath(data_path,
                                              'Utahscat600k_ca_seg4.hs')
        ad = pet.AcquisitionData(raw_data_file)
        # create sample image
        image = pet.ImageData()
        image.initialise(dim=(31, 111, 111), vsize=(2.25, 2.25, 2.25))
        # set up Acquisition Model
        am.set_up(ad, image)
        # test for adjointnesss
        if not is_operator_adjoint(am, verbose=verb):
            raise AssertionError(
                'AcquisitionModelUsingRayTracingMatrix is not adjoint')

    # Reset original verbose-ness
    pet.set_verbosity(original_verb)
    return 0, 1
コード例 #2
0
ファイル: tests_NiftyPET.py プロジェクト: danieldeidda/SIRF
def test_main(rec=False, verb=False, throw=True):

    # Set STIR verbosity to off
    original_verb = pet.get_verbosity()
    pet.set_verbosity(1)

    time.sleep(0.5)
    sys.stderr.write("Testing NiftyPET projector...")
    time.sleep(0.5)

    # Get image
    image = get_image()

    # Get AM
    try:
        acq_model = pet.AcquisitionModelUsingNiftyPET()
    except:
        return 1, 1
    acq_model.set_cuda_verbosity(verb)

    data_path = examples_data_path('PET')
    # raw_data_path = pet.existing_filepath(os.path.join(data_path, 'mMR'), 'mMR_template_span11.hs')
    raw_data_path = os.path.join(data_path, 'mMR')
    template_acq_data = pet.AcquisitionData(
        os.path.join(raw_data_path, 'mMR_template_span11.hs'))

    acq_model.set_up(template_acq_data, image)

    # Test operator adjointness
    if verb:
        print('testing adjointness')
    if not is_operator_adjoint(acq_model, num_tests=1, verbose=True):
        raise AssertionError('NiftyPet AcquisitionModel is not adjoint')

    # Generate test data
    simulated_acq_data = acq_model.forward(image)
    simulated_acq_data_w_noise = add_noise(simulated_acq_data, 10)

    obj_fun = pet.make_Poisson_loglikelihood(template_acq_data)
    obj_fun.set_acquisition_model(acq_model)

    recon = pet.OSMAPOSLReconstructor()
    recon.set_objective_function(obj_fun)
    recon.set_num_subsets(1)
    recon.set_num_subiterations(1)
    recon.set_input(simulated_acq_data_w_noise)
    if verb:
        print('setting up, please wait...')
    initial_estimate = image.get_uniform_copy()
    recon.set_up(initial_estimate)

    if verb:
        print('reconstructing...')
    recon.set_current_estimate(initial_estimate)
    recon.process()
    reconstructed_im = recon.get_output()
    if not reconstructed_im:
        raise AssertionError()

    # Reset original verbose-ness
    pet.set_verbosity(original_verb)

    return 0, 1
コード例 #3
0
    convert = lambda text: int(text) if text.isdigit() else text.lower()
    alphanum_key = lambda key: [convert(c) for c in re.split('([0-9]+)', key)]
    return sorted(data, key=alphanum_key, reverse=False)

# generate a list, contains the time intervalls (sum of frames)
def sum_list(lists):
    sum_liste = []
    add = int(0)
    sum_liste.append(add)
    for frame in lists[0:]:
        add += frame
        sum_liste.append(add)
    return sum_liste

# Set the STIR verbosity
Pet.set_verbosity(1)


#%% data path and set filenames
# data path to list-mode and normalisation files
data_path_LM = '/home/rich/Documents/ReCo/UKL_data/LM/20190417/'
data_path_MR = '/home/rich/Documents/ReCo/UKL_data/Processed/MedPhys_MoCo_Test_20190417_7/'
# avoid cluttering of files, delete working-folder and start from scratch
working_folder = '/home/rich/Documents/ReCo/working'
if os.path.exists(working_folder):
    shutil.rmtree(working_folder)
if not os.path.exists(working_folder):
    os.makedirs(working_folder, mode=0o770)

# change the current working directory to the given path
os.chdir(working_folder)
コード例 #4
0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
#=========================================================================

import os, shutil, numpy
import unittest
import sirf.STIR as pet
from sirf.Utilities import examples_data_path

pet.AcquisitionData.set_storage_scheme('file')
pet.set_verbosity(0)


class TestSTIRObjectiveFunction(unittest.TestCase):
    def setUp(self):
        data_path = os.path.join(examples_data_path('PET'),
                                 'thorax_single_slice')

        image = pet.ImageData(os.path.join(data_path, 'emission.hv'))

        am = pet.AcquisitionModelUsingRayTracingMatrix()
        am.set_num_tangential_LORs(5)
        templ = pet.AcquisitionData(
            os.path.join(data_path, 'template_sinogram.hs'))
        am.set_up(templ, image)
        acquired_data = am.forward(image)
コード例 #5
0
# Output file
outp_prefix = args['--outp']

# Initial estimate
initial_estimate = args['--initial']

visualisations = True if args['--visualisations'] and have_pylab else False
nifti = True if args['--nifti'] else False
use_gpu = True if args['--gpu'] else False
descriptive_fname = True if args['--descriptive_fname'] else False
update_obj_fn_interval = int(args['--update_obj_fn_interval'])

# Verbosity
verbosity = int(args['--verbosity'])
pet.set_verbosity(verbosity)
if verbosity == 0:
    msg_red = pet.MessageRedirector(None, None, None)

# Save interval
save_interval = int(args['--save_interval'])
save_interval = min(save_interval, num_iters)

# Convergence variables
r_alpha = float(args['--alpha'])
precond = True if args['--precond'] else False


def get_resampler(image, ref=None, trans=None):
    """returns a NiftyResampler object for the specified transform and image"""
    if ref is None: