Conditions | 2 |
Total Lines | 55 |
Lines | 0 |
Ratio | 0 % |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | import os.path |
||
19 | def setUp(self): |
||
20 | self.useLocal = False |
||
21 | |||
22 | if self.useLocal: |
||
23 | self.tempdir = tempdir = '.' |
||
24 | else: |
||
25 | self.tempdir = tempdir = mkdtemp(prefix='patty-analytics') |
||
26 | |||
27 | self.drivemapLas = os.path.join(tempdir, 'testDriveMap.las') |
||
28 | self.sourcelas = os.path.join(tempdir, 'testSource.las') |
||
29 | self.footprint_csv = os.path.join(tempdir, 'testFootprint.csv') |
||
30 | self.foutlas = os.path.join(tempdir, 'testOutput.las') |
||
31 | |||
32 | self.min = -10 |
||
33 | self.max = 10 |
||
34 | self.num_rows = 1000 |
||
35 | |||
36 | # Create plane with a pyramid |
||
37 | dm_pct = 0.5 |
||
38 | dm_rows = np.round(self.num_rows * dm_pct) |
||
39 | dm_min = self.min * dm_pct |
||
40 | dm_max = self.max * dm_pct |
||
41 | |||
42 | delta = dm_max / dm_rows |
||
43 | shape_side = dm_max - dm_min |
||
44 | |||
45 | dm_offset = [0, 0, 0] |
||
46 | self.dense_obj_offset = [3, 2, -(1 + shape_side / 2)] |
||
47 | |||
48 | # make drivemap |
||
49 | plane_row = np.linspace( |
||
50 | start=self.min, stop=self.max, num=self.num_rows) |
||
51 | plane_points = cartesian((plane_row, plane_row, [0])) |
||
52 | |||
53 | shape_points, footprint = make_tri_pyramid_with_base( |
||
54 | shape_side, delta, dm_offset) |
||
55 | np.savetxt(self.footprint_csv, footprint, fmt='%.3f', delimiter=',') |
||
56 | |||
57 | dm_points = np.vstack([plane_points, shape_points]) |
||
58 | plane_grid = np.zeros((dm_points.shape[0], 6), dtype=np.float32) |
||
59 | plane_grid[:, 0:3] = dm_points |
||
60 | |||
61 | self.drivemap_pc = pcl.PointCloudXYZRGB(plane_grid) |
||
62 | self.drivemap_pc = downsample_voxel(self.drivemap_pc, |
||
63 | voxel_size=delta * 20) |
||
64 | # utils.set_registration(self.drivemap_pc) |
||
65 | utils.save(self.drivemap_pc, self.drivemapLas) |
||
66 | |||
67 | # Create a simple pyramid |
||
68 | dense_grid = np.zeros((shape_points.shape[0], 6), dtype=np.float32) |
||
69 | dense_grid[:, 0:3] = shape_points + self.dense_obj_offset |
||
70 | |||
71 | self.source_pc = pcl.PointCloudXYZRGB(dense_grid) |
||
72 | self.source_pc = downsample_voxel(self.source_pc, voxel_size=delta * 5) |
||
73 | utils.save(self.source_pc, self.sourcelas) |
||
74 | |||
105 |