Esempio n. 1
0
 def test_div(self):
     with self.subTest(0):
         p = Path('/tmp')
         p = p / 'sub'
         self.assertEqual(p.route, '/tmp/sub')
     with self.subTest(1):
         p = Path('/tmp')
         p = p / 'sub/'
         self.assertEqual(p.route, '/tmp/sub')
Esempio n. 2
0
File: main.py Progetto: tech-pi/SRF
def lm2bin(config, target):
    path_file = config['input']['listmode']['path_file']
    data = load_h5(path_file)
    coo_data = np.hstack((data['fst'], data['snd']))
    bin_data = np.hstack(
        (coo_data, data['weight'].reshape(data['weight'].size, 1)))
    out = bin_data.astype(np.float32)
    out.tofile((Path(target) + 'input.txt').abs)
    f = open((Path(target) + 'input.txt.hdr').abs, 'w')
    f.write(str(out.shape[0]))
Esempio n. 3
0
 def setUp(self):
     dpath = tempfile.mkdtemp()
     dpath1 = tempfile.mkdtemp()
     pdr = Path(dpath)
     pf1 = Directory(pdr / 'sub1')
     mkdir(pf1)
     pf2 = Directory(pdr / 'sub2')
     mkdir(pf2)
     pd6 = pdr / 'sub6'
     mkdir(Directory(pd6))
     pd7 = Directory(pd6 / 'sub7')
     mkdir(pd7)
     self.root = dpath
     self.root1 = Path(dpath1)
Esempio n. 4
0
def save_script(path, data):
    path = Path(path)
    if path.suffix == ' ':
        path = path + 'hs'
    target = path.abs
    with open(target, 'w') as fin:
        fin.write(data)
Esempio n. 5
0
def save_script(path, data, suffix):
    path = Path(path)
    if path.suffix == '':
        path = path + suffix
    target = path.abs
    with open(target, 'w') as fout:
        fout.write(data)
Esempio n. 6
0
def save_osem_result(save_path, dataset_prefix, source, nb_iterations,
                     nb_subsets):
    with h5py.File(save_path.abs) as fout:
        for i in range(0, nb_iterations):
            for j in range(0, nb_subsets):
                label = dataset_prefix + 'output_' + str(i + 1) + '_' + str(j +
                                                                            1)
                source_path = Path(source) + str(i + 1) + '_' + str(j +
                                                                    1) + '.v'
                fout[label] = np.fromfile(source_path.abs, dtype='float32')
Esempio n. 7
0
def generate_recon_script(config, target, source):
    with open(config, 'r') as fin:
        c = json.load(fin)
    if source is None:
        source = '.'
    recon_spec = generatereconspec(c, source)
    recon_script = render(ReconstructionSpecScript(recon_spec))
    path_script = Path(target).abs + '/OSMAPOSL.par'
    # if path_script.suffix == ' ':
    #     path_script = path_script+'.par'
    save_script(path_script, recon_script)
Esempio n. 8
0
 def test_parts(self):
     with self.subTest(0):
         p = Path('/tmp/base')
         self.assertEqual(p.parts(), ('/', 'tmp', 'base'))
     with self.subTest(1):
         p = Path('a/b')
         self.assertEqual(p.parts(), ('a', 'b'))
Esempio n. 9
0
def save_result(config, source):
    part_config = config['algorithm']['recon']
    nb_subsets, nb_subiterations = get_iter_info(part_config)
    algorithm = get_algorithm(part_config)
    save_path = Path(config['output']['image']['path_file'])
    dataset_prefix = config['output']['image']['path_dataset_prefix']
    if algorithm == ('FBP2D' or 'FBP3DRP'):
        save_fbp_result(save_path, dataset_prefix, source)
    elif algorithm == 'MLEM':
        save_mlem_result(save_path, dataset_prefix, source, nb_subiterations)
    else:
        save_osem_result(save_path, dataset_prefix, source, nb_subiterations,
                         nb_subsets)
Esempio n. 10
0
def generatereconspec(config, path_header):
    path_header = Path(path_header + '/sinogram.hs')
    part_config = config['algorithm']['recon']
    if ("osem" in part_config):
        nb_subsets = part_config['osem']['nb_subsets']
        nb_subiterations = part_config['osem']['nb_iterations']
    else:
        nb_subsets = 1
        nb_subiterations = part_config['mlem']['nb_iterations']

    return ReconstructionSpec(path_header.abs,
                              config['output']['image']['grid'][0], nb_subsets,
                              nb_subiterations)
Esempio n. 11
0
def generate_data_and_header(config, target):
    with open(config, 'r') as fin:
        c = json.load(fin)
    scanner = get_scanner(c['scanner']['petscanner'])
    path_data = Path(target)
    gen_sino_script(c['scanner']['petscanner'], (path_data.abs + 'sinogram'))
    path_file = c['input']['listmode']['path_file']
    data = load_h5(path_file)
    lor = List(
        LoR(PositionEvent(data['fst'][i, ]),
            PositionEvent(data['snd'][i, ]),
            weight=data['weight'][i]) for i in range(0, data['weight'].size))
    lm2sino(scanner, lor, (path_data.abs + '/sinogram.s'))
Esempio n. 12
0
 def setUp(self):
     dpath = tempfile.mkdtemp()
     dpath1 = tempfile.mkdtemp()
     pdr = Path(dpath)
     pf1 = File(pdr / 'tmp.txt')
     touch(pf1)
     pf2 = File(pdr / 'tmp2.txt')
     touch(pf2)
     pf3 = File(pdr / 'tmp4.txt')
     touch(pf3)
     with open(str(pf3.path), 'w') as fout:
         print('test3', file=fout)
     self.root = dpath
     self.root1 = dpath1
Esempio n. 13
0
 def test_copy_file(self):
     file1 = File(self.root + '/tmp2.txt')
     cp(file1, Path(self.root1 + '/tmp2.txt'))
     file2 = File(self.root1 + '/tmp2.txt')
     assert file2.exists and file1.exists
Esempio n. 14
0
 def neg1():
     path2 = Path(self.root + '/tmpx.txt')
     assert not File.is_file(path2)
Esempio n. 15
0
 def neg2():
     path3 = Path(self.root + '/sub1')
     assert not File.is_file(path3)
Esempio n. 16
0
 def neg():
     file1 = File((Path(self.root) / 'tmpx.txt').abs)
     assert not (file1.exists)
Esempio n. 17
0
 def pos():
     path1 = Path(self.root + '/tmp.txt')
     assert File.is_file(path1)
Esempio n. 18
0
 def test_fatherpath(self,input,output):    
     assert Path(input).father_path().route ==output        
Esempio n. 19
0
 def pos():
     file1 = File((Path(self.root) / 'tmp.txt').abs)
     assert (file1.exists)
Esempio n. 20
0
 def test_absolute(self,input,output):
     assert Path(input).absolute().route == output     
Esempio n. 21
0
 def test_dot(self):
     self.assertEqual(Path('.').route, '')
Esempio n. 22
0
 def test_eq(self,xi,xo):
     assert Path(xi) == Path(xo)
Esempio n. 23
0
 def test_relative(self,input,output):
     assert Path(input).relative == output
Esempio n. 24
0
 def test_isabs(self,input,output):
     assert Path(input).isabs == output
Esempio n. 25
0
 def test_name(self, input, output):
     assert Path(input).name == output
Esempio n. 26
0
 def test_suffixes(self,input,output):    
     assert Path(input).suffixes == output
Esempio n. 27
0
 def test_move_file(self):
     file1 = File(self.root + '/tmp2.txt')
     mv(file1, Path(self.root1 + '/tmp2.txt'))
     file2 = File(self.root1 + '/tmp2.txt')
     assert file2.exists and not file1.exists
Esempio n. 28
0
 def test_join_dot(self):
     self.assertEqual((Path('.') / 'a').route, 'a')
Esempio n. 29
0
 def test_isroot(self,input,output):
     assert Path(input).isroot == output
Esempio n. 30
0
 def test_father(self,input,output):
     assert Path(input).father == output