def interpolate(self): # elec_coord = geodesic3D_hybrid(A_vox, B_vox, D_vox, C_vox, 8, 8, mask_data) elec_coord = interpol(A_vox, B_vox, C_vox, 8, 8) snap_coords = elec_snap(elec_coord, ct_data) for point in snap_coords: ct_data[point[0]-2:point[0]+2, point[1]-2:point[1]+2, point[2]-2:point[2]+2] = 5000 mip = ct2mip(ct_data, 1, theta, phi) a.imshow(mip) canvas.show()
def __init__(self, vars, config): ProjectWalker.Checker.__init__(self, self.__class__, vars, config) self.addOption('files', isList=True, default=[]) self.addOption('excludeFiles', isList=True, default=[]) self.addOption('command', isList=True) self.parseOptions() self.setUpIncludesExcludes(self.files, self.excludeFiles) self.cmds = [] for tcmd in self.command: self.cmds.append(interpol(vars, tcmd))
def geodesic3D_hybrid(A, B, C, D, m, n, mask): A2C = tuple(geodesic3D(A, C, mask)) B2D = interpol(B, D, [], 1, n) B2D = tuple(B2D) # Divide up sides into n electrodes. dist = len(A2C) l = dist-1 k = l/float(m-1) # Distance between electrodes electrodes = [] i = 0 if k.is_integer(): while i <= l: electrodes.append(A2C[int(i)]) i += k else: while True: if i >= l: electrodes.append(A2C[-1]) break else: e, f = math.modf(i) f = int(f) inc = tuple(np.add(A2C[f],np.multiply(e,(np.subtract(A2C[f+1],A2C[f]))))) electrodes.append(inc) i += k # Interpolate linearly between each side. grid = [] grid.append(electrodes) for i in xrange(0,n): start = electrodes[i] end = B2D[i] pairs = interpol(start, end, [], 1, n) grid.append(pairs[1:-1]) grid.append(B2D) grid = list(itertools.chain(*grid)) return grid
def geodesic3D_hybrid(A, B, C, D, m, n, mask): A2C = tuple(geodesic3D(A, C, mask)) B2D = tuple(geodesic3D(B, D, mask)) # Divide up sides into n electrodes. sides = [A2C, B2D] d = {} for x in sides: dist = len(x) l = dist-1 k = l/float(m-1) # Distance between electrodes electrodes = [] i = 0 if k.is_integer(): while i <= l: electrodes.append(x[int(i)]) i += k else: while True: if i >= l: electrodes.append(x[-1]) break else: e, f = math.modf(i) f = int(f) inc = tuple(np.add(x[f],np.multiply(e,(np.subtract(x[f+1],x[f]))))) electrodes.append(inc) i += k d[x] = electrodes # Interpolate linearly between each side. grid = [] grid.append(d[A2C]) for i in range(0,n): start = d[A2C][i] end = d[B2D][i] pairs = interpol(start, end, [], 1, n) grid.append(pairs[1:-1]) grid.append(d[B2D]) grid = list(itertools.chain(*grid)) return grid
def __init__( self, name, vars, config, ): Visitor.__init__(self) self.name = name self.check_result = [] self.checked_count = 0 self.failed_count = 0 # read-only! self.vars = vars self.config = interpol(vars, config) self.current_context = None self.optionParser = DictConfig.DictConfigParser(self, isCaseSensitive=False, removeChars='-_', isLongestTokenMatch=True) self.hasVariable = has_variable(config)
def test_regexReplacement1(self): self.assertEqual('fXXqXXxbar', interpol(self.v, '%{other#[ou]#X}bar'))
def test_stringReplacement2(self): self.assertEqual('quuxbar', interpol(self.v, '%{other#foo#}bar'))
def test_stringEmbeddedSubstringFromTo2(self): self.assertEqual('oqubar', interpol(self.v, '%{other:2:5}bar'))
def test_stringSubstringFromTo3(self): self.assertEqual('oquu bar', interpol(self.v, '%{other:2:-1} bar'))
def test_stringWithTwoEmbeddedValues(self): self.assertEqual('foobar', interpol(self.v, '%{this}%{that}'))
def test_regexMatchReturn2(self): self.assertEqual('barbar', interpol(self.v, '%{some#[^-]+-([^-]+)$}bar'))
def test_stringWithTwoValues(self): self.assertEqual('foo bar', interpol(self.v, '%this %that'))
def test_stringWithEmbeddedValue(self): self.assertEqual('foobar', interpol(self.v, '%{this}bar'))
def test_stringWithOneValue(self): self.assertEqual('FOOQUUX bar', interpol(self.v, '%other_joo bar'))
def test_stringWithOneValue(self): self.assertEqual('foo bar', interpol(self.v, '%this bar'))
def eval(self, node): for cmd in self.cmds: self.addResult(self.callCommand(interpol(node.file_attrs, cmd)))
def test_regexReplacement2(self): self.assertEqual('XXXXXXXbar', interpol(self.v, '%{other#\w#X}bar'))
def test_stringSubstringFrom1(self): self.assertEqual('o bar', interpol(self.v, '%this:2 bar'))
def test_regexMatchReturn1(self): self.assertEqual('foobar', interpol(self.v, '%{some#[^-]+}bar'))
def test_patient(self,patient_id): """returns True or False depending on the success of creating a synthetic electrode interpolation NIfTI file. @param patient_id: Sample patient ID @type patient_id: string @rtype: bool """ try: preprocess_start = time.clock() # Load the test coordinates data = self.load_data() # Load the segmentation file seg_filename = '%s/%s_unburied_electrode_seg.nii.gz'%( DATA_DIR, patient_id ) seg = nib.load(path.expanduser(seg_filename)) seg_data = seg.get_data() # Initialize the result 3d image matrix res = np.zeros(seg_data.shape) # Set the output file name out_filename = seg_filename[:-35] + '%s_interpol.nii.gz'%patient_id # Interpolate on the 2-3 corners grid = data[patient_id]["1"]["grid_config"] M = int(grid.split('x')[0]) N = int(grid.split('x')[1]) radius = 0.2 * 10 print 'Preprocessing took: %s ms'%( (time.clock()-preprocess_start)*1000 ) interpol_start = time.clock() if M == 1 or N == 1: pairs = interpol(data[patient_id]["1"]["A"], data[patient_id]["1"]["B"],[], M,N) else: pairs = interpol(data[patient_id]["1"]["A"], data[patient_id]["1"]["B"], data[patient_id]["1"]["C"], M,N) print 'Interpolation took: %s ms'%( (time.clock()-interpol_start)*1000 ) nib_start = time.clock() # Create spheres of radius for k,v in pairs.items(): res[v[0]-radius:v[0]+radius, v[1]-radius:v[1]+radius, v[2]-radius:v[2]+radius] = 1 # Save res as new output result file res_nifti = nib.Nifti1Image(res,seg.get_affine()) nib.save(res_nifti,path.expanduser(out_filename)) print 'Postprocessing (which includes creating the final NIfTI \ file) took: %s ms'%((time.clock()-nib_start)*1000) return True except Exception, e: print str(e) return False
skip_header=1) kd2 = np.genfromtxt('video1_20170721_000052_918.txt', delimiter='\t', skip_header=1) for p in range(len(kd1)): #ins Bogenmaß umrechnen kd1[p][1] = 360 - kd1[p][1] kd1[p][1] = kd1[p][1] * np.pi / 180 kd1[p][3] = kd1[p][3] * np.pi / 180 for p in range(len(kd2)): kd2[p][1] = 360 - kd2[p][1] kd2[p][1] = kd2[p][1] * np.pi / 180 kd2[p][3] = kd2[p][3] * np.pi / 180 for qw in range(10): #10mal for i, Dt in enumerate(w): #die Werte in w als versatz testen kd2i = deltaT(kd2, Dt) #verstaz addieren kd1i, kd2i = interpol(kd1, kd2i) #mit versatz interpolieren if kd1i is None: fehler = np.inf else: sp = schnittp(kd1i, kd2i) #schnittpunkte der Geraden berechnen fehler = 0 for loop in range(len(sp[0])): fehler += ((sp[1][loop][0] - sp[0][loop][0])**2 + (sp[1][loop][1] - sp[0][loop][1])**2 + (sp[1][loop][2] - sp[0][loop][2])**2 ) #Abstand der Punkte berechnen feher = fehler / len(sp[0]) a[i] = [Dt, fehler] #fehler in Array eintragen #print(a) h = min(a[:, 1]) #aus a und w neues w erstellen #print(h)
def test_stringSubstringFromTo1(self): self.assertEqual('oqu bar', interpol(self.v, '%other:2:5 bar'))
def test_stringEmbeddedSubstringFrom2(self): self.assertEqual('obar', interpol(self.v, '%{this:2}bar'))
def interpolateNode(self, node): return interpol(node.file_attrs, self.config)