Skip to content

Commit

Permalink
Set line length to 119 for black and pylint
Browse files Browse the repository at this point in the history
  • Loading branch information
torbsorb authored and SatjaSivcev committed Oct 30, 2020
1 parent f4f12fd commit 6d97017
Show file tree
Hide file tree
Showing 26 changed files with 325 additions and 326 deletions.
2 changes: 1 addition & 1 deletion .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ max-locals=16
max-returns=9

[FORMAT]
max-line-length=120
max-line-length=119
2 changes: 1 addition & 1 deletion continuous-integration/lint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ pythonFiles=$(find "$SOURCE_DIR" -name '*.py' -not -path "*/ur_hand_eye_calibrat

echo Running black on:
echo "$pythonFiles"
black --check --diff $pythonFiles || exit $?
black --config="$ROOT_DIR/pyproject.toml" --check --diff $pythonFiles || exit $?

echo Running flake8 on:
echo "$pythonFiles"
Expand Down
2 changes: 2 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[tool.black]
line-length = 119
16 changes: 4 additions & 12 deletions source/applications/advanced/color_balance.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,7 @@ def _set_settings(dimension, iris, exposure_time, brightness, gain):
settings.brightness = brightness
settings.gain = gain
else:
raise ValueError(
f"The dimension value should be '3d' or '2d', got: '{dimension}'"
)
raise ValueError(f"The dimension value should be '3d' or '2d', got: '{dimension}'")

return settings

Expand Down Expand Up @@ -195,16 +193,10 @@ def _color_balance_calibration(camera, settings_3d):
f"{int(mean_color.blue)} "
)
)
if int(mean_color.green) == int(mean_color.red) and int(
mean_color.green
) == int(mean_color.blue):
if int(mean_color.green) == int(mean_color.red) and int(mean_color.green) == int(mean_color.blue):
break
corrected_red_balance = (
camera.settings.red_balance * mean_color.green / mean_color.red
)
corrected_blue_balance = (
camera.settings.blue_balance * mean_color.green / mean_color.blue
)
corrected_red_balance = camera.settings.red_balance * mean_color.green / mean_color.red
corrected_blue_balance = camera.settings.blue_balance * mean_color.green / mean_color.blue
_display_rgb(rgb, "RGB image after color balance (3D capture)")

return (corrected_red_balance, corrected_blue_balance)
Expand Down
4 changes: 1 addition & 3 deletions source/applications/advanced/create_depth_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@ def _main():
depth_map = np.dstack([point_cloud["z"]])

depth_map_uint8 = (
(depth_map - np.nanmin(depth_map))
/ (np.nanmax(depth_map) - np.nanmin(depth_map))
* 255
(depth_map - np.nanmin(depth_map)) / (np.nanmax(depth_map) - np.nanmin(depth_map)) * 255
).astype(np.uint8)

# Applying color map
Expand Down
19 changes: 5 additions & 14 deletions source/applications/advanced/downsample.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@ def _gridsum(matrix, downsampling_factor):
Returns:
Matrix reshaped and summed in second direction.
"""
return _sumline(
np.transpose(_sumline(matrix, downsampling_factor)), downsampling_factor
)
return _sumline(np.transpose(_sumline(matrix, downsampling_factor)), downsampling_factor)


def _sumline(matrix, downsampling_factor):
Expand All @@ -41,9 +39,7 @@ def _sumline(matrix, downsampling_factor):
Matrix reshaped and summed in first direction.
"""
return np.transpose(
np.nansum(
np.transpose(np.transpose(matrix).reshape(-1, downsampling_factor)), 0
).reshape(
np.nansum(np.transpose(np.transpose(matrix).reshape(-1, downsampling_factor)), 0).reshape(
int(np.shape(np.transpose(matrix))[0]),
int(np.shape(np.transpose(matrix))[1] / downsampling_factor),
)
Expand All @@ -69,12 +65,8 @@ def _downsample(xyz, rgb, contrast, downsampling_factor):
"""

# Checking if downsampling_factor is ok
if fmod(rgb.shape[0], downsampling_factor) or fmod(
rgb.shape[1], downsampling_factor
):
raise ValueError(
"Downsampling factor has to be a factor of point cloud width (1920) and height (1200)."
)
if fmod(rgb.shape[0], downsampling_factor) or fmod(rgb.shape[1], downsampling_factor):
raise ValueError("Downsampling factor has to be a factor of point cloud width (1920) and height (1200).")

rgb_new = np.zeros(
(
Expand All @@ -86,8 +78,7 @@ def _downsample(xyz, rgb, contrast, downsampling_factor):
)
for i in range(3):
rgb_new[:, :, i] = (
(np.transpose(_gridsum(rgb[:, :, i], downsampling_factor)))
/ (downsampling_factor * downsampling_factor)
(np.transpose(_gridsum(rgb[:, :, i], downsampling_factor))) / (downsampling_factor * downsampling_factor)
).astype(np.uint8)

contrast[np.isnan(xyz[:, :, 2])] = 0
Expand Down
9 changes: 2 additions & 7 deletions source/applications/advanced/gamma_correction.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,7 @@ def _options():
"""
parser = argparse.ArgumentParser(
description=(
"Capture 2D image and apply gamma correction\n"
"Example:\n\t $ python gamma_correction.py 2"
),
description=("Capture 2D image and apply gamma correction\n" "Example:\n\t $ python gamma_correction.py 2"),
formatter_class=argparse.RawTextHelpFormatter,
)

Expand All @@ -44,9 +41,7 @@ def adjust_gamma(image, gamma: float):
# build a lookup table mapping the pixel values [0, 255] to
# their adjusted gamma values
inv_gamma = 1.0 / gamma
table = np.array(
[((i / 255.0) ** inv_gamma) * 255 for i in np.arange(0, 256)]
).astype("uint8")
table = np.array([((i / 255.0) ** inv_gamma) * 255 for i in np.arange(0, 256)]).astype("uint8")
# apply gamma correction using the lookup table
return cv2.LUT(image, table)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ def _acquire_checkerboard_frame(camera):

def _enter_robot_pose(index):
inputted = input(
f"Enter pose with id={index} (a line with 16 space separated values"
" describing 4x4 row-major matrix):"
f"Enter pose with id={index} (a line with 16 space separated values" " describing 4x4 row-major matrix):"
)
elements = inputted.split(maxsplit=15)
data = np.array(elements, dtype=np.float64).reshape((4, 4))
Expand All @@ -38,9 +37,7 @@ def _main():
calibrate = False

while not calibrate:
command = input(
"Enter command, p (to add robot pose) or c (to perform calibration):"
).strip()
command = input("Enter command, p (to add robot pose) or c (to perform calibration):").strip()
if command == "p":
try:
robot_pose = _enter_robot_pose(current_pose_id)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,12 +232,8 @@ def roll_pitch_yaw_to_rotation_matrix(rpy_list):
"""
for rotation in rpy_list:
rotation_matrix = R.from_euler(
rotation["convention"].value, rotation["roll_pitch_yaw"]
).as_matrix()
print(
f"Rotation Matrix from Roll-Pitch-Yaw angles ({rotation['convention'].name}):"
)
rotation_matrix = R.from_euler(rotation["convention"].value, rotation["roll_pitch_yaw"]).as_matrix()
print(f"Rotation Matrix from Roll-Pitch-Yaw angles ({rotation['convention'].name}):")
print(f"{rotation_matrix}")


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,17 @@
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

import sys
sys.path.append('..')

sys.path.append("..")

import struct
from rtde import serialize


class CSVBinaryWriter(object):

def __init__(self, file, names, types, delimiter=' '):
def __init__(self, file, names, types, delimiter=" "):
if len(names) != len(types):
raise ValueError('List sizes are not identical.')
raise ValueError("List sizes are not identical.")
self.__file = file
self.__names = names
self.__types = types
Expand All @@ -43,75 +44,146 @@ def __init__(self, file, names, types, delimiter=' '):
self.__columns += size
if size > 1:
for j in range(size):
name = self.__names[i]+'_'+str(j)
name = self.__names[i] + "_" + str(j)
self.__header_names.append(name)
else:
name = self.__names[i]
self.__header_names.append(name)

def getType(self, vtype):
if(vtype == 'VECTOR3D'):
if vtype == "VECTOR3D":
return "DOUBLE" + self.__delimiter + "DOUBLE" + self.__delimiter + "DOUBLE"
elif(vtype == 'VECTOR6D'):
return "DOUBLE" + self.__delimiter + "DOUBLE" + self.__delimiter + "DOUBLE" + self.__delimiter + "DOUBLE" + self.__delimiter + "DOUBLE" + self.__delimiter + "DOUBLE"
elif(vtype == 'VECTOR6INT32'):
return "INT32" + self.__delimiter + "INT32" + self.__delimiter + "INT32" + self.__delimiter + "INT32" + self.__delimiter + "INT32" + self.__delimiter + "INT32"
elif(vtype == 'VECTOR6UINT32'):
return "UINT32" + self.__delimiter + "UINT32" + self.__delimiter + "UINT32" + self.__delimiter + "UINT32" + self.__delimiter + "UINT32" + self.__delimiter + "UINT32"
elif vtype == "VECTOR6D":
return (
"DOUBLE"
+ self.__delimiter
+ "DOUBLE"
+ self.__delimiter
+ "DOUBLE"
+ self.__delimiter
+ "DOUBLE"
+ self.__delimiter
+ "DOUBLE"
+ self.__delimiter
+ "DOUBLE"
)
elif vtype == "VECTOR6INT32":
return (
"INT32"
+ self.__delimiter
+ "INT32"
+ self.__delimiter
+ "INT32"
+ self.__delimiter
+ "INT32"
+ self.__delimiter
+ "INT32"
+ self.__delimiter
+ "INT32"
)
elif vtype == "VECTOR6UINT32":
return (
"UINT32"
+ self.__delimiter
+ "UINT32"
+ self.__delimiter
+ "UINT32"
+ self.__delimiter
+ "UINT32"
+ self.__delimiter
+ "UINT32"
+ self.__delimiter
+ "UINT32"
)
else:
return str(vtype)


def writeheader(self):
#Header names
headerStr=str("")
# Header names
headerStr = str("")
for i in range(len(self.__header_names)):
if(i != 0):
if i != 0:
headerStr += self.__delimiter

headerStr += self.__header_names[i]

headerStr += "\n"
self.__file.write(struct.pack(str(len(headerStr)) + 's', headerStr))
self.__file.write(struct.pack(str(len(headerStr)) + "s", headerStr))

#Header types
typeStr=str("")
# Header types
typeStr = str("")
for i in range(len(self.__names)):
if(i != 0):
if i != 0:
typeStr += self.__delimiter

typeStr += self.getType(self.__types[i])

typeStr += "\n"
self.__file.write(struct.pack(str(len(typeStr)) + 's', typeStr))
self.__file.write(struct.pack(str(len(typeStr)) + "s", typeStr))


def packToBinary(self, vtype, value):
print(vtype)
if(vtype == 'BOOL'):
if vtype == "BOOL":
print("isBOOL" + str(value))
if(vtype == 'UINT8'):
if vtype == "UINT8":
print("isUINT8" + str(value))
elif(vtype == 'INT32'):
elif vtype == "INT32":
print("isINT32" + str(value))
elif(vtype == 'INT64'):
elif vtype == "INT64":
print("isINT64" + str(value))
elif(vtype == 'UINT32'):
elif vtype == "UINT32":
print("isUINT32" + str(value))
elif(vtype == 'UINT64'):
elif vtype == "UINT64":
print("isUINT64" + str(value))
elif(vtype == 'DOUBLE'):
elif vtype == "DOUBLE":
print("isDOUBLE" + str(value) + str(type(value)) + str(sys.getsizeof(value)))
elif(vtype == 'VECTOR3D'):
print("isVECTOR3D" + str(value[0]) + ","+ str(value[1]) + ","+ str(value[2]))
elif(vtype == 'VECTOR6D'):
print("isVECTOR6D" + str(value[0]) + ","+ str(value[1]) + ","+ str(value[2]) + ","+ str(value[3]) + ","+ str(value[4]) + ","+ str(value[5]))
elif(vtype == 'VECTOR6INT32'):
print("isVECTOR6INT32" + str(value[0]) + ","+ str(value[1]) + ","+ str(value[2]) + ","+ str(value[3]) + ","+ str(value[4]) + ","+ str(value[5]))
elif(vtype == 'VECTOR6UINT32'):
print("isVECTOR6UINT32" + str(value[0]) + ","+ str(value[1]) + ","+ str(value[2]) + ","+ str(value[3]) + ","+ str(value[4]) + ","+ str(value[5]))
elif vtype == "VECTOR3D":
print("isVECTOR3D" + str(value[0]) + "," + str(value[1]) + "," + str(value[2]))
elif vtype == "VECTOR6D":
print(
"isVECTOR6D"
+ str(value[0])
+ ","
+ str(value[1])
+ ","
+ str(value[2])
+ ","
+ str(value[3])
+ ","
+ str(value[4])
+ ","
+ str(value[5])
)
elif vtype == "VECTOR6INT32":
print(
"isVECTOR6INT32"
+ str(value[0])
+ ","
+ str(value[1])
+ ","
+ str(value[2])
+ ","
+ str(value[3])
+ ","
+ str(value[4])
+ ","
+ str(value[5])
)
elif vtype == "VECTOR6UINT32":
print(
"isVECTOR6UINT32"
+ str(value[0])
+ ","
+ str(value[1])
+ ","
+ str(value[2])
+ ","
+ str(value[3])
+ ","
+ str(value[4])
+ ","
+ str(value[5])
)

def writerow(self, data_object):
self.__file.write(data_object)


Loading

0 comments on commit 6d97017

Please sign in to comment.