How to use bundle_length method in hypothesis

Best Python code snippet using hypothesis

test_qbx.py

Source:test_qbx.py Github

copy

Full Screen

1import itertools2import numpy as np3from dipy.segment.clustering import QuickBundlesX4from dipy.segment.metric import AveragePointwiseEuclideanMetric5from dipy.tracking.streamline import set_number_of_points6from dipy.data import get_data7import nibabel.trackvis as tv8def straight_bundle(nb_streamlines=1, nb_pts=30, step_size=1,9 radius=1, rng=np.random.RandomState(42)):10 bundle = []11 bundle_length = step_size * nb_pts12 Z = -np.linspace(0, bundle_length, nb_pts)13 for k in range(nb_streamlines):14 theta = rng.rand() * (2*np.pi)15 r = radius * rng.rand()16 Xk = np.ones(nb_pts) * (r * np.cos(theta))17 Yk = np.ones(nb_pts) * (r * np.sin(theta))18 Zk = Z.copy()19 bundle.append(np.c_[Xk, Yk, Zk])20 return bundle21def bearing_bundles(nb_balls=6, bearing_radius=2):22 bundles = []23 for theta in np.linspace(0, 2*np.pi, nb_balls, endpoint=False):24 x = bearing_radius * np.cos(theta)25 y = bearing_radius * np.sin(theta)26 bundle = np.array(straight_bundle(nb_streamlines=100))27 bundle += (x, y, 0)28 bundles.append(bundle)29 return bundles30def streamlines_in_circle(nb_streamlines=1, nb_pts=30, step_size=1,31 radius=1):32 bundle = []33 bundle_length = step_size * nb_pts34 Z = np.linspace(0, bundle_length, nb_pts)35 theta = 036 for theta in np.linspace(0, 2*np.pi, nb_streamlines, endpoint=False):37 Xk = np.ones(nb_pts) * (radius * np.cos(theta))38 Yk = np.ones(nb_pts) * (radius * np.sin(theta))39 Zk = Z.copy()40 bundle.append(np.c_[Xk, Yk, Zk])41 return bundle42def streamlines_parallel(nb_streamlines=1, nb_pts=30, step_size=1,43 delta=1):44 bundle = []45 bundle_length = step_size * nb_pts46 Z = np.linspace(0, bundle_length, nb_pts)47 for x in delta*np.arange(0, nb_streamlines):48 Xk = np.ones(nb_pts) * x49 Yk = np.zeros(nb_pts)50 Zk = Z.copy()51 bundle.append(np.c_[Xk, Yk, Zk])52 return bundle53def simulated_bundle(no_streamlines=10, waves=False, no_pts=12):54 t = np.linspace(-10, 10, 200)55 # parallel waves or parallel lines56 bundle = []57 for i in np.linspace(-5, 5, no_streamlines):58 if waves:59 pts = np.vstack((np.cos(t), t, i * np.ones(t.shape))).T60 else:61 pts = np.vstack((np.zeros(t.shape), t, i * np.ones(t.shape))).T62 pts = set_number_of_points(pts, no_pts)63 bundle.append(pts)64 return bundle65def fornix_streamlines(no_pts=12):66 fname = get_data('fornix')67 streams, hdr = tv.read(fname)68 streamlines = [set_number_of_points(i[0], no_pts) for i in streams]69 return streamlines70def test_3D_segments():71 points = np.array([[[1, 0, 0],72 [1, 1, 0]],73 [[3, 1, 0],74 [3, 0, 0]],75 [[2, 0, 0],76 [2, 1, 0]],77 [[5, 1, 0],78 [5, 0, 0]],79 [[5.5, 0, 0],80 [5.5, 1, 0]]], dtype="f4")81 thresholds = [4, 2, 1]82 qbx_class = QuickBundlesX(thresholds)83 qbx = qbx_class.cluster(points)84 print qbx85def test_3D_points():86 points = np.array([[[1, 0, 0]],87 [[3, 0, 0]],88 [[2, 0, 0]],89 [[5, 0, 0]],90 [[5.5, 0, 0]]], dtype="f4")91 thresholds = [4, 2, 1]92 qbx_class = QuickBundlesX(thresholds)93 qbx = qbx_class.cluster(points)94 print qbx95def test_with_simulated_bundles():96 streamlines = simulated_bundle(3, False, 2)97 from dipy.viz import actor, window98 renderer = window.Renderer()99 bundle_actor = actor.line(streamlines)100 renderer.add(bundle_actor)101 window.show(renderer)102 thresholds = [10, 3, 1]103 qbx_class = QuickBundlesX(thresholds)104 qbx = qbx_class.cluster(streamlines)105 print qbx106 renderer.clear()107 for level in range(len(thresholds) + 1):108 clusters = qbx.get_clusters(level)109 clusters_actor = actor.line(clusters.centroids)110 renderer.add(clusters_actor)111 window.show(renderer)112 renderer.clear()113 from ipdb import set_trace114 set_trace()115def test_with_simulated_bundles2():116 # Generate synthetic streamlines117 bundles = bearing_bundles(4, 2)118 bundles.append(straight_bundle(1))119 streamlines = list(itertools.chain(*bundles))120 from dipy.viz import actor, window121 renderer = window.Renderer()122 bundle_actor = actor.line(streamlines)123 renderer.add(bundle_actor)124 window.show(renderer)125 thresholds = [10, 2, 1]126 qbx_class = QuickBundlesX(thresholds)127 print "Adding streamlines..."128 qbx = qbx_class.cluster(streamlines)129 renderer.clear()130 # for level in range(len(thresholds) + 1):131 # clusters = qbx.get_clusters(level)132 # clusters_actor = actor.line(clusters.centroids)133 # renderer.add(clusters_actor)134 # window.show(renderer)135 # renderer.clear()136 from dipy.viz.clustering import show_hierarchical_clusters137 tree = qbx.get_tree_cluster_map()138 tree.refdata = streamlines139 show_hierarchical_clusters(tree, show_circles=True)140 from ipdb import set_trace141 set_trace()142def color_tree(tree, bg=(1, 1, 1)):143 import colorsys144 from dipy.viz.colormap import distinguishable_colormap145 global colormap146 colormap = iter(distinguishable_colormap(bg=bg, exclude=[(1., 1., 0.93103448)]))147 def _color_subtree(node, color=None, level=0):148 global colormap149 node.color = color150 max_luminosity = 0151 if color is not None:152 hls = np.asarray(colorsys.rgb_to_hls(*color))153 max_luminosity = hls[1]154 #luminosities = np.linspace(0.3, 0.8, len(node.children))155 children_sizes = map(len, node.children)156 indices = np.argsort(children_sizes)[::-1]157 luminosities = np.linspace(max_luminosity, 0.2, len(node.children))158 offsets = np.linspace(-0.2, 0.2, len(node.children))159 #for child, luminosity, offset in zip(node.children, luminosities, offsets):160 for idx, luminosity, offset in zip(indices, luminosities, offsets):161 child = node.children[idx]162 if level == 0:163 color = next(colormap)164 _color_subtree(child, color, level+1)165 else:166 hls = np.asarray(colorsys.rgb_to_hls(*color))167 #if hls[1] > 0.8:168 # hls[1] -= 0.3169 #elif hls[1] < 0.3:170 # hls[1] += 0.3171 rbg = colorsys.hls_to_rgb(hls[0], luminosity, hls[2])172 _color_subtree(child, np.asarray(rbg), level+1)173 _color_subtree(tree.root)174def test_show_qbx_tree():175 filename = "/home/marc/research/dat/streamlines/MPI_Camille/myBrain.trk"176 import nibabel as nib177 print "Loading streamlines..."178 import os179 tmp_filename = "/tmp/streamlines.npz"180 if os.path.isfile(tmp_filename):181 streamlines = nib.streamlines.compact_list.load_compact_list(tmp_filename)182 else:183 streamlines = nib.streamlines.load(filename).streamlines184 nib.streamlines.compact_list.save_compact_list(tmp_filename, streamlines)185 streamlines = streamlines[::10].copy()186 streamlines._data -= np.mean(streamlines._data, axis=0)187 print "Displaying {} streamlines...".format(len(streamlines))188 #from dipy.viz import actor, window189 #renderer = window.Renderer()190 #bundle_actor = actor.line(streamlines)191 #renderer.add(bundle_actor)192 #window.show(renderer)193 thresholds = [40, 30, 25]#, 20, 15]194 qbx_class = QuickBundlesX(thresholds)195 print "Clustering {} streamlines ({})...".format(len(streamlines), thresholds)196 qbx = qbx_class.cluster(streamlines)197 print "Displaying clusters graph..."198 tree = qbx.get_tree_cluster_map()199 tree.refdata = streamlines200 color_tree(tree)201 from dipy.viz.clustering import show_clusters_graph202 show_clusters_graph(tree)203def test_show_qbx():204 filename = "/home/marc/research/dat/streamlines/MPI_Camille/myBrain.trk"205 import nibabel as nib206 print "Loading streamlines..."207 import os208 tmp_filename = "/tmp/streamlines.npz"209 if os.path.isfile(tmp_filename):210 streamlines = nib.streamlines.compact_list.load_compact_list(tmp_filename)211 else:212 streamlines = nib.streamlines.load(filename).streamlines213 nib.streamlines.compact_list.save_compact_list(tmp_filename, streamlines)214 streamlines = streamlines[::10].copy()215 streamlines._data -= np.mean(streamlines._data, axis=0)216 # Rotate brain to see a sagital view.217 from nibabel.affines import apply_affine218 from dipy.core.geometry import rodrigues_axis_rotation219 R1 = np.eye(4)220 R1[:3, :3] = rodrigues_axis_rotation((0, 1, 0), theta=90)221 R2 = np.eye(4)222 R2[:3, :3] = rodrigues_axis_rotation((0, 0, 1), theta=90)223 R = np.dot(R2, R1)224 streamlines._data = apply_affine(R, streamlines._data)225 #print "Displaying {} streamlines...".format(len(streamlines))226 #from dipy.viz import actor, window227 #renderer = window.Renderer()228 #bundle_actor = actor.line(streamlines)229 #renderer.add(bundle_actor)230 #window.show(renderer)231 thresholds = [40, 30, 25]#, 20, 15]232 qbx_class = QuickBundlesX(thresholds)233 print "Clustering {} streamlines ({})...".format(len(streamlines), thresholds)234 qbx = qbx_class.cluster(streamlines)235 clusters = qbx.get_clusters(len(thresholds))236 clusters.refdata = streamlines237 from dipy.viz.clustering import show_clusters238 print "Displaying {} clusters...".format(len(clusters))239 tree = qbx.get_tree_cluster_map()240 tree.refdata = streamlines241 color_tree(tree)242 for level in range(1, len(thresholds) + 1):243 print level, thresholds[level-1]244 clusters = tree.get_clusters(level)245 clusters.refdata = streamlines246 show_clusters(clusters)247if __name__ == '__main__':248 #test_with_simulated_bundles2()249 #test_show_qbx_tree()...

Full Screen

Full Screen

second_round_bundle_generator.py

Source:second_round_bundle_generator.py Github

copy

Full Screen

...70 bundle_length = 071 if self.student.b_m_timetable_student.exists():72 bundle_length = len(list(self.student.b_m_timetable_student.get().get_tutorials_list()))73 else:74 bundle_length = self.student.preferences.get_bundle_length()75 violating_dict = self.__get_violating_timeslot_dict(bundle_length)76 rank = 177 for num_violations in violating_dict:78 all_bundles_num_violation = self.create_valid_bundles(num_violations,violating_dict)79 for bundle in all_bundles_num_violation:80 new_pref_list.add_item(rank,frozenset(bundle))81 rank += 182 return new_pref_list83 def __additional_rounds_in_second_round(self,with_course_constraint):84 new_pref_list = PreferenceList()85 bundles = self.create_no_constraint_prefs(self.interested_tutorials,with_course_constraint)86 rank = 187 for bundle in bundles:88 new_pref_list.add_item(rank, frozenset(bundle))...

Full Screen

Full Screen

HexagonalBundle.py

Source:HexagonalBundle.py Github

copy

Full Screen

1from Molecule import Molecule2from ..geometry import shapes3import numpy as np4from math import ceil5class HexagonalBundle(Molecule):6 def __init__(self):7 super(HexagonalBundle,self).__init__() #Need to call parent class' constructor8 self.name = 'HexagonalBundle'9 # def build(self,nstems,nlayers,diameter=1.0,topType=0,bottomType=2,middleType=1):10 def build(self,bundle_radius,bundle_length,bead_diameter=1.0,topType=0,bottomType=2,middleType=1,base_gridsize=500):11 # pos = shapes.hexagonalspiral.positions(nstems,diameter)12 kwargs = {}13 kwargs['nx'] = base_gridsize14 kwargs['ny'] = base_gridsize15 kwargs['nz'] = 116 kwargs['diameter'] = bead_diameter17 kwargs['topType'] = topType18 kwargs['middleType'] = topType19 kwargs['bottomType'] = topType20 kwargs['alternate_z'] = True21 molData = shapes.hexagonal.surface(**kwargs)22 pos = np.array([molData['x'], molData['y'], molData['z']]).T23 idex = pos.shape[0]/224 idex = base_gridsize*base_gridsize/2 + base_gridsize/225 cpos = pos[idex]26 dist = np.sqrt(np.sum(np.square(cpos - pos),axis=1))27 28 mask = ( dist<=bundle_radius )29 pos = pos[mask]30 pos -= cpos31 new_pos = []32 bonds = []33 types = [topType for i in range(pos.shape[0])]34 beadj = pos.shape[0]35 bundle_length = int(bundle_length)36 for pi,p in enumerate(pos):37 beadi = pi38 for l in range(1,bundle_length):39 new_pos.append([p[0],p[1],p[2]+l*bead_diameter])40 bonds.append([beadi,beadj])41 types.append(middleType)42 beadi = beadj43 beadj = beadj + 144 types[-1] = bottomType45 pos = np.append(pos,new_pos,axis=0)46 types = np.array(types)47 48 49 molData = {}50 molData['x'] = pos[:,0]51 molData['y'] = pos[:,1]52 molData['z'] = pos[:,2]53 molData['types'] = types54 molData['bonds'] = bonds...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run hypothesis automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful