예제 #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')
예제 #2
0
파일: main.py 프로젝트: 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]))
예제 #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)
예제 #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)
예제 #5
0
파일: fileio.py 프로젝트: tech-pi/SRF
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)
예제 #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')
예제 #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)
예제 #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'))
예제 #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)
예제 #10
0
파일: genespec.py 프로젝트: tech-pi/SRF
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)
예제 #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'))
예제 #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
예제 #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
예제 #14
0
 def neg1():
     path2 = Path(self.root + '/tmpx.txt')
     assert not File.is_file(path2)
예제 #15
0
 def neg2():
     path3 = Path(self.root + '/sub1')
     assert not File.is_file(path3)
예제 #16
0
 def neg():
     file1 = File((Path(self.root) / 'tmpx.txt').abs)
     assert not (file1.exists)
예제 #17
0
 def pos():
     path1 = Path(self.root + '/tmp.txt')
     assert File.is_file(path1)
예제 #18
0
 def test_fatherpath(self,input,output):    
     assert Path(input).father_path().route ==output        
예제 #19
0
 def pos():
     file1 = File((Path(self.root) / 'tmp.txt').abs)
     assert (file1.exists)
예제 #20
0
 def test_absolute(self,input,output):
     assert Path(input).absolute().route == output     
예제 #21
0
 def test_dot(self):
     self.assertEqual(Path('.').route, '')
예제 #22
0
 def test_eq(self,xi,xo):
     assert Path(xi) == Path(xo)
예제 #23
0
 def test_relative(self,input,output):
     assert Path(input).relative == output
예제 #24
0
 def test_isabs(self,input,output):
     assert Path(input).isabs == output
예제 #25
0
 def test_name(self, input, output):
     assert Path(input).name == output
예제 #26
0
 def test_suffixes(self,input,output):    
     assert Path(input).suffixes == output
예제 #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
예제 #28
0
 def test_join_dot(self):
     self.assertEqual((Path('.') / 'a').route, 'a')
예제 #29
0
 def test_isroot(self,input,output):
     assert Path(input).isroot == output
예제 #30
0
 def test_father(self,input,output):
     assert Path(input).father == output