repository_name stringlengths 7 55 | func_path_in_repository stringlengths 4 223 | func_name stringlengths 1 134 | whole_func_string stringlengths 75 104k | language stringclasses 1
value | func_code_string stringlengths 75 104k | func_code_tokens listlengths 19 28.4k | func_documentation_string stringlengths 1 46.9k | func_documentation_tokens listlengths 1 1.97k | split_name stringclasses 1
value | func_code_url stringlengths 87 315 |
|---|---|---|---|---|---|---|---|---|---|---|
poppy-project/pypot | pypot/primitive/manager.py | PrimitiveManager.stop | def stop(self):
""" Stop the primitive manager. """
for p in self.primitives[:]:
p.stop()
StoppableLoopThread.stop(self) | python | def stop(self):
""" Stop the primitive manager. """
for p in self.primitives[:]:
p.stop()
StoppableLoopThread.stop(self) | [
"def",
"stop",
"(",
"self",
")",
":",
"for",
"p",
"in",
"self",
".",
"primitives",
"[",
":",
"]",
":",
"p",
".",
"stop",
"(",
")",
"StoppableLoopThread",
".",
"stop",
"(",
"self",
")"
] | Stop the primitive manager. | [
"Stop",
"the",
"primitive",
"manager",
"."
] | train | https://github.com/poppy-project/pypot/blob/d9c6551bbc87d45d9d1f0bc15e35b616d0002afd/pypot/primitive/manager.py#L76-L81 |
poppy-project/pypot | pypot/vrep/io.py | VrepIO.load_scene | def load_scene(self, scene_path, start=False):
""" Loads a scene on the V-REP server.
:param str scene_path: path to a V-REP scene file
:param bool start: whether to directly start the simulation after loading the scene
.. note:: It is assumed that the scene file is always available on... | python | def load_scene(self, scene_path, start=False):
""" Loads a scene on the V-REP server.
:param str scene_path: path to a V-REP scene file
:param bool start: whether to directly start the simulation after loading the scene
.. note:: It is assumed that the scene file is always available on... | [
"def",
"load_scene",
"(",
"self",
",",
"scene_path",
",",
"start",
"=",
"False",
")",
":",
"self",
".",
"stop_simulation",
"(",
")",
"if",
"not",
"os",
".",
"path",
".",
"exists",
"(",
"scene_path",
")",
":",
"raise",
"IOError",
"(",
"\"No such file or d... | Loads a scene on the V-REP server.
:param str scene_path: path to a V-REP scene file
:param bool start: whether to directly start the simulation after loading the scene
.. note:: It is assumed that the scene file is always available on the server side. | [
"Loads",
"a",
"scene",
"on",
"the",
"V",
"-",
"REP",
"server",
"."
] | train | https://github.com/poppy-project/pypot/blob/d9c6551bbc87d45d9d1f0bc15e35b616d0002afd/pypot/vrep/io.py#L91-L108 |
poppy-project/pypot | pypot/vrep/io.py | VrepIO.get_motor_position | def get_motor_position(self, motor_name):
""" Gets the motor current position. """
return self.call_remote_api('simxGetJointPosition',
self.get_object_handle(motor_name),
streaming=True) | python | def get_motor_position(self, motor_name):
""" Gets the motor current position. """
return self.call_remote_api('simxGetJointPosition',
self.get_object_handle(motor_name),
streaming=True) | [
"def",
"get_motor_position",
"(",
"self",
",",
"motor_name",
")",
":",
"return",
"self",
".",
"call_remote_api",
"(",
"'simxGetJointPosition'",
",",
"self",
".",
"get_object_handle",
"(",
"motor_name",
")",
",",
"streaming",
"=",
"True",
")"
] | Gets the motor current position. | [
"Gets",
"the",
"motor",
"current",
"position",
"."
] | train | https://github.com/poppy-project/pypot/blob/d9c6551bbc87d45d9d1f0bc15e35b616d0002afd/pypot/vrep/io.py#L143-L147 |
poppy-project/pypot | pypot/vrep/io.py | VrepIO.set_motor_position | def set_motor_position(self, motor_name, position):
""" Sets the motor target position. """
self.call_remote_api('simxSetJointTargetPosition',
self.get_object_handle(motor_name),
position,
sending=True) | python | def set_motor_position(self, motor_name, position):
""" Sets the motor target position. """
self.call_remote_api('simxSetJointTargetPosition',
self.get_object_handle(motor_name),
position,
sending=True) | [
"def",
"set_motor_position",
"(",
"self",
",",
"motor_name",
",",
"position",
")",
":",
"self",
".",
"call_remote_api",
"(",
"'simxSetJointTargetPosition'",
",",
"self",
".",
"get_object_handle",
"(",
"motor_name",
")",
",",
"position",
",",
"sending",
"=",
"Tru... | Sets the motor target position. | [
"Sets",
"the",
"motor",
"target",
"position",
"."
] | train | https://github.com/poppy-project/pypot/blob/d9c6551bbc87d45d9d1f0bc15e35b616d0002afd/pypot/vrep/io.py#L149-L154 |
poppy-project/pypot | pypot/vrep/io.py | VrepIO.get_motor_force | def get_motor_force(self, motor_name):
""" Retrieves the force or torque applied to a joint along/about its active axis. """
return self.call_remote_api('simxGetJointForce',
self.get_object_handle(motor_name),
streaming=True) | python | def get_motor_force(self, motor_name):
""" Retrieves the force or torque applied to a joint along/about its active axis. """
return self.call_remote_api('simxGetJointForce',
self.get_object_handle(motor_name),
streaming=True) | [
"def",
"get_motor_force",
"(",
"self",
",",
"motor_name",
")",
":",
"return",
"self",
".",
"call_remote_api",
"(",
"'simxGetJointForce'",
",",
"self",
".",
"get_object_handle",
"(",
"motor_name",
")",
",",
"streaming",
"=",
"True",
")"
] | Retrieves the force or torque applied to a joint along/about its active axis. | [
"Retrieves",
"the",
"force",
"or",
"torque",
"applied",
"to",
"a",
"joint",
"along",
"/",
"about",
"its",
"active",
"axis",
"."
] | train | https://github.com/poppy-project/pypot/blob/d9c6551bbc87d45d9d1f0bc15e35b616d0002afd/pypot/vrep/io.py#L156-L160 |
poppy-project/pypot | pypot/vrep/io.py | VrepIO.set_motor_force | def set_motor_force(self, motor_name, force):
""" Sets the maximum force or torque that a joint can exert. """
self.call_remote_api('simxSetJointForce',
self.get_object_handle(motor_name),
force,
sending=True) | python | def set_motor_force(self, motor_name, force):
""" Sets the maximum force or torque that a joint can exert. """
self.call_remote_api('simxSetJointForce',
self.get_object_handle(motor_name),
force,
sending=True) | [
"def",
"set_motor_force",
"(",
"self",
",",
"motor_name",
",",
"force",
")",
":",
"self",
".",
"call_remote_api",
"(",
"'simxSetJointForce'",
",",
"self",
".",
"get_object_handle",
"(",
"motor_name",
")",
",",
"force",
",",
"sending",
"=",
"True",
")"
] | Sets the maximum force or torque that a joint can exert. | [
"Sets",
"the",
"maximum",
"force",
"or",
"torque",
"that",
"a",
"joint",
"can",
"exert",
"."
] | train | https://github.com/poppy-project/pypot/blob/d9c6551bbc87d45d9d1f0bc15e35b616d0002afd/pypot/vrep/io.py#L162-L167 |
poppy-project/pypot | pypot/vrep/io.py | VrepIO.get_object_position | def get_object_position(self, object_name, relative_to_object=None):
""" Gets the object position. """
h = self.get_object_handle(object_name)
relative_handle = (-1 if relative_to_object is None
else self.get_object_handle(relative_to_object))
return self.call... | python | def get_object_position(self, object_name, relative_to_object=None):
""" Gets the object position. """
h = self.get_object_handle(object_name)
relative_handle = (-1 if relative_to_object is None
else self.get_object_handle(relative_to_object))
return self.call... | [
"def",
"get_object_position",
"(",
"self",
",",
"object_name",
",",
"relative_to_object",
"=",
"None",
")",
":",
"h",
"=",
"self",
".",
"get_object_handle",
"(",
"object_name",
")",
"relative_handle",
"=",
"(",
"-",
"1",
"if",
"relative_to_object",
"is",
"None... | Gets the object position. | [
"Gets",
"the",
"object",
"position",
"."
] | train | https://github.com/poppy-project/pypot/blob/d9c6551bbc87d45d9d1f0bc15e35b616d0002afd/pypot/vrep/io.py#L169-L177 |
poppy-project/pypot | pypot/vrep/io.py | VrepIO.set_object_position | def set_object_position(self, object_name, position=[0, 0, 0]):
""" Sets the object position. """
h = self.get_object_handle(object_name)
return self.call_remote_api('simxSetObjectPosition',
h, -1, position,
sending=True) | python | def set_object_position(self, object_name, position=[0, 0, 0]):
""" Sets the object position. """
h = self.get_object_handle(object_name)
return self.call_remote_api('simxSetObjectPosition',
h, -1, position,
sending=True) | [
"def",
"set_object_position",
"(",
"self",
",",
"object_name",
",",
"position",
"=",
"[",
"0",
",",
"0",
",",
"0",
"]",
")",
":",
"h",
"=",
"self",
".",
"get_object_handle",
"(",
"object_name",
")",
"return",
"self",
".",
"call_remote_api",
"(",
"'simxSe... | Sets the object position. | [
"Sets",
"the",
"object",
"position",
"."
] | train | https://github.com/poppy-project/pypot/blob/d9c6551bbc87d45d9d1f0bc15e35b616d0002afd/pypot/vrep/io.py#L179-L185 |
poppy-project/pypot | pypot/vrep/io.py | VrepIO.get_object_handle | def get_object_handle(self, obj):
""" Gets the vrep object handle. """
if obj not in self._object_handles:
self._object_handles[obj] = self._get_object_handle(obj=obj)
return self._object_handles[obj] | python | def get_object_handle(self, obj):
""" Gets the vrep object handle. """
if obj not in self._object_handles:
self._object_handles[obj] = self._get_object_handle(obj=obj)
return self._object_handles[obj] | [
"def",
"get_object_handle",
"(",
"self",
",",
"obj",
")",
":",
"if",
"obj",
"not",
"in",
"self",
".",
"_object_handles",
":",
"self",
".",
"_object_handles",
"[",
"obj",
"]",
"=",
"self",
".",
"_get_object_handle",
"(",
"obj",
"=",
"obj",
")",
"return",
... | Gets the vrep object handle. | [
"Gets",
"the",
"vrep",
"object",
"handle",
"."
] | train | https://github.com/poppy-project/pypot/blob/d9c6551bbc87d45d9d1f0bc15e35b616d0002afd/pypot/vrep/io.py#L200-L205 |
poppy-project/pypot | pypot/vrep/io.py | VrepIO.get_collision_state | def get_collision_state(self, collision_name):
""" Gets the collision state. """
return self.call_remote_api('simxReadCollision',
self.get_collision_handle(collision_name),
streaming=True) | python | def get_collision_state(self, collision_name):
""" Gets the collision state. """
return self.call_remote_api('simxReadCollision',
self.get_collision_handle(collision_name),
streaming=True) | [
"def",
"get_collision_state",
"(",
"self",
",",
"collision_name",
")",
":",
"return",
"self",
".",
"call_remote_api",
"(",
"'simxReadCollision'",
",",
"self",
".",
"get_collision_handle",
"(",
"collision_name",
")",
",",
"streaming",
"=",
"True",
")"
] | Gets the collision state. | [
"Gets",
"the",
"collision",
"state",
"."
] | train | https://github.com/poppy-project/pypot/blob/d9c6551bbc87d45d9d1f0bc15e35b616d0002afd/pypot/vrep/io.py#L207-L211 |
poppy-project/pypot | pypot/vrep/io.py | VrepIO.get_collision_handle | def get_collision_handle(self, collision):
""" Gets a vrep collisions handle. """
if collision not in self._object_handles:
h = self._get_collision_handle(collision)
self._object_handles[collision] = h
return self._object_handles[collision] | python | def get_collision_handle(self, collision):
""" Gets a vrep collisions handle. """
if collision not in self._object_handles:
h = self._get_collision_handle(collision)
self._object_handles[collision] = h
return self._object_handles[collision] | [
"def",
"get_collision_handle",
"(",
"self",
",",
"collision",
")",
":",
"if",
"collision",
"not",
"in",
"self",
".",
"_object_handles",
":",
"h",
"=",
"self",
".",
"_get_collision_handle",
"(",
"collision",
")",
"self",
".",
"_object_handles",
"[",
"collision"... | Gets a vrep collisions handle. | [
"Gets",
"a",
"vrep",
"collisions",
"handle",
"."
] | train | https://github.com/poppy-project/pypot/blob/d9c6551bbc87d45d9d1f0bc15e35b616d0002afd/pypot/vrep/io.py#L216-L222 |
poppy-project/pypot | pypot/vrep/io.py | VrepIO.add_cube | def add_cube(self, name, position, sizes, mass):
""" Add Cube """
self._create_pure_shape(0, 239, sizes, mass, [0, 0])
self.set_object_position("Cuboid", position)
self.change_object_name("Cuboid", name) | python | def add_cube(self, name, position, sizes, mass):
""" Add Cube """
self._create_pure_shape(0, 239, sizes, mass, [0, 0])
self.set_object_position("Cuboid", position)
self.change_object_name("Cuboid", name) | [
"def",
"add_cube",
"(",
"self",
",",
"name",
",",
"position",
",",
"sizes",
",",
"mass",
")",
":",
"self",
".",
"_create_pure_shape",
"(",
"0",
",",
"239",
",",
"sizes",
",",
"mass",
",",
"[",
"0",
",",
"0",
"]",
")",
"self",
".",
"set_object_posit... | Add Cube | [
"Add",
"Cube"
] | train | https://github.com/poppy-project/pypot/blob/d9c6551bbc87d45d9d1f0bc15e35b616d0002afd/pypot/vrep/io.py#L231-L235 |
poppy-project/pypot | pypot/vrep/io.py | VrepIO.add_cylinder | def add_cylinder(self, name, position, sizes, mass, precision=[10, 10]):
""" Add Cylinder """
self._create_pure_shape(2, 239, sizes, mass, precision)
self.set_object_position("Cylinder", position)
self.change_object_name("Cylinder", name) | python | def add_cylinder(self, name, position, sizes, mass, precision=[10, 10]):
""" Add Cylinder """
self._create_pure_shape(2, 239, sizes, mass, precision)
self.set_object_position("Cylinder", position)
self.change_object_name("Cylinder", name) | [
"def",
"add_cylinder",
"(",
"self",
",",
"name",
",",
"position",
",",
"sizes",
",",
"mass",
",",
"precision",
"=",
"[",
"10",
",",
"10",
"]",
")",
":",
"self",
".",
"_create_pure_shape",
"(",
"2",
",",
"239",
",",
"sizes",
",",
"mass",
",",
"preci... | Add Cylinder | [
"Add",
"Cylinder"
] | train | https://github.com/poppy-project/pypot/blob/d9c6551bbc87d45d9d1f0bc15e35b616d0002afd/pypot/vrep/io.py#L243-L247 |
poppy-project/pypot | pypot/vrep/io.py | VrepIO.change_object_name | def change_object_name(self, old_name, new_name):
""" Change object name """
h = self._get_object_handle(old_name)
if old_name in self._object_handles:
self._object_handles.pop(old_name)
lua_code = "simSetObjectName({}, '{}')".format(h, new_name)
self._inject_lua_code... | python | def change_object_name(self, old_name, new_name):
""" Change object name """
h = self._get_object_handle(old_name)
if old_name in self._object_handles:
self._object_handles.pop(old_name)
lua_code = "simSetObjectName({}, '{}')".format(h, new_name)
self._inject_lua_code... | [
"def",
"change_object_name",
"(",
"self",
",",
"old_name",
",",
"new_name",
")",
":",
"h",
"=",
"self",
".",
"_get_object_handle",
"(",
"old_name",
")",
"if",
"old_name",
"in",
"self",
".",
"_object_handles",
":",
"self",
".",
"_object_handles",
".",
"pop",
... | Change object name | [
"Change",
"object",
"name"
] | train | https://github.com/poppy-project/pypot/blob/d9c6551bbc87d45d9d1f0bc15e35b616d0002afd/pypot/vrep/io.py#L255-L261 |
poppy-project/pypot | pypot/vrep/io.py | VrepIO._create_pure_shape | def _create_pure_shape(self, primitive_type, options, sizes, mass, precision):
""" Create Pure Shape """
lua_code = "simCreatePureShape({}, {}, {{{}, {}, {}}}, {}, {{{}, {}}})".format(
primitive_type, options, sizes[0], sizes[1], sizes[2], mass, precision[0], precision[1])
self._inje... | python | def _create_pure_shape(self, primitive_type, options, sizes, mass, precision):
""" Create Pure Shape """
lua_code = "simCreatePureShape({}, {}, {{{}, {}, {}}}, {}, {{{}, {}}})".format(
primitive_type, options, sizes[0], sizes[1], sizes[2], mass, precision[0], precision[1])
self._inje... | [
"def",
"_create_pure_shape",
"(",
"self",
",",
"primitive_type",
",",
"options",
",",
"sizes",
",",
"mass",
",",
"precision",
")",
":",
"lua_code",
"=",
"\"simCreatePureShape({}, {}, {{{}, {}, {}}}, {}, {{{}, {}}})\"",
".",
"format",
"(",
"primitive_type",
",",
"optio... | Create Pure Shape | [
"Create",
"Pure",
"Shape"
] | train | https://github.com/poppy-project/pypot/blob/d9c6551bbc87d45d9d1f0bc15e35b616d0002afd/pypot/vrep/io.py#L263-L267 |
poppy-project/pypot | pypot/vrep/io.py | VrepIO._inject_lua_code | def _inject_lua_code(self, lua_code):
""" Sends raw lua code and evaluate it wihtout any checking! """
msg = (ctypes.c_ubyte * len(lua_code)).from_buffer_copy(lua_code.encode())
self.call_remote_api('simxWriteStringStream', 'my_lua_code', msg) | python | def _inject_lua_code(self, lua_code):
""" Sends raw lua code and evaluate it wihtout any checking! """
msg = (ctypes.c_ubyte * len(lua_code)).from_buffer_copy(lua_code.encode())
self.call_remote_api('simxWriteStringStream', 'my_lua_code', msg) | [
"def",
"_inject_lua_code",
"(",
"self",
",",
"lua_code",
")",
":",
"msg",
"=",
"(",
"ctypes",
".",
"c_ubyte",
"*",
"len",
"(",
"lua_code",
")",
")",
".",
"from_buffer_copy",
"(",
"lua_code",
".",
"encode",
"(",
")",
")",
"self",
".",
"call_remote_api",
... | Sends raw lua code and evaluate it wihtout any checking! | [
"Sends",
"raw",
"lua",
"code",
"and",
"evaluate",
"it",
"wihtout",
"any",
"checking!"
] | train | https://github.com/poppy-project/pypot/blob/d9c6551bbc87d45d9d1f0bc15e35b616d0002afd/pypot/vrep/io.py#L269-L272 |
poppy-project/pypot | pypot/vrep/io.py | VrepIO.call_remote_api | def call_remote_api(self, func_name, *args, **kwargs):
""" Calls any remote API func in a thread_safe way.
:param str func_name: name of the remote API func to call
:param args: args to pass to the remote API call
:param kwargs: args to pass to the remote API call
.. note:: You... | python | def call_remote_api(self, func_name, *args, **kwargs):
""" Calls any remote API func in a thread_safe way.
:param str func_name: name of the remote API func to call
:param args: args to pass to the remote API call
:param kwargs: args to pass to the remote API call
.. note:: You... | [
"def",
"call_remote_api",
"(",
"self",
",",
"func_name",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"f",
"=",
"getattr",
"(",
"remote_api",
",",
"func_name",
")",
"mode",
"=",
"self",
".",
"_extract_mode",
"(",
"kwargs",
")",
"kwargs",
"[",
... | Calls any remote API func in a thread_safe way.
:param str func_name: name of the remote API func to call
:param args: args to pass to the remote API call
:param kwargs: args to pass to the remote API call
.. note:: You can add an extra keyword to specify if you want to use the streami... | [
"Calls",
"any",
"remote",
"API",
"func",
"in",
"a",
"thread_safe",
"way",
"."
] | train | https://github.com/poppy-project/pypot/blob/d9c6551bbc87d45d9d1f0bc15e35b616d0002afd/pypot/vrep/io.py#L274-L361 |
poppy-project/pypot | pypot/server/httpserver.py | HTTPRobotServer.run | def run(self, **kwargs):
""" Start the tornado server, run forever"""
try:
loop = IOLoop()
app = self.make_app()
app.listen(self.port)
loop.start()
except socket.error as serr:
# Re raise the socket error if not "[Errno 98] Address al... | python | def run(self, **kwargs):
""" Start the tornado server, run forever"""
try:
loop = IOLoop()
app = self.make_app()
app.listen(self.port)
loop.start()
except socket.error as serr:
# Re raise the socket error if not "[Errno 98] Address al... | [
"def",
"run",
"(",
"self",
",",
"*",
"*",
"kwargs",
")",
":",
"try",
":",
"loop",
"=",
"IOLoop",
"(",
")",
"app",
"=",
"self",
".",
"make_app",
"(",
")",
"app",
".",
"listen",
"(",
"self",
".",
"port",
")",
"loop",
".",
"start",
"(",
")",
"ex... | Start the tornado server, run forever | [
"Start",
"the",
"tornado",
"server",
"run",
"forever"
] | train | https://github.com/poppy-project/pypot/blob/d9c6551bbc87d45d9d1f0bc15e35b616d0002afd/pypot/server/httpserver.py#L253-L267 |
poppy-project/pypot | pypot/server/zmqserver.py | ZMQRobotServer.run | def run(self):
""" Run an infinite REQ/REP loop. """
while True:
req = self.socket.recv_json()
try:
answer = self.handle_request(req)
self.socket.send(json.dumps(answer))
except (AttributeError, TypeError) as e:
self.s... | python | def run(self):
""" Run an infinite REQ/REP loop. """
while True:
req = self.socket.recv_json()
try:
answer = self.handle_request(req)
self.socket.send(json.dumps(answer))
except (AttributeError, TypeError) as e:
self.s... | [
"def",
"run",
"(",
"self",
")",
":",
"while",
"True",
":",
"req",
"=",
"self",
".",
"socket",
".",
"recv_json",
"(",
")",
"try",
":",
"answer",
"=",
"self",
".",
"handle_request",
"(",
"req",
")",
"self",
".",
"socket",
".",
"send",
"(",
"json",
... | Run an infinite REQ/REP loop. | [
"Run",
"an",
"infinite",
"REQ",
"/",
"REP",
"loop",
"."
] | train | https://github.com/poppy-project/pypot/blob/d9c6551bbc87d45d9d1f0bc15e35b616d0002afd/pypot/server/zmqserver.py#L26-L36 |
poppy-project/pypot | pypot/dynamixel/io/abstract_io.py | AbstractDxlIO.open | def open(self, port, baudrate=1000000, timeout=0.05):
""" Opens a new serial communication (closes the previous communication if needed).
:raises: :py:exc:`~pypot.dynamixel.io.DxlError` if the port is already used.
"""
self._open(port, baudrate, timeout)
logger.info("Op... | python | def open(self, port, baudrate=1000000, timeout=0.05):
""" Opens a new serial communication (closes the previous communication if needed).
:raises: :py:exc:`~pypot.dynamixel.io.DxlError` if the port is already used.
"""
self._open(port, baudrate, timeout)
logger.info("Op... | [
"def",
"open",
"(",
"self",
",",
"port",
",",
"baudrate",
"=",
"1000000",
",",
"timeout",
"=",
"0.05",
")",
":",
"self",
".",
"_open",
"(",
"port",
",",
"baudrate",
",",
"timeout",
")",
"logger",
".",
"info",
"(",
"\"Opening port '%s'\"",
",",
"self",
... | Opens a new serial communication (closes the previous communication if needed).
:raises: :py:exc:`~pypot.dynamixel.io.DxlError` if the port is already used. | [
"Opens",
"a",
"new",
"serial",
"communication",
"(",
"closes",
"the",
"previous",
"communication",
"if",
"needed",
")",
"."
] | train | https://github.com/poppy-project/pypot/blob/d9c6551bbc87d45d9d1f0bc15e35b616d0002afd/pypot/dynamixel/io/abstract_io.py#L92-L102 |
poppy-project/pypot | pypot/dynamixel/io/abstract_io.py | AbstractDxlIO.close | def close(self, _force_lock=False):
""" Closes the serial communication if opened. """
if not self.closed:
with self.__force_lock(_force_lock) or self._serial_lock:
self._serial.close()
self.__used_ports.remove(self.port)
logger.info("Closing port... | python | def close(self, _force_lock=False):
""" Closes the serial communication if opened. """
if not self.closed:
with self.__force_lock(_force_lock) or self._serial_lock:
self._serial.close()
self.__used_ports.remove(self.port)
logger.info("Closing port... | [
"def",
"close",
"(",
"self",
",",
"_force_lock",
"=",
"False",
")",
":",
"if",
"not",
"self",
".",
"closed",
":",
"with",
"self",
".",
"__force_lock",
"(",
"_force_lock",
")",
"or",
"self",
".",
"_serial_lock",
":",
"self",
".",
"_serial",
".",
"close"... | Closes the serial communication if opened. | [
"Closes",
"the",
"serial",
"communication",
"if",
"opened",
"."
] | train | https://github.com/poppy-project/pypot/blob/d9c6551bbc87d45d9d1f0bc15e35b616d0002afd/pypot/dynamixel/io/abstract_io.py#L145-L155 |
poppy-project/pypot | pypot/dynamixel/io/abstract_io.py | AbstractDxlIO.flush | def flush(self, _force_lock=False):
""" Flushes the serial communication (both input and output). """
if self.closed:
raise DxlError('attempt to flush a closed serial communication')
with self.__force_lock(_force_lock) or self._serial_lock:
self._serial.flushInput()
... | python | def flush(self, _force_lock=False):
""" Flushes the serial communication (both input and output). """
if self.closed:
raise DxlError('attempt to flush a closed serial communication')
with self.__force_lock(_force_lock) or self._serial_lock:
self._serial.flushInput()
... | [
"def",
"flush",
"(",
"self",
",",
"_force_lock",
"=",
"False",
")",
":",
"if",
"self",
".",
"closed",
":",
"raise",
"DxlError",
"(",
"'attempt to flush a closed serial communication'",
")",
"with",
"self",
".",
"__force_lock",
"(",
"_force_lock",
")",
"or",
"s... | Flushes the serial communication (both input and output). | [
"Flushes",
"the",
"serial",
"communication",
"(",
"both",
"input",
"and",
"output",
")",
"."
] | train | https://github.com/poppy-project/pypot/blob/d9c6551bbc87d45d9d1f0bc15e35b616d0002afd/pypot/dynamixel/io/abstract_io.py#L157-L164 |
poppy-project/pypot | pypot/dynamixel/io/abstract_io.py | AbstractDxlIO.ping | def ping(self, id):
""" Pings the motor with the specified id.
.. note:: The motor id should always be included in [0, 253]. 254 is used for broadcast.
"""
pp = self._protocol.DxlPingPacket(id)
try:
self._send_packet(pp, error_handler=None)
retu... | python | def ping(self, id):
""" Pings the motor with the specified id.
.. note:: The motor id should always be included in [0, 253]. 254 is used for broadcast.
"""
pp = self._protocol.DxlPingPacket(id)
try:
self._send_packet(pp, error_handler=None)
retu... | [
"def",
"ping",
"(",
"self",
",",
"id",
")",
":",
"pp",
"=",
"self",
".",
"_protocol",
".",
"DxlPingPacket",
"(",
"id",
")",
"try",
":",
"self",
".",
"_send_packet",
"(",
"pp",
",",
"error_handler",
"=",
"None",
")",
"return",
"True",
"except",
"DxlTi... | Pings the motor with the specified id.
.. note:: The motor id should always be included in [0, 253]. 254 is used for broadcast. | [
"Pings",
"the",
"motor",
"with",
"the",
"specified",
"id",
"."
] | train | https://github.com/poppy-project/pypot/blob/d9c6551bbc87d45d9d1f0bc15e35b616d0002afd/pypot/dynamixel/io/abstract_io.py#L205-L217 |
poppy-project/pypot | pypot/dynamixel/io/abstract_io.py | AbstractDxlIO.scan | def scan(self, ids=range(254)):
""" Pings all ids within the specified list, by default it finds all the motors connected to the bus. """
return [id for id in ids if self.ping(id)] | python | def scan(self, ids=range(254)):
""" Pings all ids within the specified list, by default it finds all the motors connected to the bus. """
return [id for id in ids if self.ping(id)] | [
"def",
"scan",
"(",
"self",
",",
"ids",
"=",
"range",
"(",
"254",
")",
")",
":",
"return",
"[",
"id",
"for",
"id",
"in",
"ids",
"if",
"self",
".",
"ping",
"(",
"id",
")",
"]"
] | Pings all ids within the specified list, by default it finds all the motors connected to the bus. | [
"Pings",
"all",
"ids",
"within",
"the",
"specified",
"list",
"by",
"default",
"it",
"finds",
"all",
"the",
"motors",
"connected",
"to",
"the",
"bus",
"."
] | train | https://github.com/poppy-project/pypot/blob/d9c6551bbc87d45d9d1f0bc15e35b616d0002afd/pypot/dynamixel/io/abstract_io.py#L219-L221 |
poppy-project/pypot | pypot/dynamixel/io/abstract_io.py | AbstractDxlIO.get_model | def get_model(self, ids):
""" Gets the model for the specified motors. """
to_get_ids = [i for i in ids if i not in self._known_models]
models = [dxl_to_model(m) for m in self._get_model(to_get_ids, convert=False)]
self._known_models.update(zip(to_get_ids, models))
return tuple(... | python | def get_model(self, ids):
""" Gets the model for the specified motors. """
to_get_ids = [i for i in ids if i not in self._known_models]
models = [dxl_to_model(m) for m in self._get_model(to_get_ids, convert=False)]
self._known_models.update(zip(to_get_ids, models))
return tuple(... | [
"def",
"get_model",
"(",
"self",
",",
"ids",
")",
":",
"to_get_ids",
"=",
"[",
"i",
"for",
"i",
"in",
"ids",
"if",
"i",
"not",
"in",
"self",
".",
"_known_models",
"]",
"models",
"=",
"[",
"dxl_to_model",
"(",
"m",
")",
"for",
"m",
"in",
"self",
"... | Gets the model for the specified motors. | [
"Gets",
"the",
"model",
"for",
"the",
"specified",
"motors",
"."
] | train | https://github.com/poppy-project/pypot/blob/d9c6551bbc87d45d9d1f0bc15e35b616d0002afd/pypot/dynamixel/io/abstract_io.py#L225-L231 |
poppy-project/pypot | pypot/dynamixel/io/abstract_io.py | AbstractDxlIO.change_id | def change_id(self, new_id_for_id):
""" Changes the id of the specified motors (each id must be unique on the bus). """
if len(set(new_id_for_id.values())) < len(new_id_for_id):
raise ValueError('each id must be unique.')
for new_id in new_id_for_id.itervalues():
if self... | python | def change_id(self, new_id_for_id):
""" Changes the id of the specified motors (each id must be unique on the bus). """
if len(set(new_id_for_id.values())) < len(new_id_for_id):
raise ValueError('each id must be unique.')
for new_id in new_id_for_id.itervalues():
if self... | [
"def",
"change_id",
"(",
"self",
",",
"new_id_for_id",
")",
":",
"if",
"len",
"(",
"set",
"(",
"new_id_for_id",
".",
"values",
"(",
")",
")",
")",
"<",
"len",
"(",
"new_id_for_id",
")",
":",
"raise",
"ValueError",
"(",
"'each id must be unique.'",
")",
"... | Changes the id of the specified motors (each id must be unique on the bus). | [
"Changes",
"the",
"id",
"of",
"the",
"specified",
"motors",
"(",
"each",
"id",
"must",
"be",
"unique",
"on",
"the",
"bus",
")",
"."
] | train | https://github.com/poppy-project/pypot/blob/d9c6551bbc87d45d9d1f0bc15e35b616d0002afd/pypot/dynamixel/io/abstract_io.py#L233-L250 |
poppy-project/pypot | pypot/dynamixel/io/abstract_io.py | AbstractDxlIO.change_baudrate | def change_baudrate(self, baudrate_for_ids):
""" Changes the baudrate of the specified motors. """
self._change_baudrate(baudrate_for_ids)
for motor_id in baudrate_for_ids:
if motor_id in self._known_models:
del self._known_models[motor_id]
if motor_id in... | python | def change_baudrate(self, baudrate_for_ids):
""" Changes the baudrate of the specified motors. """
self._change_baudrate(baudrate_for_ids)
for motor_id in baudrate_for_ids:
if motor_id in self._known_models:
del self._known_models[motor_id]
if motor_id in... | [
"def",
"change_baudrate",
"(",
"self",
",",
"baudrate_for_ids",
")",
":",
"self",
".",
"_change_baudrate",
"(",
"baudrate_for_ids",
")",
"for",
"motor_id",
"in",
"baudrate_for_ids",
":",
"if",
"motor_id",
"in",
"self",
".",
"_known_models",
":",
"del",
"self",
... | Changes the baudrate of the specified motors. | [
"Changes",
"the",
"baudrate",
"of",
"the",
"specified",
"motors",
"."
] | train | https://github.com/poppy-project/pypot/blob/d9c6551bbc87d45d9d1f0bc15e35b616d0002afd/pypot/dynamixel/io/abstract_io.py#L252-L260 |
poppy-project/pypot | pypot/dynamixel/io/abstract_io.py | AbstractDxlIO.get_status_return_level | def get_status_return_level(self, ids, **kwargs):
""" Gets the status level for the specified motors. """
convert = kwargs['convert'] if 'convert' in kwargs else self._convert
srl = []
for id in ids:
try:
srl.extend(self._get_status_return_level((id, ),
... | python | def get_status_return_level(self, ids, **kwargs):
""" Gets the status level for the specified motors. """
convert = kwargs['convert'] if 'convert' in kwargs else self._convert
srl = []
for id in ids:
try:
srl.extend(self._get_status_return_level((id, ),
... | [
"def",
"get_status_return_level",
"(",
"self",
",",
"ids",
",",
"*",
"*",
"kwargs",
")",
":",
"convert",
"=",
"kwargs",
"[",
"'convert'",
"]",
"if",
"'convert'",
"in",
"kwargs",
"else",
"self",
".",
"_convert",
"srl",
"=",
"[",
"]",
"for",
"id",
"in",
... | Gets the status level for the specified motors. | [
"Gets",
"the",
"status",
"level",
"for",
"the",
"specified",
"motors",
"."
] | train | https://github.com/poppy-project/pypot/blob/d9c6551bbc87d45d9d1f0bc15e35b616d0002afd/pypot/dynamixel/io/abstract_io.py#L262-L280 |
poppy-project/pypot | pypot/dynamixel/io/abstract_io.py | AbstractDxlIO.set_status_return_level | def set_status_return_level(self, srl_for_id, **kwargs):
""" Sets status return level to the specified motors. """
convert = kwargs['convert'] if 'convert' in kwargs else self._convert
if convert:
srl_for_id = dict(zip(srl_for_id.keys(),
[('never', '... | python | def set_status_return_level(self, srl_for_id, **kwargs):
""" Sets status return level to the specified motors. """
convert = kwargs['convert'] if 'convert' in kwargs else self._convert
if convert:
srl_for_id = dict(zip(srl_for_id.keys(),
[('never', '... | [
"def",
"set_status_return_level",
"(",
"self",
",",
"srl_for_id",
",",
"*",
"*",
"kwargs",
")",
":",
"convert",
"=",
"kwargs",
"[",
"'convert'",
"]",
"if",
"'convert'",
"in",
"kwargs",
"else",
"self",
".",
"_convert",
"if",
"convert",
":",
"srl_for_id",
"=... | Sets status return level to the specified motors. | [
"Sets",
"status",
"return",
"level",
"to",
"the",
"specified",
"motors",
"."
] | train | https://github.com/poppy-project/pypot/blob/d9c6551bbc87d45d9d1f0bc15e35b616d0002afd/pypot/dynamixel/io/abstract_io.py#L282-L288 |
poppy-project/pypot | pypot/dynamixel/io/abstract_io.py | AbstractDxlIO.switch_led_on | def switch_led_on(self, ids):
""" Switches on the LED of the motors with the specified ids. """
self._set_LED(dict(zip(ids, itertools.repeat(True)))) | python | def switch_led_on(self, ids):
""" Switches on the LED of the motors with the specified ids. """
self._set_LED(dict(zip(ids, itertools.repeat(True)))) | [
"def",
"switch_led_on",
"(",
"self",
",",
"ids",
")",
":",
"self",
".",
"_set_LED",
"(",
"dict",
"(",
"zip",
"(",
"ids",
",",
"itertools",
".",
"repeat",
"(",
"True",
")",
")",
")",
")"
] | Switches on the LED of the motors with the specified ids. | [
"Switches",
"on",
"the",
"LED",
"of",
"the",
"motors",
"with",
"the",
"specified",
"ids",
"."
] | train | https://github.com/poppy-project/pypot/blob/d9c6551bbc87d45d9d1f0bc15e35b616d0002afd/pypot/dynamixel/io/abstract_io.py#L290-L292 |
poppy-project/pypot | pypot/dynamixel/io/abstract_io.py | AbstractDxlIO.switch_led_off | def switch_led_off(self, ids):
""" Switches off the LED of the motors with the specified ids. """
self._set_LED(dict(zip(ids, itertools.repeat(False)))) | python | def switch_led_off(self, ids):
""" Switches off the LED of the motors with the specified ids. """
self._set_LED(dict(zip(ids, itertools.repeat(False)))) | [
"def",
"switch_led_off",
"(",
"self",
",",
"ids",
")",
":",
"self",
".",
"_set_LED",
"(",
"dict",
"(",
"zip",
"(",
"ids",
",",
"itertools",
".",
"repeat",
"(",
"False",
")",
")",
")",
")"
] | Switches off the LED of the motors with the specified ids. | [
"Switches",
"off",
"the",
"LED",
"of",
"the",
"motors",
"with",
"the",
"specified",
"ids",
"."
] | train | https://github.com/poppy-project/pypot/blob/d9c6551bbc87d45d9d1f0bc15e35b616d0002afd/pypot/dynamixel/io/abstract_io.py#L294-L296 |
poppy-project/pypot | pypot/dynamixel/io/abstract_io.py | AbstractDxlIO.enable_torque | def enable_torque(self, ids):
""" Enables torque of the motors with the specified ids. """
self._set_torque_enable(dict(zip(ids, itertools.repeat(True)))) | python | def enable_torque(self, ids):
""" Enables torque of the motors with the specified ids. """
self._set_torque_enable(dict(zip(ids, itertools.repeat(True)))) | [
"def",
"enable_torque",
"(",
"self",
",",
"ids",
")",
":",
"self",
".",
"_set_torque_enable",
"(",
"dict",
"(",
"zip",
"(",
"ids",
",",
"itertools",
".",
"repeat",
"(",
"True",
")",
")",
")",
")"
] | Enables torque of the motors with the specified ids. | [
"Enables",
"torque",
"of",
"the",
"motors",
"with",
"the",
"specified",
"ids",
"."
] | train | https://github.com/poppy-project/pypot/blob/d9c6551bbc87d45d9d1f0bc15e35b616d0002afd/pypot/dynamixel/io/abstract_io.py#L298-L300 |
poppy-project/pypot | pypot/dynamixel/io/abstract_io.py | AbstractDxlIO.disable_torque | def disable_torque(self, ids):
""" Disables torque of the motors with the specified ids. """
self._set_torque_enable(dict(zip(ids, itertools.repeat(False)))) | python | def disable_torque(self, ids):
""" Disables torque of the motors with the specified ids. """
self._set_torque_enable(dict(zip(ids, itertools.repeat(False)))) | [
"def",
"disable_torque",
"(",
"self",
",",
"ids",
")",
":",
"self",
".",
"_set_torque_enable",
"(",
"dict",
"(",
"zip",
"(",
"ids",
",",
"itertools",
".",
"repeat",
"(",
"False",
")",
")",
")",
")"
] | Disables torque of the motors with the specified ids. | [
"Disables",
"torque",
"of",
"the",
"motors",
"with",
"the",
"specified",
"ids",
"."
] | train | https://github.com/poppy-project/pypot/blob/d9c6551bbc87d45d9d1f0bc15e35b616d0002afd/pypot/dynamixel/io/abstract_io.py#L302-L304 |
poppy-project/pypot | pypot/dynamixel/io/abstract_io.py | AbstractDxlIO.get_pid_gain | def get_pid_gain(self, ids, **kwargs):
""" Gets the pid gain for the specified motors. """
return tuple([tuple(reversed(t)) for t in self._get_pid_gain(ids, **kwargs)]) | python | def get_pid_gain(self, ids, **kwargs):
""" Gets the pid gain for the specified motors. """
return tuple([tuple(reversed(t)) for t in self._get_pid_gain(ids, **kwargs)]) | [
"def",
"get_pid_gain",
"(",
"self",
",",
"ids",
",",
"*",
"*",
"kwargs",
")",
":",
"return",
"tuple",
"(",
"[",
"tuple",
"(",
"reversed",
"(",
"t",
")",
")",
"for",
"t",
"in",
"self",
".",
"_get_pid_gain",
"(",
"ids",
",",
"*",
"*",
"kwargs",
")"... | Gets the pid gain for the specified motors. | [
"Gets",
"the",
"pid",
"gain",
"for",
"the",
"specified",
"motors",
"."
] | train | https://github.com/poppy-project/pypot/blob/d9c6551bbc87d45d9d1f0bc15e35b616d0002afd/pypot/dynamixel/io/abstract_io.py#L306-L308 |
poppy-project/pypot | pypot/dynamixel/io/abstract_io.py | AbstractDxlIO.set_pid_gain | def set_pid_gain(self, pid_for_id, **kwargs):
""" Sets the pid gain to the specified motors. """
pid_for_id = dict(itertools.izip(pid_for_id.iterkeys(),
[tuple(reversed(t)) for t in pid_for_id.values()]))
self._set_pid_gain(pid_for_id, **kwargs) | python | def set_pid_gain(self, pid_for_id, **kwargs):
""" Sets the pid gain to the specified motors. """
pid_for_id = dict(itertools.izip(pid_for_id.iterkeys(),
[tuple(reversed(t)) for t in pid_for_id.values()]))
self._set_pid_gain(pid_for_id, **kwargs) | [
"def",
"set_pid_gain",
"(",
"self",
",",
"pid_for_id",
",",
"*",
"*",
"kwargs",
")",
":",
"pid_for_id",
"=",
"dict",
"(",
"itertools",
".",
"izip",
"(",
"pid_for_id",
".",
"iterkeys",
"(",
")",
",",
"[",
"tuple",
"(",
"reversed",
"(",
"t",
")",
")",
... | Sets the pid gain to the specified motors. | [
"Sets",
"the",
"pid",
"gain",
"to",
"the",
"specified",
"motors",
"."
] | train | https://github.com/poppy-project/pypot/blob/d9c6551bbc87d45d9d1f0bc15e35b616d0002afd/pypot/dynamixel/io/abstract_io.py#L310-L314 |
poppy-project/pypot | pypot/dynamixel/io/abstract_io.py | AbstractDxlIO.get_control_table | def get_control_table(self, ids, **kwargs):
""" Gets the full control table for the specified motors.
..note:: This function requires the model for each motor to be known. Querring this additional information might add some extra delay.
"""
error_handler = kwargs['error_handler... | python | def get_control_table(self, ids, **kwargs):
""" Gets the full control table for the specified motors.
..note:: This function requires the model for each motor to be known. Querring this additional information might add some extra delay.
"""
error_handler = kwargs['error_handler... | [
"def",
"get_control_table",
"(",
"self",
",",
"ids",
",",
"*",
"*",
"kwargs",
")",
":",
"error_handler",
"=",
"kwargs",
"[",
"'error_handler'",
"]",
"if",
"(",
"'error_handler'",
"in",
"kwargs",
")",
"else",
"self",
".",
"_error_handler",
"convert",
"=",
"... | Gets the full control table for the specified motors.
..note:: This function requires the model for each motor to be known. Querring this additional information might add some extra delay. | [
"Gets",
"the",
"full",
"control",
"table",
"for",
"the",
"specified",
"motors",
"."
] | train | https://github.com/poppy-project/pypot/blob/d9c6551bbc87d45d9d1f0bc15e35b616d0002afd/pypot/dynamixel/io/abstract_io.py#L318-L350 |
poppy-project/pypot | pypot/utils/interpolation.py | KDTreeDict.nearest_keys | def nearest_keys(self, key):
"""Find the nearest_keys (l2 distance) thanks to a cKDTree query"""
if not isinstance(key, tuple):
_key = (key,)
if self.__stale:
self.generate_tree()
d, idx = self.__tree.query(
_key, self.k_neighbors, distance_upper_bound... | python | def nearest_keys(self, key):
"""Find the nearest_keys (l2 distance) thanks to a cKDTree query"""
if not isinstance(key, tuple):
_key = (key,)
if self.__stale:
self.generate_tree()
d, idx = self.__tree.query(
_key, self.k_neighbors, distance_upper_bound... | [
"def",
"nearest_keys",
"(",
"self",
",",
"key",
")",
":",
"if",
"not",
"isinstance",
"(",
"key",
",",
"tuple",
")",
":",
"_key",
"=",
"(",
"key",
",",
")",
"if",
"self",
".",
"__stale",
":",
"self",
".",
"generate_tree",
"(",
")",
"d",
",",
"idx"... | Find the nearest_keys (l2 distance) thanks to a cKDTree query | [
"Find",
"the",
"nearest_keys",
"(",
"l2",
"distance",
")",
"thanks",
"to",
"a",
"cKDTree",
"query"
] | train | https://github.com/poppy-project/pypot/blob/d9c6551bbc87d45d9d1f0bc15e35b616d0002afd/pypot/utils/interpolation.py#L50-L63 |
poppy-project/pypot | pypot/utils/interpolation.py | KDTreeDict.interpolate_motor_positions | def interpolate_motor_positions(self, input_key, nearest_keys):
""" Process linear interpolation to estimate actual speed and position of motors
Method specific to the :meth:~pypot.primitive.move.Move.position() structure
it is a KDTreeDict[timestamp] = {dict[motor]=(position,speed)}
... | python | def interpolate_motor_positions(self, input_key, nearest_keys):
""" Process linear interpolation to estimate actual speed and position of motors
Method specific to the :meth:~pypot.primitive.move.Move.position() structure
it is a KDTreeDict[timestamp] = {dict[motor]=(position,speed)}
... | [
"def",
"interpolate_motor_positions",
"(",
"self",
",",
"input_key",
",",
"nearest_keys",
")",
":",
"# TODO : to be rewrited with more style (map ?)",
"if",
"len",
"(",
"nearest_keys",
")",
"==",
"1",
":",
"return",
"self",
"[",
"nearest_keys",
"[",
"0",
"]",
"]",... | Process linear interpolation to estimate actual speed and position of motors
Method specific to the :meth:~pypot.primitive.move.Move.position() structure
it is a KDTreeDict[timestamp] = {dict[motor]=(position,speed)} | [
"Process",
"linear",
"interpolation",
"to",
"estimate",
"actual",
"speed",
"and",
"position",
"of",
"motors",
"Method",
"specific",
"to",
"the",
":",
"meth",
":",
"~pypot",
".",
"primitive",
".",
"move",
".",
"Move",
".",
"position",
"()",
"structure",
"it",... | train | https://github.com/poppy-project/pypot/blob/d9c6551bbc87d45d9d1f0bc15e35b616d0002afd/pypot/utils/interpolation.py#L65-L102 |
poppy-project/pypot | pypot/utils/flushed_print.py | flushed_print | def flushed_print(*args, **kwargs):
"""
Use to replace print(*args, flush=True) that doesn't exist for python<3.3
"""
print(*args, **kwargs)
file = kwargs.get('file', sys.stdout)
file.flush() if file is not None else sys.stdout.flush() | python | def flushed_print(*args, **kwargs):
"""
Use to replace print(*args, flush=True) that doesn't exist for python<3.3
"""
print(*args, **kwargs)
file = kwargs.get('file', sys.stdout)
file.flush() if file is not None else sys.stdout.flush() | [
"def",
"flushed_print",
"(",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"print",
"(",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
"file",
"=",
"kwargs",
".",
"get",
"(",
"'file'",
",",
"sys",
".",
"stdout",
")",
"file",
".",
"flush",
"(",
"... | Use to replace print(*args, flush=True) that doesn't exist for python<3.3 | [
"Use",
"to",
"replace",
"print",
"(",
"*",
"args",
"flush",
"=",
"True",
")",
"that",
"doesn",
"t",
"exist",
"for",
"python<3",
".",
"3"
] | train | https://github.com/poppy-project/pypot/blob/d9c6551bbc87d45d9d1f0bc15e35b616d0002afd/pypot/utils/flushed_print.py#L5-L11 |
poppy-project/pypot | pypot/robot/config.py | from_config | def from_config(config, strict=True, sync=True, use_dummy_io=False, **extra):
""" Returns a :class:`~pypot.robot.robot.Robot` instance created from a configuration dictionnary.
:param dict config: robot configuration dictionary
:param bool strict: make sure that all ports, motors are availaible.
... | python | def from_config(config, strict=True, sync=True, use_dummy_io=False, **extra):
""" Returns a :class:`~pypot.robot.robot.Robot` instance created from a configuration dictionnary.
:param dict config: robot configuration dictionary
:param bool strict: make sure that all ports, motors are availaible.
... | [
"def",
"from_config",
"(",
"config",
",",
"strict",
"=",
"True",
",",
"sync",
"=",
"True",
",",
"use_dummy_io",
"=",
"False",
",",
"*",
"*",
"extra",
")",
":",
"logger",
".",
"info",
"(",
"'Loading config... '",
",",
"extra",
"=",
"{",
"'config'",
":",... | Returns a :class:`~pypot.robot.robot.Robot` instance created from a configuration dictionnary.
:param dict config: robot configuration dictionary
:param bool strict: make sure that all ports, motors are availaible.
:param bool sync: choose if automatically starts the synchronization loops
... | [
"Returns",
"a",
":",
"class",
":",
"~pypot",
".",
"robot",
".",
"robot",
".",
"Robot",
"instance",
"created",
"from",
"a",
"configuration",
"dictionnary",
"."
] | train | https://github.com/poppy-project/pypot/blob/d9c6551bbc87d45d9d1f0bc15e35b616d0002afd/pypot/robot/config.py#L33-L114 |
poppy-project/pypot | pypot/robot/config.py | check_motor_eprom_configuration | def check_motor_eprom_configuration(config, dxl_io, motor_names):
""" Change the angles limits depanding on the robot configuration ;
Check if the return delay time is set to 0.
"""
changed_angle_limits = {}
changed_return_delay_time = {}
for name in motor_names:
m = config['motors'... | python | def check_motor_eprom_configuration(config, dxl_io, motor_names):
""" Change the angles limits depanding on the robot configuration ;
Check if the return delay time is set to 0.
"""
changed_angle_limits = {}
changed_return_delay_time = {}
for name in motor_names:
m = config['motors'... | [
"def",
"check_motor_eprom_configuration",
"(",
"config",
",",
"dxl_io",
",",
"motor_names",
")",
":",
"changed_angle_limits",
"=",
"{",
"}",
"changed_return_delay_time",
"=",
"{",
"}",
"for",
"name",
"in",
"motor_names",
":",
"m",
"=",
"config",
"[",
"'motors'",... | Change the angles limits depanding on the robot configuration ;
Check if the return delay time is set to 0. | [
"Change",
"the",
"angles",
"limits",
"depanding",
"on",
"the",
"robot",
"configuration",
";",
"Check",
"if",
"the",
"return",
"delay",
"time",
"is",
"set",
"to",
"0",
"."
] | train | https://github.com/poppy-project/pypot/blob/d9c6551bbc87d45d9d1f0bc15e35b616d0002afd/pypot/robot/config.py#L209-L252 |
poppy-project/pypot | pypot/robot/config.py | from_json | def from_json(json_file, sync=True, strict=True, use_dummy_io=False, **extra):
""" Returns a :class:`~pypot.robot.robot.Robot` instance created from a JSON configuration file.
For details on how to write such a configuration file, you should refer to the section :ref:`config_file`.
"""
with open(json_... | python | def from_json(json_file, sync=True, strict=True, use_dummy_io=False, **extra):
""" Returns a :class:`~pypot.robot.robot.Robot` instance created from a JSON configuration file.
For details on how to write such a configuration file, you should refer to the section :ref:`config_file`.
"""
with open(json_... | [
"def",
"from_json",
"(",
"json_file",
",",
"sync",
"=",
"True",
",",
"strict",
"=",
"True",
",",
"use_dummy_io",
"=",
"False",
",",
"*",
"*",
"extra",
")",
":",
"with",
"open",
"(",
"json_file",
")",
"as",
"f",
":",
"config",
"=",
"json",
".",
"loa... | Returns a :class:`~pypot.robot.robot.Robot` instance created from a JSON configuration file.
For details on how to write such a configuration file, you should refer to the section :ref:`config_file`. | [
"Returns",
"a",
":",
"class",
":",
"~pypot",
".",
"robot",
".",
"robot",
".",
"Robot",
"instance",
"created",
"from",
"a",
"JSON",
"configuration",
"file",
"."
] | train | https://github.com/poppy-project/pypot/blob/d9c6551bbc87d45d9d1f0bc15e35b616d0002afd/pypot/robot/config.py#L295-L304 |
poppy-project/pypot | pypot/server/rest.py | RESTRobot.stop_move_recorder | def stop_move_recorder(self, move_name):
"""Allow more easily than stop_primitive() to save in a filename the recorded move"""
recorder = getattr(self.robot, '_{}_recorder'.format(move_name))
recorder.stop()
with open('{}.record'.format(move_name), 'w') as f:
recorder.move.sa... | python | def stop_move_recorder(self, move_name):
"""Allow more easily than stop_primitive() to save in a filename the recorded move"""
recorder = getattr(self.robot, '_{}_recorder'.format(move_name))
recorder.stop()
with open('{}.record'.format(move_name), 'w') as f:
recorder.move.sa... | [
"def",
"stop_move_recorder",
"(",
"self",
",",
"move_name",
")",
":",
"recorder",
"=",
"getattr",
"(",
"self",
".",
"robot",
",",
"'_{}_recorder'",
".",
"format",
"(",
"move_name",
")",
")",
"recorder",
".",
"stop",
"(",
")",
"with",
"open",
"(",
"'{}.re... | Allow more easily than stop_primitive() to save in a filename the recorded move | [
"Allow",
"more",
"easily",
"than",
"stop_primitive",
"()",
"to",
"save",
"in",
"a",
"filename",
"the",
"recorded",
"move"
] | train | https://github.com/poppy-project/pypot/blob/d9c6551bbc87d45d9d1f0bc15e35b616d0002afd/pypot/server/rest.py#L147-L161 |
poppy-project/pypot | pypot/server/rest.py | RESTRobot.start_move_player | def start_move_player(self, move_name, speed=1.0, backwards=False):
"""Move player need to have a move file
<move_name.record> in the working directory to play it"""
# check if running
try:
player = getattr(self.robot, '_{}_player'.format(move_name))
if player.ru... | python | def start_move_player(self, move_name, speed=1.0, backwards=False):
"""Move player need to have a move file
<move_name.record> in the working directory to play it"""
# check if running
try:
player = getattr(self.robot, '_{}_player'.format(move_name))
if player.ru... | [
"def",
"start_move_player",
"(",
"self",
",",
"move_name",
",",
"speed",
"=",
"1.0",
",",
"backwards",
"=",
"False",
")",
":",
"# check if running",
"try",
":",
"player",
"=",
"getattr",
"(",
"self",
".",
"robot",
",",
"'_{}_player'",
".",
"format",
"(",
... | Move player need to have a move file
<move_name.record> in the working directory to play it | [
"Move",
"player",
"need",
"to",
"have",
"a",
"move",
"file",
"<move_name",
".",
"record",
">",
"in",
"the",
"working",
"directory",
"to",
"play",
"it"
] | train | https://github.com/poppy-project/pypot/blob/d9c6551bbc87d45d9d1f0bc15e35b616d0002afd/pypot/server/rest.py#L163-L182 |
icometrix/dicom2nifti | dicom2nifti/compressed_dicom.py | _get_gdcmconv | def _get_gdcmconv():
"""
Get the full path to gdcmconv.
If not found raise error
"""
gdcmconv_executable = settings.gdcmconv_path
if gdcmconv_executable is None:
gdcmconv_executable = _which('gdcmconv')
if gdcmconv_executable is None:
gdcmconv_executable = _which('gdcmconv.ex... | python | def _get_gdcmconv():
"""
Get the full path to gdcmconv.
If not found raise error
"""
gdcmconv_executable = settings.gdcmconv_path
if gdcmconv_executable is None:
gdcmconv_executable = _which('gdcmconv')
if gdcmconv_executable is None:
gdcmconv_executable = _which('gdcmconv.ex... | [
"def",
"_get_gdcmconv",
"(",
")",
":",
"gdcmconv_executable",
"=",
"settings",
".",
"gdcmconv_path",
"if",
"gdcmconv_executable",
"is",
"None",
":",
"gdcmconv_executable",
"=",
"_which",
"(",
"'gdcmconv'",
")",
"if",
"gdcmconv_executable",
"is",
"None",
":",
"gdcm... | Get the full path to gdcmconv.
If not found raise error | [
"Get",
"the",
"full",
"path",
"to",
"gdcmconv",
".",
"If",
"not",
"found",
"raise",
"error"
] | train | https://github.com/icometrix/dicom2nifti/blob/1462ae5dd979fa3f276fe7a78ceb9b028121536f/dicom2nifti/compressed_dicom.py#L41-L55 |
icometrix/dicom2nifti | dicom2nifti/compressed_dicom.py | compress_directory | def compress_directory(dicom_directory):
"""
This function can be used to convert a folder of jpeg compressed images to an uncompressed ones
:param dicom_directory: directory of dicom files to compress
"""
if _is_compressed(dicom_directory):
return
logger.info('Compressing dicom files ... | python | def compress_directory(dicom_directory):
"""
This function can be used to convert a folder of jpeg compressed images to an uncompressed ones
:param dicom_directory: directory of dicom files to compress
"""
if _is_compressed(dicom_directory):
return
logger.info('Compressing dicom files ... | [
"def",
"compress_directory",
"(",
"dicom_directory",
")",
":",
"if",
"_is_compressed",
"(",
"dicom_directory",
")",
":",
"return",
"logger",
".",
"info",
"(",
"'Compressing dicom files in %s'",
"%",
"dicom_directory",
")",
"for",
"root",
",",
"_",
",",
"files",
... | This function can be used to convert a folder of jpeg compressed images to an uncompressed ones
:param dicom_directory: directory of dicom files to compress | [
"This",
"function",
"can",
"be",
"used",
"to",
"convert",
"a",
"folder",
"of",
"jpeg",
"compressed",
"images",
"to",
"an",
"uncompressed",
"ones"
] | train | https://github.com/icometrix/dicom2nifti/blob/1462ae5dd979fa3f276fe7a78ceb9b028121536f/dicom2nifti/compressed_dicom.py#L58-L71 |
icometrix/dicom2nifti | dicom2nifti/compressed_dicom.py | is_dicom_file | def is_dicom_file(filename):
"""
Util function to check if file is a dicom file
the first 128 bytes are preamble
the next 4 bytes should contain DICM otherwise it is not a dicom
:param filename: file to check for the DICM header block
:type filename: six.string_types
:returns: True if it is... | python | def is_dicom_file(filename):
"""
Util function to check if file is a dicom file
the first 128 bytes are preamble
the next 4 bytes should contain DICM otherwise it is not a dicom
:param filename: file to check for the DICM header block
:type filename: six.string_types
:returns: True if it is... | [
"def",
"is_dicom_file",
"(",
"filename",
")",
":",
"file_stream",
"=",
"open",
"(",
"filename",
",",
"'rb'",
")",
"file_stream",
".",
"seek",
"(",
"128",
")",
"data",
"=",
"file_stream",
".",
"read",
"(",
"4",
")",
"file_stream",
".",
"close",
"(",
")"... | Util function to check if file is a dicom file
the first 128 bytes are preamble
the next 4 bytes should contain DICM otherwise it is not a dicom
:param filename: file to check for the DICM header block
:type filename: six.string_types
:returns: True if it is a dicom file | [
"Util",
"function",
"to",
"check",
"if",
"file",
"is",
"a",
"dicom",
"file",
"the",
"first",
"128",
"bytes",
"are",
"preamble",
"the",
"next",
"4",
"bytes",
"should",
"contain",
"DICM",
"otherwise",
"it",
"is",
"not",
"a",
"dicom"
] | train | https://github.com/icometrix/dicom2nifti/blob/1462ae5dd979fa3f276fe7a78ceb9b028121536f/dicom2nifti/compressed_dicom.py#L74-L97 |
icometrix/dicom2nifti | dicom2nifti/compressed_dicom.py | _is_compressed | def _is_compressed(dicom_file, force=False):
"""
Check if dicoms are compressed or not
"""
header = pydicom.read_file(dicom_file,
defer_size="1 KB",
stop_before_pixels=True,
force=force)
uncompressed_types ... | python | def _is_compressed(dicom_file, force=False):
"""
Check if dicoms are compressed or not
"""
header = pydicom.read_file(dicom_file,
defer_size="1 KB",
stop_before_pixels=True,
force=force)
uncompressed_types ... | [
"def",
"_is_compressed",
"(",
"dicom_file",
",",
"force",
"=",
"False",
")",
":",
"header",
"=",
"pydicom",
".",
"read_file",
"(",
"dicom_file",
",",
"defer_size",
"=",
"\"1 KB\"",
",",
"stop_before_pixels",
"=",
"True",
",",
"force",
"=",
"force",
")",
"u... | Check if dicoms are compressed or not | [
"Check",
"if",
"dicoms",
"are",
"compressed",
"or",
"not"
] | train | https://github.com/icometrix/dicom2nifti/blob/1462ae5dd979fa3f276fe7a78ceb9b028121536f/dicom2nifti/compressed_dicom.py#L100-L116 |
icometrix/dicom2nifti | dicom2nifti/compressed_dicom.py | _decompress_dicom | def _decompress_dicom(dicom_file, output_file):
"""
This function can be used to convert a jpeg compressed image to an uncompressed one for further conversion
:param input_file: single dicom file to decompress
"""
gdcmconv_executable = _get_gdcmconv()
subprocess.check_output([gdcmconv_executab... | python | def _decompress_dicom(dicom_file, output_file):
"""
This function can be used to convert a jpeg compressed image to an uncompressed one for further conversion
:param input_file: single dicom file to decompress
"""
gdcmconv_executable = _get_gdcmconv()
subprocess.check_output([gdcmconv_executab... | [
"def",
"_decompress_dicom",
"(",
"dicom_file",
",",
"output_file",
")",
":",
"gdcmconv_executable",
"=",
"_get_gdcmconv",
"(",
")",
"subprocess",
".",
"check_output",
"(",
"[",
"gdcmconv_executable",
",",
"'-w'",
",",
"dicom_file",
",",
"output_file",
"]",
")"
] | This function can be used to convert a jpeg compressed image to an uncompressed one for further conversion
:param input_file: single dicom file to decompress | [
"This",
"function",
"can",
"be",
"used",
"to",
"convert",
"a",
"jpeg",
"compressed",
"image",
"to",
"an",
"uncompressed",
"one",
"for",
"further",
"conversion"
] | train | https://github.com/icometrix/dicom2nifti/blob/1462ae5dd979fa3f276fe7a78ceb9b028121536f/dicom2nifti/compressed_dicom.py#L119-L127 |
icometrix/dicom2nifti | scripts/dicomdiff.py | dicom_diff | def dicom_diff(file1, file2):
""" Shows the fields that differ between two DICOM images.
Inspired by https://code.google.com/p/pydicom/source/browse/source/dicom/examples/DicomDiff.py
"""
datasets = compressed_dicom.read_file(file1), compressed_dicom.read_file(file2)
rep = []
for dataset in ... | python | def dicom_diff(file1, file2):
""" Shows the fields that differ between two DICOM images.
Inspired by https://code.google.com/p/pydicom/source/browse/source/dicom/examples/DicomDiff.py
"""
datasets = compressed_dicom.read_file(file1), compressed_dicom.read_file(file2)
rep = []
for dataset in ... | [
"def",
"dicom_diff",
"(",
"file1",
",",
"file2",
")",
":",
"datasets",
"=",
"compressed_dicom",
".",
"read_file",
"(",
"file1",
")",
",",
"compressed_dicom",
".",
"read_file",
"(",
"file2",
")",
"rep",
"=",
"[",
"]",
"for",
"dataset",
"in",
"datasets",
"... | Shows the fields that differ between two DICOM images.
Inspired by https://code.google.com/p/pydicom/source/browse/source/dicom/examples/DicomDiff.py | [
"Shows",
"the",
"fields",
"that",
"differ",
"between",
"two",
"DICOM",
"images",
"."
] | train | https://github.com/icometrix/dicom2nifti/blob/1462ae5dd979fa3f276fe7a78ceb9b028121536f/scripts/dicomdiff.py#L14-L32 |
icometrix/dicom2nifti | dicom2nifti/image_volume.py | ImageVolume.get_slice | def get_slice(self, slice_type, slice_number, time_point=0):
"""
Returns a slice of the dataset.
slice.data contains the window/levelled values, in uint8
slice.original_data contains the original data for this slice
:param time_point: in case of 4d nifti the 4th d... | python | def get_slice(self, slice_type, slice_number, time_point=0):
"""
Returns a slice of the dataset.
slice.data contains the window/levelled values, in uint8
slice.original_data contains the original data for this slice
:param time_point: in case of 4d nifti the 4th d... | [
"def",
"get_slice",
"(",
"self",
",",
"slice_type",
",",
"slice_number",
",",
"time_point",
"=",
"0",
")",
":",
"slice_",
"=",
"Slice",
"(",
")",
"slice_",
".",
"slice_number",
"=",
"slice_number",
"# assert that slice_ number is withing the range",
"assert",
"sli... | Returns a slice of the dataset.
slice.data contains the window/levelled values, in uint8
slice.original_data contains the original data for this slice
:param time_point: in case of 4d nifti the 4th dimension
:param slice_number: the slice number
:param slice_t... | [
"Returns",
"a",
"slice",
"of",
"the",
"dataset",
".",
"slice",
".",
"data",
"contains",
"the",
"window",
"/",
"levelled",
"values",
"in",
"uint8",
"slice",
".",
"original_data",
"contains",
"the",
"original",
"data",
"for",
"this",
"slice",
":",
"param",
"... | train | https://github.com/icometrix/dicom2nifti/blob/1462ae5dd979fa3f276fe7a78ceb9b028121536f/dicom2nifti/image_volume.py#L138-L164 |
icometrix/dicom2nifti | dicom2nifti/image_volume.py | ImageVolume._get_number_of_slices | def _get_number_of_slices(self, slice_type):
"""
Get the number of slices in a certain direction
"""
if slice_type == SliceType.AXIAL:
return self.dimensions[self.axial_orientation.normal_component]
elif slice_type == SliceType.SAGITTAL:
return self.dimens... | python | def _get_number_of_slices(self, slice_type):
"""
Get the number of slices in a certain direction
"""
if slice_type == SliceType.AXIAL:
return self.dimensions[self.axial_orientation.normal_component]
elif slice_type == SliceType.SAGITTAL:
return self.dimens... | [
"def",
"_get_number_of_slices",
"(",
"self",
",",
"slice_type",
")",
":",
"if",
"slice_type",
"==",
"SliceType",
".",
"AXIAL",
":",
"return",
"self",
".",
"dimensions",
"[",
"self",
".",
"axial_orientation",
".",
"normal_component",
"]",
"elif",
"slice_type",
... | Get the number of slices in a certain direction | [
"Get",
"the",
"number",
"of",
"slices",
"in",
"a",
"certain",
"direction"
] | train | https://github.com/icometrix/dicom2nifti/blob/1462ae5dd979fa3f276fe7a78ceb9b028121536f/dicom2nifti/image_volume.py#L166-L175 |
icometrix/dicom2nifti | dicom2nifti/convert_dicom.py | dicom_series_to_nifti | def dicom_series_to_nifti(original_dicom_directory, output_file=None, reorient_nifti=True):
""" Converts dicom single series (see pydicom) to nifty, mimicking SPM
Examples: See unit test
will return a dictionary containing
- the NIFTI under key 'NIFTI'
- the NIFTI file path under 'NII_FILE'
-... | python | def dicom_series_to_nifti(original_dicom_directory, output_file=None, reorient_nifti=True):
""" Converts dicom single series (see pydicom) to nifty, mimicking SPM
Examples: See unit test
will return a dictionary containing
- the NIFTI under key 'NIFTI'
- the NIFTI file path under 'NII_FILE'
-... | [
"def",
"dicom_series_to_nifti",
"(",
"original_dicom_directory",
",",
"output_file",
"=",
"None",
",",
"reorient_nifti",
"=",
"True",
")",
":",
"# copy files so we can can modify without altering the original",
"temp_directory",
"=",
"tempfile",
".",
"mkdtemp",
"(",
")",
... | Converts dicom single series (see pydicom) to nifty, mimicking SPM
Examples: See unit test
will return a dictionary containing
- the NIFTI under key 'NIFTI'
- the NIFTI file path under 'NII_FILE'
- the BVAL file path under 'BVAL_FILE' (only for dti)
- the BVEC file path under 'BVEC_FILE' (onl... | [
"Converts",
"dicom",
"single",
"series",
"(",
"see",
"pydicom",
")",
"to",
"nifty",
"mimicking",
"SPM"
] | train | https://github.com/icometrix/dicom2nifti/blob/1462ae5dd979fa3f276fe7a78ceb9b028121536f/dicom2nifti/convert_dicom.py#L54-L96 |
icometrix/dicom2nifti | dicom2nifti/convert_dicom.py | dicom_array_to_nifti | def dicom_array_to_nifti(dicom_list, output_file, reorient_nifti=True):
""" Converts dicom single series (see pydicom) to nifty, mimicking SPM
Examples: See unit test
will return a dictionary containing
- the NIFTI under key 'NIFTI'
- the NIFTI file path under 'NII_FILE'
- the BVAL file path ... | python | def dicom_array_to_nifti(dicom_list, output_file, reorient_nifti=True):
""" Converts dicom single series (see pydicom) to nifty, mimicking SPM
Examples: See unit test
will return a dictionary containing
- the NIFTI under key 'NIFTI'
- the NIFTI file path under 'NII_FILE'
- the BVAL file path ... | [
"def",
"dicom_array_to_nifti",
"(",
"dicom_list",
",",
"output_file",
",",
"reorient_nifti",
"=",
"True",
")",
":",
"# copy files so we can can modify without altering the original",
"if",
"not",
"are_imaging_dicoms",
"(",
"dicom_list",
")",
":",
"raise",
"ConversionValidat... | Converts dicom single series (see pydicom) to nifty, mimicking SPM
Examples: See unit test
will return a dictionary containing
- the NIFTI under key 'NIFTI'
- the NIFTI file path under 'NII_FILE'
- the BVAL file path under 'BVAL_FILE' (only for dti)
- the BVEC file path under 'BVEC_FILE' (onl... | [
"Converts",
"dicom",
"single",
"series",
"(",
"see",
"pydicom",
")",
"to",
"nifty",
"mimicking",
"SPM"
] | train | https://github.com/icometrix/dicom2nifti/blob/1462ae5dd979fa3f276fe7a78ceb9b028121536f/dicom2nifti/convert_dicom.py#L99-L149 |
icometrix/dicom2nifti | dicom2nifti/convert_dicom.py | are_imaging_dicoms | def are_imaging_dicoms(dicom_input):
"""
This function will check the dicom headers to see which type of series it is
Possibilities are fMRI, DTI, Anatomical (if no clear type is found anatomical is used)
:param dicom_input: directory with dicom files or a list of dicom objects
"""
# if it is ... | python | def are_imaging_dicoms(dicom_input):
"""
This function will check the dicom headers to see which type of series it is
Possibilities are fMRI, DTI, Anatomical (if no clear type is found anatomical is used)
:param dicom_input: directory with dicom files or a list of dicom objects
"""
# if it is ... | [
"def",
"are_imaging_dicoms",
"(",
"dicom_input",
")",
":",
"# if it is philips and multiframe dicom then we assume it is ok",
"if",
"common",
".",
"is_philips",
"(",
"dicom_input",
")",
":",
"if",
"common",
".",
"is_multiframe_dicom",
"(",
"dicom_input",
")",
":",
"retu... | This function will check the dicom headers to see which type of series it is
Possibilities are fMRI, DTI, Anatomical (if no clear type is found anatomical is used)
:param dicom_input: directory with dicom files or a list of dicom objects | [
"This",
"function",
"will",
"check",
"the",
"dicom",
"headers",
"to",
"see",
"which",
"type",
"of",
"series",
"it",
"is",
"Possibilities",
"are",
"fMRI",
"DTI",
"Anatomical",
"(",
"if",
"no",
"clear",
"type",
"is",
"found",
"anatomical",
"is",
"used",
")"
... | train | https://github.com/icometrix/dicom2nifti/blob/1462ae5dd979fa3f276fe7a78ceb9b028121536f/dicom2nifti/convert_dicom.py#L152-L167 |
icometrix/dicom2nifti | dicom2nifti/convert_dicom.py | _get_vendor | def _get_vendor(dicom_input):
"""
This function will check the dicom headers to see which type of series it is
Possibilities are fMRI, DTI, Anatomical (if no clear type is found anatomical is used)
"""
# check if it is siemens
if common.is_siemens(dicom_input):
logger.info('Found manufac... | python | def _get_vendor(dicom_input):
"""
This function will check the dicom headers to see which type of series it is
Possibilities are fMRI, DTI, Anatomical (if no clear type is found anatomical is used)
"""
# check if it is siemens
if common.is_siemens(dicom_input):
logger.info('Found manufac... | [
"def",
"_get_vendor",
"(",
"dicom_input",
")",
":",
"# check if it is siemens",
"if",
"common",
".",
"is_siemens",
"(",
"dicom_input",
")",
":",
"logger",
".",
"info",
"(",
"'Found manufacturer: SIEMENS'",
")",
"return",
"Vendor",
".",
"SIEMENS",
"# check if it is g... | This function will check the dicom headers to see which type of series it is
Possibilities are fMRI, DTI, Anatomical (if no clear type is found anatomical is used) | [
"This",
"function",
"will",
"check",
"the",
"dicom",
"headers",
"to",
"see",
"which",
"type",
"of",
"series",
"it",
"is",
"Possibilities",
"are",
"fMRI",
"DTI",
"Anatomical",
"(",
"if",
"no",
"clear",
"type",
"is",
"found",
"anatomical",
"is",
"used",
")"
... | train | https://github.com/icometrix/dicom2nifti/blob/1462ae5dd979fa3f276fe7a78ceb9b028121536f/dicom2nifti/convert_dicom.py#L170-L193 |
icometrix/dicom2nifti | dicom2nifti/convert_dicom.py | _get_first_header | def _get_first_header(dicom_directory):
"""
Function to get the first dicom file form a directory and return the header
Useful to determine the type of data to convert
:param dicom_directory: directory with dicom files
"""
# looping over all files
for root, _, file_names in os.walk(dicom_di... | python | def _get_first_header(dicom_directory):
"""
Function to get the first dicom file form a directory and return the header
Useful to determine the type of data to convert
:param dicom_directory: directory with dicom files
"""
# looping over all files
for root, _, file_names in os.walk(dicom_di... | [
"def",
"_get_first_header",
"(",
"dicom_directory",
")",
":",
"# looping over all files",
"for",
"root",
",",
"_",
",",
"file_names",
"in",
"os",
".",
"walk",
"(",
"dicom_directory",
")",
":",
"# go over all the files and try to read the dicom header",
"for",
"file_name... | Function to get the first dicom file form a directory and return the header
Useful to determine the type of data to convert
:param dicom_directory: directory with dicom files | [
"Function",
"to",
"get",
"the",
"first",
"dicom",
"file",
"form",
"a",
"directory",
"and",
"return",
"the",
"header",
"Useful",
"to",
"determine",
"the",
"type",
"of",
"data",
"to",
"convert"
] | train | https://github.com/icometrix/dicom2nifti/blob/1462ae5dd979fa3f276fe7a78ceb9b028121536f/dicom2nifti/convert_dicom.py#L196-L216 |
icometrix/dicom2nifti | scripts/shrink_singleframe.py | _shrink_file | def _shrink_file(dicom_file_in, subsample_factor):
"""
Anonimize a single dicomfile
:param dicom_file_in: filepath for input file
:param dicom_file_out: filepath for output file
:param fields_to_keep: dicom tags to keep
"""
# Default meta_fields
# Required fields according to reference
... | python | def _shrink_file(dicom_file_in, subsample_factor):
"""
Anonimize a single dicomfile
:param dicom_file_in: filepath for input file
:param dicom_file_out: filepath for output file
:param fields_to_keep: dicom tags to keep
"""
# Default meta_fields
# Required fields according to reference
... | [
"def",
"_shrink_file",
"(",
"dicom_file_in",
",",
"subsample_factor",
")",
":",
"# Default meta_fields",
"# Required fields according to reference",
"dicom_file_out",
"=",
"dicom_file_in",
"# Load dicom_file_in",
"dicom_in",
"=",
"compressed_dicom",
".",
"read_file",
"(",
"di... | Anonimize a single dicomfile
:param dicom_file_in: filepath for input file
:param dicom_file_out: filepath for output file
:param fields_to_keep: dicom tags to keep | [
"Anonimize",
"a",
"single",
"dicomfile",
":",
"param",
"dicom_file_in",
":",
"filepath",
"for",
"input",
"file",
":",
"param",
"dicom_file_out",
":",
"filepath",
"for",
"output",
"file",
":",
"param",
"fields_to_keep",
":",
"dicom",
"tags",
"to",
"keep"
] | train | https://github.com/icometrix/dicom2nifti/blob/1462ae5dd979fa3f276fe7a78ceb9b028121536f/scripts/shrink_singleframe.py#L16-L72 |
icometrix/dicom2nifti | dicom2nifti/image_reorientation.py | reorient_image | def reorient_image(input_image, output_image):
"""
Change the orientation of the Image data in order to be in LAS space
x will represent the coronal plane, y the sagittal and z the axial plane.
x increases from Right (R) to Left (L), y from Posterior (P) to Anterior (A) and z from Inferior (I) to Superi... | python | def reorient_image(input_image, output_image):
"""
Change the orientation of the Image data in order to be in LAS space
x will represent the coronal plane, y the sagittal and z the axial plane.
x increases from Right (R) to Left (L), y from Posterior (P) to Anterior (A) and z from Inferior (I) to Superi... | [
"def",
"reorient_image",
"(",
"input_image",
",",
"output_image",
")",
":",
"# Use the imageVolume module to find which coordinate corresponds to each plane",
"# and get the image data in RAS orientation",
"# print 'Reading nifti'",
"image",
"=",
"load",
"(",
"input_image",
")",
"#... | Change the orientation of the Image data in order to be in LAS space
x will represent the coronal plane, y the sagittal and z the axial plane.
x increases from Right (R) to Left (L), y from Posterior (P) to Anterior (A) and z from Inferior (I) to Superior (S)
:returns: The output image in nibabel form
... | [
"Change",
"the",
"orientation",
"of",
"the",
"Image",
"data",
"in",
"order",
"to",
"be",
"in",
"LAS",
"space",
"x",
"will",
"represent",
"the",
"coronal",
"plane",
"y",
"the",
"sagittal",
"and",
"z",
"the",
"axial",
"plane",
".",
"x",
"increases",
"from"... | train | https://github.com/icometrix/dicom2nifti/blob/1462ae5dd979fa3f276fe7a78ceb9b028121536f/dicom2nifti/image_reorientation.py#L18-L80 |
icometrix/dicom2nifti | dicom2nifti/image_reorientation.py | _reorient_3d | def _reorient_3d(image):
"""
Reorganize the data for a 3d nifti
"""
# Create empty array where x,y,z correspond to LR (sagittal), PA (coronal), IS (axial) directions and the size
# of the array in each direction is the same with the corresponding direction of the input image.
new_image = numpy.z... | python | def _reorient_3d(image):
"""
Reorganize the data for a 3d nifti
"""
# Create empty array where x,y,z correspond to LR (sagittal), PA (coronal), IS (axial) directions and the size
# of the array in each direction is the same with the corresponding direction of the input image.
new_image = numpy.z... | [
"def",
"_reorient_3d",
"(",
"image",
")",
":",
"# Create empty array where x,y,z correspond to LR (sagittal), PA (coronal), IS (axial) directions and the size",
"# of the array in each direction is the same with the corresponding direction of the input image.",
"new_image",
"=",
"numpy",
".",
... | Reorganize the data for a 3d nifti | [
"Reorganize",
"the",
"data",
"for",
"a",
"3d",
"nifti"
] | train | https://github.com/icometrix/dicom2nifti/blob/1462ae5dd979fa3f276fe7a78ceb9b028121536f/dicom2nifti/image_reorientation.py#L112-L133 |
icometrix/dicom2nifti | dicom2nifti/convert_philips.py | dicom_to_nifti | def dicom_to_nifti(dicom_input, output_file=None):
"""
This is the main dicom to nifti conversion fuction for philips images.
As input philips images are required. It will then determine the type of images and do the correct conversion
Examples: See unit test
:param output_file: file path to the o... | python | def dicom_to_nifti(dicom_input, output_file=None):
"""
This is the main dicom to nifti conversion fuction for philips images.
As input philips images are required. It will then determine the type of images and do the correct conversion
Examples: See unit test
:param output_file: file path to the o... | [
"def",
"dicom_to_nifti",
"(",
"dicom_input",
",",
"output_file",
"=",
"None",
")",
":",
"assert",
"common",
".",
"is_philips",
"(",
"dicom_input",
")",
"if",
"common",
".",
"is_multiframe_dicom",
"(",
"dicom_input",
")",
":",
"_assert_explicit_vr",
"(",
"dicom_i... | This is the main dicom to nifti conversion fuction for philips images.
As input philips images are required. It will then determine the type of images and do the correct conversion
Examples: See unit test
:param output_file: file path to the output nifti
:param dicom_input: directory with dicom files ... | [
"This",
"is",
"the",
"main",
"dicom",
"to",
"nifti",
"conversion",
"fuction",
"for",
"philips",
"images",
".",
"As",
"input",
"philips",
"images",
"are",
"required",
".",
"It",
"will",
"then",
"determine",
"the",
"type",
"of",
"images",
"and",
"do",
"the",... | train | https://github.com/icometrix/dicom2nifti/blob/1462ae5dd979fa3f276fe7a78ceb9b028121536f/dicom2nifti/convert_philips.py#L31-L62 |
icometrix/dicom2nifti | dicom2nifti/convert_philips.py | _assert_explicit_vr | def _assert_explicit_vr(dicom_input):
"""
Assert that explicit vr is used
"""
if settings.validate_multiframe_implicit:
header = dicom_input[0]
if header.file_meta[0x0002, 0x0010].value == '1.2.840.10008.1.2':
raise ConversionError('IMPLICIT_VR_ENHANCED_DICOM') | python | def _assert_explicit_vr(dicom_input):
"""
Assert that explicit vr is used
"""
if settings.validate_multiframe_implicit:
header = dicom_input[0]
if header.file_meta[0x0002, 0x0010].value == '1.2.840.10008.1.2':
raise ConversionError('IMPLICIT_VR_ENHANCED_DICOM') | [
"def",
"_assert_explicit_vr",
"(",
"dicom_input",
")",
":",
"if",
"settings",
".",
"validate_multiframe_implicit",
":",
"header",
"=",
"dicom_input",
"[",
"0",
"]",
"if",
"header",
".",
"file_meta",
"[",
"0x0002",
",",
"0x0010",
"]",
".",
"value",
"==",
"'1.... | Assert that explicit vr is used | [
"Assert",
"that",
"explicit",
"vr",
"is",
"used"
] | train | https://github.com/icometrix/dicom2nifti/blob/1462ae5dd979fa3f276fe7a78ceb9b028121536f/dicom2nifti/convert_philips.py#L65-L72 |
icometrix/dicom2nifti | dicom2nifti/convert_philips.py | _is_multiframe_diffusion_imaging | def _is_multiframe_diffusion_imaging(dicom_input):
"""
Use this function to detect if a dicom series is a philips multiframe dti dataset
NOTE: We already assue this is a 4D dataset as input
"""
header = dicom_input[0]
if "PerFrameFunctionalGroupsSequence" not in header:
return False
... | python | def _is_multiframe_diffusion_imaging(dicom_input):
"""
Use this function to detect if a dicom series is a philips multiframe dti dataset
NOTE: We already assue this is a 4D dataset as input
"""
header = dicom_input[0]
if "PerFrameFunctionalGroupsSequence" not in header:
return False
... | [
"def",
"_is_multiframe_diffusion_imaging",
"(",
"dicom_input",
")",
":",
"header",
"=",
"dicom_input",
"[",
"0",
"]",
"if",
"\"PerFrameFunctionalGroupsSequence\"",
"not",
"in",
"header",
":",
"return",
"False",
"# check if there is diffusion info in the frame",
"found_diffu... | Use this function to detect if a dicom series is a philips multiframe dti dataset
NOTE: We already assue this is a 4D dataset as input | [
"Use",
"this",
"function",
"to",
"detect",
"if",
"a",
"dicom",
"series",
"is",
"a",
"philips",
"multiframe",
"dti",
"dataset",
"NOTE",
":",
"We",
"already",
"assue",
"this",
"is",
"a",
"4D",
"dataset",
"as",
"input"
] | train | https://github.com/icometrix/dicom2nifti/blob/1462ae5dd979fa3f276fe7a78ceb9b028121536f/dicom2nifti/convert_philips.py#L75-L95 |
icometrix/dicom2nifti | dicom2nifti/convert_philips.py | _is_multiframe_4d | def _is_multiframe_4d(dicom_input):
"""
Use this function to detect if a dicom series is a philips multiframe 4D dataset
"""
# check if it is multi frame dicom
if not common.is_multiframe_dicom(dicom_input):
return False
header = dicom_input[0]
# check if there are multiple stacks
... | python | def _is_multiframe_4d(dicom_input):
"""
Use this function to detect if a dicom series is a philips multiframe 4D dataset
"""
# check if it is multi frame dicom
if not common.is_multiframe_dicom(dicom_input):
return False
header = dicom_input[0]
# check if there are multiple stacks
... | [
"def",
"_is_multiframe_4d",
"(",
"dicom_input",
")",
":",
"# check if it is multi frame dicom",
"if",
"not",
"common",
".",
"is_multiframe_dicom",
"(",
"dicom_input",
")",
":",
"return",
"False",
"header",
"=",
"dicom_input",
"[",
"0",
"]",
"# check if there are multi... | Use this function to detect if a dicom series is a philips multiframe 4D dataset | [
"Use",
"this",
"function",
"to",
"detect",
"if",
"a",
"dicom",
"series",
"is",
"a",
"philips",
"multiframe",
"4D",
"dataset"
] | train | https://github.com/icometrix/dicom2nifti/blob/1462ae5dd979fa3f276fe7a78ceb9b028121536f/dicom2nifti/convert_philips.py#L98-L114 |
icometrix/dicom2nifti | dicom2nifti/convert_philips.py | _is_singleframe_4d | def _is_singleframe_4d(dicom_input):
"""
Use this function to detect if a dicom series is a philips singleframe 4D dataset
"""
header = dicom_input[0]
# check if there are stack information
slice_number_mr_tag = Tag(0x2001, 0x100a)
if slice_number_mr_tag not in header:
return False
... | python | def _is_singleframe_4d(dicom_input):
"""
Use this function to detect if a dicom series is a philips singleframe 4D dataset
"""
header = dicom_input[0]
# check if there are stack information
slice_number_mr_tag = Tag(0x2001, 0x100a)
if slice_number_mr_tag not in header:
return False
... | [
"def",
"_is_singleframe_4d",
"(",
"dicom_input",
")",
":",
"header",
"=",
"dicom_input",
"[",
"0",
"]",
"# check if there are stack information",
"slice_number_mr_tag",
"=",
"Tag",
"(",
"0x2001",
",",
"0x100a",
")",
"if",
"slice_number_mr_tag",
"not",
"in",
"header"... | Use this function to detect if a dicom series is a philips singleframe 4D dataset | [
"Use",
"this",
"function",
"to",
"detect",
"if",
"a",
"dicom",
"series",
"is",
"a",
"philips",
"singleframe",
"4D",
"dataset"
] | train | https://github.com/icometrix/dicom2nifti/blob/1462ae5dd979fa3f276fe7a78ceb9b028121536f/dicom2nifti/convert_philips.py#L139-L155 |
icometrix/dicom2nifti | dicom2nifti/convert_philips.py | _is_bval_type_a | def _is_bval_type_a(grouped_dicoms):
"""
Check if the bvals are stored in the first of 2 currently known ways for single frame dti
"""
bval_tag = Tag(0x2001, 0x1003)
bvec_x_tag = Tag(0x2005, 0x10b0)
bvec_y_tag = Tag(0x2005, 0x10b1)
bvec_z_tag = Tag(0x2005, 0x10b2)
for group in grouped_di... | python | def _is_bval_type_a(grouped_dicoms):
"""
Check if the bvals are stored in the first of 2 currently known ways for single frame dti
"""
bval_tag = Tag(0x2001, 0x1003)
bvec_x_tag = Tag(0x2005, 0x10b0)
bvec_y_tag = Tag(0x2005, 0x10b1)
bvec_z_tag = Tag(0x2005, 0x10b2)
for group in grouped_di... | [
"def",
"_is_bval_type_a",
"(",
"grouped_dicoms",
")",
":",
"bval_tag",
"=",
"Tag",
"(",
"0x2001",
",",
"0x1003",
")",
"bvec_x_tag",
"=",
"Tag",
"(",
"0x2005",
",",
"0x10b0",
")",
"bvec_y_tag",
"=",
"Tag",
"(",
"0x2005",
",",
"0x10b1",
")",
"bvec_z_tag",
... | Check if the bvals are stored in the first of 2 currently known ways for single frame dti | [
"Check",
"if",
"the",
"bvals",
"are",
"stored",
"in",
"the",
"first",
"of",
"2",
"currently",
"known",
"ways",
"for",
"single",
"frame",
"dti"
] | train | https://github.com/icometrix/dicom2nifti/blob/1462ae5dd979fa3f276fe7a78ceb9b028121536f/dicom2nifti/convert_philips.py#L172-L187 |
icometrix/dicom2nifti | dicom2nifti/convert_philips.py | _is_bval_type_b | def _is_bval_type_b(grouped_dicoms):
"""
Check if the bvals are stored in the second of 2 currently known ways for single frame dti
"""
bval_tag = Tag(0x0018, 0x9087)
bvec_tag = Tag(0x0018, 0x9089)
for group in grouped_dicoms:
if bvec_tag in group[0] and bval_tag in group[0]:
... | python | def _is_bval_type_b(grouped_dicoms):
"""
Check if the bvals are stored in the second of 2 currently known ways for single frame dti
"""
bval_tag = Tag(0x0018, 0x9087)
bvec_tag = Tag(0x0018, 0x9089)
for group in grouped_dicoms:
if bvec_tag in group[0] and bval_tag in group[0]:
... | [
"def",
"_is_bval_type_b",
"(",
"grouped_dicoms",
")",
":",
"bval_tag",
"=",
"Tag",
"(",
"0x0018",
",",
"0x9087",
")",
"bvec_tag",
"=",
"Tag",
"(",
"0x0018",
",",
"0x9089",
")",
"for",
"group",
"in",
"grouped_dicoms",
":",
"if",
"bvec_tag",
"in",
"group",
... | Check if the bvals are stored in the second of 2 currently known ways for single frame dti | [
"Check",
"if",
"the",
"bvals",
"are",
"stored",
"in",
"the",
"second",
"of",
"2",
"currently",
"known",
"ways",
"for",
"single",
"frame",
"dti"
] | train | https://github.com/icometrix/dicom2nifti/blob/1462ae5dd979fa3f276fe7a78ceb9b028121536f/dicom2nifti/convert_philips.py#L190-L202 |
icometrix/dicom2nifti | dicom2nifti/convert_philips.py | _multiframe_to_nifti | def _multiframe_to_nifti(dicom_input, output_file):
"""
This function will convert philips 4D or anatomical multiframe series to a nifti
"""
# Read the multiframe dicom file
logger.info('Read dicom file')
multiframe_dicom = dicom_input[0]
# Create mosaic block
logger.info('Creating dat... | python | def _multiframe_to_nifti(dicom_input, output_file):
"""
This function will convert philips 4D or anatomical multiframe series to a nifti
"""
# Read the multiframe dicom file
logger.info('Read dicom file')
multiframe_dicom = dicom_input[0]
# Create mosaic block
logger.info('Creating dat... | [
"def",
"_multiframe_to_nifti",
"(",
"dicom_input",
",",
"output_file",
")",
":",
"# Read the multiframe dicom file",
"logger",
".",
"info",
"(",
"'Read dicom file'",
")",
"multiframe_dicom",
"=",
"dicom_input",
"[",
"0",
"]",
"# Create mosaic block",
"logger",
".",
"i... | This function will convert philips 4D or anatomical multiframe series to a nifti | [
"This",
"function",
"will",
"convert",
"philips",
"4D",
"or",
"anatomical",
"multiframe",
"series",
"to",
"a",
"nifti"
] | train | https://github.com/icometrix/dicom2nifti/blob/1462ae5dd979fa3f276fe7a78ceb9b028121536f/dicom2nifti/convert_philips.py#L216-L268 |
icometrix/dicom2nifti | dicom2nifti/convert_philips.py | _singleframe_to_nifti | def _singleframe_to_nifti(grouped_dicoms, output_file):
"""
This function will convert a philips singleframe series to a nifti
"""
# Create mosaic block
logger.info('Creating data block')
full_block = _singleframe_to_block(grouped_dicoms)
logger.info('Creating affine')
# Create the nif... | python | def _singleframe_to_nifti(grouped_dicoms, output_file):
"""
This function will convert a philips singleframe series to a nifti
"""
# Create mosaic block
logger.info('Creating data block')
full_block = _singleframe_to_block(grouped_dicoms)
logger.info('Creating affine')
# Create the nif... | [
"def",
"_singleframe_to_nifti",
"(",
"grouped_dicoms",
",",
"output_file",
")",
":",
"# Create mosaic block",
"logger",
".",
"info",
"(",
"'Creating data block'",
")",
"full_block",
"=",
"_singleframe_to_block",
"(",
"grouped_dicoms",
")",
"logger",
".",
"info",
"(",
... | This function will convert a philips singleframe series to a nifti | [
"This",
"function",
"will",
"convert",
"a",
"philips",
"singleframe",
"series",
"to",
"a",
"nifti"
] | train | https://github.com/icometrix/dicom2nifti/blob/1462ae5dd979fa3f276fe7a78ceb9b028121536f/dicom2nifti/convert_philips.py#L271-L322 |
icometrix/dicom2nifti | dicom2nifti/convert_philips.py | _singleframe_to_block | def _singleframe_to_block(grouped_dicoms):
"""
Generate a full datablock containing all timepoints
"""
# For each slice / mosaic create a data volume block
data_blocks = []
for index in range(0, len(grouped_dicoms)):
logger.info('Creating block %s of %s' % (index + 1, len(grouped_dicoms)... | python | def _singleframe_to_block(grouped_dicoms):
"""
Generate a full datablock containing all timepoints
"""
# For each slice / mosaic create a data volume block
data_blocks = []
for index in range(0, len(grouped_dicoms)):
logger.info('Creating block %s of %s' % (index + 1, len(grouped_dicoms)... | [
"def",
"_singleframe_to_block",
"(",
"grouped_dicoms",
")",
":",
"# For each slice / mosaic create a data volume block",
"data_blocks",
"=",
"[",
"]",
"for",
"index",
"in",
"range",
"(",
"0",
",",
"len",
"(",
"grouped_dicoms",
")",
")",
":",
"logger",
".",
"info",... | Generate a full datablock containing all timepoints | [
"Generate",
"a",
"full",
"datablock",
"containing",
"all",
"timepoints"
] | train | https://github.com/icometrix/dicom2nifti/blob/1462ae5dd979fa3f276fe7a78ceb9b028121536f/dicom2nifti/convert_philips.py#L325-L346 |
icometrix/dicom2nifti | dicom2nifti/convert_philips.py | _get_grouped_dicoms | def _get_grouped_dicoms(dicom_input):
"""
Search all dicoms in the dicom directory, sort and validate them
fast_read = True will only read the headers not the data
"""
# if all dicoms have an instance number try sorting by instance number else by position
if [d for d in dicom_input if 'Instance... | python | def _get_grouped_dicoms(dicom_input):
"""
Search all dicoms in the dicom directory, sort and validate them
fast_read = True will only read the headers not the data
"""
# if all dicoms have an instance number try sorting by instance number else by position
if [d for d in dicom_input if 'Instance... | [
"def",
"_get_grouped_dicoms",
"(",
"dicom_input",
")",
":",
"# if all dicoms have an instance number try sorting by instance number else by position",
"if",
"[",
"d",
"for",
"d",
"in",
"dicom_input",
"if",
"'InstanceNumber'",
"in",
"d",
"]",
":",
"dicoms",
"=",
"sorted",
... | Search all dicoms in the dicom directory, sort and validate them
fast_read = True will only read the headers not the data | [
"Search",
"all",
"dicoms",
"in",
"the",
"dicom",
"directory",
"sort",
"and",
"validate",
"them"
] | train | https://github.com/icometrix/dicom2nifti/blob/1462ae5dd979fa3f276fe7a78ceb9b028121536f/dicom2nifti/convert_philips.py#L356-L390 |
icometrix/dicom2nifti | dicom2nifti/convert_philips.py | _create_affine_multiframe | def _create_affine_multiframe(multiframe_dicom):
"""
Function to create the affine matrix for a siemens mosaic dataset
This will work for siemens dti and 4D if in mosaic format
"""
first_frame = multiframe_dicom[Tag(0x5200, 0x9230)][0]
last_frame = multiframe_dicom[Tag(0x5200, 0x9230)][-1]
#... | python | def _create_affine_multiframe(multiframe_dicom):
"""
Function to create the affine matrix for a siemens mosaic dataset
This will work for siemens dti and 4D if in mosaic format
"""
first_frame = multiframe_dicom[Tag(0x5200, 0x9230)][0]
last_frame = multiframe_dicom[Tag(0x5200, 0x9230)][-1]
#... | [
"def",
"_create_affine_multiframe",
"(",
"multiframe_dicom",
")",
":",
"first_frame",
"=",
"multiframe_dicom",
"[",
"Tag",
"(",
"0x5200",
",",
"0x9230",
")",
"]",
"[",
"0",
"]",
"last_frame",
"=",
"multiframe_dicom",
"[",
"Tag",
"(",
"0x5200",
",",
"0x9230",
... | Function to create the affine matrix for a siemens mosaic dataset
This will work for siemens dti and 4D if in mosaic format | [
"Function",
"to",
"create",
"the",
"affine",
"matrix",
"for",
"a",
"siemens",
"mosaic",
"dataset",
"This",
"will",
"work",
"for",
"siemens",
"dti",
"and",
"4D",
"if",
"in",
"mosaic",
"format"
] | train | https://github.com/icometrix/dicom2nifti/blob/1462ae5dd979fa3f276fe7a78ceb9b028121536f/dicom2nifti/convert_philips.py#L393-L419 |
icometrix/dicom2nifti | dicom2nifti/convert_philips.py | _multiframe_to_block | def _multiframe_to_block(multiframe_dicom):
"""
Generate a full datablock containing all stacks
"""
# Calculate the amount of stacks and slices in the stack
number_of_stack_slices = int(common.get_ss_value(multiframe_dicom[Tag(0x2001, 0x105f)][0][Tag(0x2001, 0x102d)]))
number_of_stacks = int(int... | python | def _multiframe_to_block(multiframe_dicom):
"""
Generate a full datablock containing all stacks
"""
# Calculate the amount of stacks and slices in the stack
number_of_stack_slices = int(common.get_ss_value(multiframe_dicom[Tag(0x2001, 0x105f)][0][Tag(0x2001, 0x102d)]))
number_of_stacks = int(int... | [
"def",
"_multiframe_to_block",
"(",
"multiframe_dicom",
")",
":",
"# Calculate the amount of stacks and slices in the stack",
"number_of_stack_slices",
"=",
"int",
"(",
"common",
".",
"get_ss_value",
"(",
"multiframe_dicom",
"[",
"Tag",
"(",
"0x2001",
",",
"0x105f",
")",
... | Generate a full datablock containing all stacks | [
"Generate",
"a",
"full",
"datablock",
"containing",
"all",
"stacks"
] | train | https://github.com/icometrix/dicom2nifti/blob/1462ae5dd979fa3f276fe7a78ceb9b028121536f/dicom2nifti/convert_philips.py#L422-L473 |
icometrix/dicom2nifti | dicom2nifti/convert_philips.py | _create_bvals_bvecs | def _create_bvals_bvecs(multiframe_dicom, bval_file, bvec_file, nifti, nifti_file):
"""
Write the bvals from the sorted dicom files to a bval file
Inspired by https://github.com/IBIC/ibicUtils/blob/master/ibicBvalsBvecs.py
"""
# create the empty arrays
number_of_stack_slices = common.get_ss_val... | python | def _create_bvals_bvecs(multiframe_dicom, bval_file, bvec_file, nifti, nifti_file):
"""
Write the bvals from the sorted dicom files to a bval file
Inspired by https://github.com/IBIC/ibicUtils/blob/master/ibicBvalsBvecs.py
"""
# create the empty arrays
number_of_stack_slices = common.get_ss_val... | [
"def",
"_create_bvals_bvecs",
"(",
"multiframe_dicom",
",",
"bval_file",
",",
"bvec_file",
",",
"nifti",
",",
"nifti_file",
")",
":",
"# create the empty arrays",
"number_of_stack_slices",
"=",
"common",
".",
"get_ss_value",
"(",
"multiframe_dicom",
"[",
"Tag",
"(",
... | Write the bvals from the sorted dicom files to a bval file
Inspired by https://github.com/IBIC/ibicUtils/blob/master/ibicBvalsBvecs.py | [
"Write",
"the",
"bvals",
"from",
"the",
"sorted",
"dicom",
"files",
"to",
"a",
"bval",
"file",
"Inspired",
"by",
"https",
":",
"//",
"github",
".",
"com",
"/",
"IBIC",
"/",
"ibicUtils",
"/",
"blob",
"/",
"master",
"/",
"ibicBvalsBvecs",
".",
"py"
] | train | https://github.com/icometrix/dicom2nifti/blob/1462ae5dd979fa3f276fe7a78ceb9b028121536f/dicom2nifti/convert_philips.py#L511-L545 |
icometrix/dicom2nifti | dicom2nifti/convert_philips.py | _fix_diffusion_images | def _fix_diffusion_images(bvals, bvecs, nifti, nifti_file):
"""
This function will remove the last timepoint from the nifti, bvals and bvecs if the last vector is 0,0,0
This is sometimes added at the end by philips
"""
# if all zero continue of if the last bvec is not all zero continue
if numpy.... | python | def _fix_diffusion_images(bvals, bvecs, nifti, nifti_file):
"""
This function will remove the last timepoint from the nifti, bvals and bvecs if the last vector is 0,0,0
This is sometimes added at the end by philips
"""
# if all zero continue of if the last bvec is not all zero continue
if numpy.... | [
"def",
"_fix_diffusion_images",
"(",
"bvals",
",",
"bvecs",
",",
"nifti",
",",
"nifti_file",
")",
":",
"# if all zero continue of if the last bvec is not all zero continue",
"if",
"numpy",
".",
"count_nonzero",
"(",
"bvecs",
")",
"==",
"0",
"or",
"not",
"numpy",
"."... | This function will remove the last timepoint from the nifti, bvals and bvecs if the last vector is 0,0,0
This is sometimes added at the end by philips | [
"This",
"function",
"will",
"remove",
"the",
"last",
"timepoint",
"from",
"the",
"nifti",
"bvals",
"and",
"bvecs",
"if",
"the",
"last",
"vector",
"is",
"0",
"0",
"0",
"This",
"is",
"sometimes",
"added",
"at",
"the",
"end",
"by",
"philips"
] | train | https://github.com/icometrix/dicom2nifti/blob/1462ae5dd979fa3f276fe7a78ceb9b028121536f/dicom2nifti/convert_philips.py#L548-L565 |
icometrix/dicom2nifti | dicom2nifti/convert_philips.py | _create_singleframe_bvals_bvecs | def _create_singleframe_bvals_bvecs(grouped_dicoms, bval_file, bvec_file, nifti, nifti_file):
"""
Write the bvals from the sorted dicom files to a bval file
"""
# create the empty arrays
bvals = numpy.zeros([len(grouped_dicoms)], dtype=numpy.int32)
bvecs = numpy.zeros([len(grouped_dicoms), 3])
... | python | def _create_singleframe_bvals_bvecs(grouped_dicoms, bval_file, bvec_file, nifti, nifti_file):
"""
Write the bvals from the sorted dicom files to a bval file
"""
# create the empty arrays
bvals = numpy.zeros([len(grouped_dicoms)], dtype=numpy.int32)
bvecs = numpy.zeros([len(grouped_dicoms), 3])
... | [
"def",
"_create_singleframe_bvals_bvecs",
"(",
"grouped_dicoms",
",",
"bval_file",
",",
"bvec_file",
",",
"nifti",
",",
"nifti_file",
")",
":",
"# create the empty arrays",
"bvals",
"=",
"numpy",
".",
"zeros",
"(",
"[",
"len",
"(",
"grouped_dicoms",
")",
"]",
",... | Write the bvals from the sorted dicom files to a bval file | [
"Write",
"the",
"bvals",
"from",
"the",
"sorted",
"dicom",
"files",
"to",
"a",
"bval",
"file"
] | train | https://github.com/icometrix/dicom2nifti/blob/1462ae5dd979fa3f276fe7a78ceb9b028121536f/dicom2nifti/convert_philips.py#L568-L607 |
icometrix/dicom2nifti | dicom2nifti/convert_generic.py | dicom_to_nifti | def dicom_to_nifti(dicom_input, output_file):
"""
This function will convert an anatomical dicom series to a nifti
Examples: See unit test
:param output_file: filepath to the output nifti
:param dicom_input: directory with the dicom files for a single scan, or list of read in dicoms
"""
if... | python | def dicom_to_nifti(dicom_input, output_file):
"""
This function will convert an anatomical dicom series to a nifti
Examples: See unit test
:param output_file: filepath to the output nifti
:param dicom_input: directory with the dicom files for a single scan, or list of read in dicoms
"""
if... | [
"def",
"dicom_to_nifti",
"(",
"dicom_input",
",",
"output_file",
")",
":",
"if",
"len",
"(",
"dicom_input",
")",
"<=",
"0",
":",
"raise",
"ConversionError",
"(",
"'NO_DICOM_FILES_FOUND'",
")",
"# remove duplicate slices based on position and data",
"dicom_input",
"=",
... | This function will convert an anatomical dicom series to a nifti
Examples: See unit test
:param output_file: filepath to the output nifti
:param dicom_input: directory with the dicom files for a single scan, or list of read in dicoms | [
"This",
"function",
"will",
"convert",
"an",
"anatomical",
"dicom",
"series",
"to",
"a",
"nifti"
] | train | https://github.com/icometrix/dicom2nifti/blob/1462ae5dd979fa3f276fe7a78ceb9b028121536f/dicom2nifti/convert_generic.py#L29-L94 |
icometrix/dicom2nifti | dicom2nifti/convert_generic.py | _remove_duplicate_slices | def _remove_duplicate_slices(dicoms):
"""
Search dicoms for localizers and delete them
"""
# Loop overall files and build dict
dicoms_dict = {}
filtered_dicoms = []
for dicom_ in dicoms:
if tuple(dicom_.ImagePositionPatient) not in dicoms_dict:
dicoms_dict[tuple(dicom_.I... | python | def _remove_duplicate_slices(dicoms):
"""
Search dicoms for localizers and delete them
"""
# Loop overall files and build dict
dicoms_dict = {}
filtered_dicoms = []
for dicom_ in dicoms:
if tuple(dicom_.ImagePositionPatient) not in dicoms_dict:
dicoms_dict[tuple(dicom_.I... | [
"def",
"_remove_duplicate_slices",
"(",
"dicoms",
")",
":",
"# Loop overall files and build dict",
"dicoms_dict",
"=",
"{",
"}",
"filtered_dicoms",
"=",
"[",
"]",
"for",
"dicom_",
"in",
"dicoms",
":",
"if",
"tuple",
"(",
"dicom_",
".",
"ImagePositionPatient",
")",... | Search dicoms for localizers and delete them | [
"Search",
"dicoms",
"for",
"localizers",
"and",
"delete",
"them"
] | train | https://github.com/icometrix/dicom2nifti/blob/1462ae5dd979fa3f276fe7a78ceb9b028121536f/dicom2nifti/convert_generic.py#L97-L115 |
icometrix/dicom2nifti | dicom2nifti/convert_generic.py | _remove_localizers_by_imagetype | def _remove_localizers_by_imagetype(dicoms):
"""
Search dicoms for localizers and delete them
"""
# Loop overall files and build dict
filtered_dicoms = []
for dicom_ in dicoms:
if 'ImageType' in dicom_ and 'LOCALIZER' in dicom_.ImageType:
continue
# 'Projection Image'... | python | def _remove_localizers_by_imagetype(dicoms):
"""
Search dicoms for localizers and delete them
"""
# Loop overall files and build dict
filtered_dicoms = []
for dicom_ in dicoms:
if 'ImageType' in dicom_ and 'LOCALIZER' in dicom_.ImageType:
continue
# 'Projection Image'... | [
"def",
"_remove_localizers_by_imagetype",
"(",
"dicoms",
")",
":",
"# Loop overall files and build dict",
"filtered_dicoms",
"=",
"[",
"]",
"for",
"dicom_",
"in",
"dicoms",
":",
"if",
"'ImageType'",
"in",
"dicom_",
"and",
"'LOCALIZER'",
"in",
"dicom_",
".",
"ImageTy... | Search dicoms for localizers and delete them | [
"Search",
"dicoms",
"for",
"localizers",
"and",
"delete",
"them"
] | train | https://github.com/icometrix/dicom2nifti/blob/1462ae5dd979fa3f276fe7a78ceb9b028121536f/dicom2nifti/convert_generic.py#L118-L131 |
icometrix/dicom2nifti | dicom2nifti/convert_generic.py | _remove_localizers_by_orientation | def _remove_localizers_by_orientation(dicoms):
"""
Removing localizers based on the orientation.
This is needed as in some cases with ct data there are some localizer/projection type images that cannot
be distiguished by the dicom headers. This is why we kick out all orientations that do not have more t... | python | def _remove_localizers_by_orientation(dicoms):
"""
Removing localizers based on the orientation.
This is needed as in some cases with ct data there are some localizer/projection type images that cannot
be distiguished by the dicom headers. This is why we kick out all orientations that do not have more t... | [
"def",
"_remove_localizers_by_orientation",
"(",
"dicoms",
")",
":",
"orientations",
"=",
"[",
"]",
"sorted_dicoms",
"=",
"{",
"}",
"# Loop overall files and build dict",
"for",
"dicom_header",
"in",
"dicoms",
":",
"# Create affine matrix (http://nipy.sourceforge.net/nibabel/... | Removing localizers based on the orientation.
This is needed as in some cases with ct data there are some localizer/projection type images that cannot
be distiguished by the dicom headers. This is why we kick out all orientations that do not have more than 4 files
4 is the limit anyway for converting to nif... | [
"Removing",
"localizers",
"based",
"on",
"the",
"orientation",
".",
"This",
"is",
"needed",
"as",
"in",
"some",
"cases",
"with",
"ct",
"data",
"there",
"are",
"some",
"localizer",
"/",
"projection",
"type",
"images",
"that",
"cannot",
"be",
"distiguished",
"... | train | https://github.com/icometrix/dicom2nifti/blob/1462ae5dd979fa3f276fe7a78ceb9b028121536f/dicom2nifti/convert_generic.py#L134-L171 |
icometrix/dicom2nifti | dicom2nifti/convert_generic.py | _convert_slice_incement_inconsistencies | def _convert_slice_incement_inconsistencies(dicom_input):
"""
If there is slice increment inconsistency detected, for the moment CT images, then split the volumes into subvolumes based on the slice increment and process each volume separately using a space constructed based on the highest resolution increment
... | python | def _convert_slice_incement_inconsistencies(dicom_input):
"""
If there is slice increment inconsistency detected, for the moment CT images, then split the volumes into subvolumes based on the slice increment and process each volume separately using a space constructed based on the highest resolution increment
... | [
"def",
"_convert_slice_incement_inconsistencies",
"(",
"dicom_input",
")",
":",
"# Estimate the \"first\" slice increment based on the 2 first slices",
"increment",
"=",
"numpy",
".",
"array",
"(",
"dicom_input",
"[",
"0",
"]",
".",
"ImagePositionPatient",
")",
"-",
"nump... | If there is slice increment inconsistency detected, for the moment CT images, then split the volumes into subvolumes based on the slice increment and process each volume separately using a space constructed based on the highest resolution increment | [
"If",
"there",
"is",
"slice",
"increment",
"inconsistency",
"detected",
"for",
"the",
"moment",
"CT",
"images",
"then",
"split",
"the",
"volumes",
"into",
"subvolumes",
"based",
"on",
"the",
"slice",
"increment",
"and",
"process",
"each",
"volume",
"separately",... | train | https://github.com/icometrix/dicom2nifti/blob/1462ae5dd979fa3f276fe7a78ceb9b028121536f/dicom2nifti/convert_generic.py#L174-L209 |
icometrix/dicom2nifti | dicom2nifti/common.py | read_dicom_directory | def read_dicom_directory(dicom_directory, stop_before_pixels=False):
"""
Read all dicom files in a given directory (stop before pixels)
:type stop_before_pixels: bool
:type dicom_directory: six.string_types
:param stop_before_pixels: Should we stop reading before the pixeldata (handy if we only wan... | python | def read_dicom_directory(dicom_directory, stop_before_pixels=False):
"""
Read all dicom files in a given directory (stop before pixels)
:type stop_before_pixels: bool
:type dicom_directory: six.string_types
:param stop_before_pixels: Should we stop reading before the pixeldata (handy if we only wan... | [
"def",
"read_dicom_directory",
"(",
"dicom_directory",
",",
"stop_before_pixels",
"=",
"False",
")",
":",
"dicom_input",
"=",
"[",
"]",
"for",
"root",
",",
"_",
",",
"files",
"in",
"os",
".",
"walk",
"(",
"dicom_directory",
")",
":",
"for",
"dicom_file",
"... | Read all dicom files in a given directory (stop before pixels)
:type stop_before_pixels: bool
:type dicom_directory: six.string_types
:param stop_before_pixels: Should we stop reading before the pixeldata (handy if we only want header info)
:param dicom_directory: Directory with dicom data
:return:... | [
"Read",
"all",
"dicom",
"files",
"in",
"a",
"given",
"directory",
"(",
"stop",
"before",
"pixels",
")"
] | train | https://github.com/icometrix/dicom2nifti/blob/1462ae5dd979fa3f276fe7a78ceb9b028121536f/dicom2nifti/common.py#L33-L54 |
icometrix/dicom2nifti | dicom2nifti/common.py | is_hitachi | def is_hitachi(dicom_input):
"""
Use this function to detect if a dicom series is a hitachi dataset
:param dicom_input: directory with dicom files for 1 scan of a dicom_header
"""
# read dicom header
header = dicom_input[0]
if 'Manufacturer' not in header or 'Modality' not in header:
... | python | def is_hitachi(dicom_input):
"""
Use this function to detect if a dicom series is a hitachi dataset
:param dicom_input: directory with dicom files for 1 scan of a dicom_header
"""
# read dicom header
header = dicom_input[0]
if 'Manufacturer' not in header or 'Modality' not in header:
... | [
"def",
"is_hitachi",
"(",
"dicom_input",
")",
":",
"# read dicom header",
"header",
"=",
"dicom_input",
"[",
"0",
"]",
"if",
"'Manufacturer'",
"not",
"in",
"header",
"or",
"'Modality'",
"not",
"in",
"header",
":",
"return",
"False",
"# we try generic conversion in... | Use this function to detect if a dicom series is a hitachi dataset
:param dicom_input: directory with dicom files for 1 scan of a dicom_header | [
"Use",
"this",
"function",
"to",
"detect",
"if",
"a",
"dicom",
"series",
"is",
"a",
"hitachi",
"dataset"
] | train | https://github.com/icometrix/dicom2nifti/blob/1462ae5dd979fa3f276fe7a78ceb9b028121536f/dicom2nifti/common.py#L57-L77 |
icometrix/dicom2nifti | dicom2nifti/common.py | is_ge | def is_ge(dicom_input):
"""
Use this function to detect if a dicom series is a GE dataset
:param dicom_input: list with dicom objects
"""
# read dicom header
header = dicom_input[0]
if 'Manufacturer' not in header or 'Modality' not in header:
return False # we try generic conversi... | python | def is_ge(dicom_input):
"""
Use this function to detect if a dicom series is a GE dataset
:param dicom_input: list with dicom objects
"""
# read dicom header
header = dicom_input[0]
if 'Manufacturer' not in header or 'Modality' not in header:
return False # we try generic conversi... | [
"def",
"is_ge",
"(",
"dicom_input",
")",
":",
"# read dicom header",
"header",
"=",
"dicom_input",
"[",
"0",
"]",
"if",
"'Manufacturer'",
"not",
"in",
"header",
"or",
"'Modality'",
"not",
"in",
"header",
":",
"return",
"False",
"# we try generic conversion in thes... | Use this function to detect if a dicom series is a GE dataset
:param dicom_input: list with dicom objects | [
"Use",
"this",
"function",
"to",
"detect",
"if",
"a",
"dicom",
"series",
"is",
"a",
"GE",
"dataset"
] | train | https://github.com/icometrix/dicom2nifti/blob/1462ae5dd979fa3f276fe7a78ceb9b028121536f/dicom2nifti/common.py#L80-L100 |
icometrix/dicom2nifti | dicom2nifti/common.py | is_philips | def is_philips(dicom_input):
"""
Use this function to detect if a dicom series is a philips dataset
:param dicom_input: directory with dicom files for 1 scan of a dicom_header
"""
# read dicom header
header = dicom_input[0]
if 'Manufacturer' not in header or 'Modality' not in header:
... | python | def is_philips(dicom_input):
"""
Use this function to detect if a dicom series is a philips dataset
:param dicom_input: directory with dicom files for 1 scan of a dicom_header
"""
# read dicom header
header = dicom_input[0]
if 'Manufacturer' not in header or 'Modality' not in header:
... | [
"def",
"is_philips",
"(",
"dicom_input",
")",
":",
"# read dicom header",
"header",
"=",
"dicom_input",
"[",
"0",
"]",
"if",
"'Manufacturer'",
"not",
"in",
"header",
"or",
"'Modality'",
"not",
"in",
"header",
":",
"return",
"False",
"# we try generic conversion in... | Use this function to detect if a dicom series is a philips dataset
:param dicom_input: directory with dicom files for 1 scan of a dicom_header | [
"Use",
"this",
"function",
"to",
"detect",
"if",
"a",
"dicom",
"series",
"is",
"a",
"philips",
"dataset"
] | train | https://github.com/icometrix/dicom2nifti/blob/1462ae5dd979fa3f276fe7a78ceb9b028121536f/dicom2nifti/common.py#L103-L123 |
icometrix/dicom2nifti | dicom2nifti/common.py | is_siemens | def is_siemens(dicom_input):
"""
Use this function to detect if a dicom series is a siemens dataset
:param dicom_input: directory with dicom files for 1 scan
"""
# read dicom header
header = dicom_input[0]
# check if manufacturer is Siemens
if 'Manufacturer' not in header or 'Modality'... | python | def is_siemens(dicom_input):
"""
Use this function to detect if a dicom series is a siemens dataset
:param dicom_input: directory with dicom files for 1 scan
"""
# read dicom header
header = dicom_input[0]
# check if manufacturer is Siemens
if 'Manufacturer' not in header or 'Modality'... | [
"def",
"is_siemens",
"(",
"dicom_input",
")",
":",
"# read dicom header",
"header",
"=",
"dicom_input",
"[",
"0",
"]",
"# check if manufacturer is Siemens",
"if",
"'Manufacturer'",
"not",
"in",
"header",
"or",
"'Modality'",
"not",
"in",
"header",
":",
"return",
"F... | Use this function to detect if a dicom series is a siemens dataset
:param dicom_input: directory with dicom files for 1 scan | [
"Use",
"this",
"function",
"to",
"detect",
"if",
"a",
"dicom",
"series",
"is",
"a",
"siemens",
"dataset"
] | train | https://github.com/icometrix/dicom2nifti/blob/1462ae5dd979fa3f276fe7a78ceb9b028121536f/dicom2nifti/common.py#L126-L146 |
icometrix/dicom2nifti | dicom2nifti/common.py | is_multiframe_dicom | def is_multiframe_dicom(dicom_input):
"""
Use this function to detect if a dicom series is a siemens 4D dataset
NOTE: Only the first slice will be checked so you can only provide an already sorted dicom directory
(containing one series)
:param dicom_input: directory with dicom files for 1 scan
... | python | def is_multiframe_dicom(dicom_input):
"""
Use this function to detect if a dicom series is a siemens 4D dataset
NOTE: Only the first slice will be checked so you can only provide an already sorted dicom directory
(containing one series)
:param dicom_input: directory with dicom files for 1 scan
... | [
"def",
"is_multiframe_dicom",
"(",
"dicom_input",
")",
":",
"# read dicom header",
"header",
"=",
"dicom_input",
"[",
"0",
"]",
"if",
"Tag",
"(",
"0x0002",
",",
"0x0002",
")",
"not",
"in",
"header",
".",
"file_meta",
":",
"return",
"False",
"if",
"header",
... | Use this function to detect if a dicom series is a siemens 4D dataset
NOTE: Only the first slice will be checked so you can only provide an already sorted dicom directory
(containing one series)
:param dicom_input: directory with dicom files for 1 scan | [
"Use",
"this",
"function",
"to",
"detect",
"if",
"a",
"dicom",
"series",
"is",
"a",
"siemens",
"4D",
"dataset",
"NOTE",
":",
"Only",
"the",
"first",
"slice",
"will",
"be",
"checked",
"so",
"you",
"can",
"only",
"provide",
"an",
"already",
"sorted",
"dico... | train | https://github.com/icometrix/dicom2nifti/blob/1462ae5dd979fa3f276fe7a78ceb9b028121536f/dicom2nifti/common.py#L149-L164 |
icometrix/dicom2nifti | dicom2nifti/common.py | is_valid_imaging_dicom | def is_valid_imaging_dicom(dicom_header):
"""
Function will do some basic checks to see if this is a valid imaging dicom
"""
# if it is philips and multiframe dicom then we assume it is ok
try:
if is_philips([dicom_header]):
if is_multiframe_dicom([dicom_header]):
... | python | def is_valid_imaging_dicom(dicom_header):
"""
Function will do some basic checks to see if this is a valid imaging dicom
"""
# if it is philips and multiframe dicom then we assume it is ok
try:
if is_philips([dicom_header]):
if is_multiframe_dicom([dicom_header]):
... | [
"def",
"is_valid_imaging_dicom",
"(",
"dicom_header",
")",
":",
"# if it is philips and multiframe dicom then we assume it is ok",
"try",
":",
"if",
"is_philips",
"(",
"[",
"dicom_header",
"]",
")",
":",
"if",
"is_multiframe_dicom",
"(",
"[",
"dicom_header",
"]",
")",
... | Function will do some basic checks to see if this is a valid imaging dicom | [
"Function",
"will",
"do",
"some",
"basic",
"checks",
"to",
"see",
"if",
"this",
"is",
"a",
"valid",
"imaging",
"dicom"
] | train | https://github.com/icometrix/dicom2nifti/blob/1462ae5dd979fa3f276fe7a78ceb9b028121536f/dicom2nifti/common.py#L167-L195 |
icometrix/dicom2nifti | dicom2nifti/common.py | get_volume_pixeldata | def get_volume_pixeldata(sorted_slices):
"""
the slice and intercept calculation can cause the slices to have different dtypes
we should get the correct dtype that can cover all of them
:type sorted_slices: list of slices
:param sorted_slices: sliced sored in the correct order to create volume
... | python | def get_volume_pixeldata(sorted_slices):
"""
the slice and intercept calculation can cause the slices to have different dtypes
we should get the correct dtype that can cover all of them
:type sorted_slices: list of slices
:param sorted_slices: sliced sored in the correct order to create volume
... | [
"def",
"get_volume_pixeldata",
"(",
"sorted_slices",
")",
":",
"slices",
"=",
"[",
"]",
"combined_dtype",
"=",
"None",
"for",
"slice_",
"in",
"sorted_slices",
":",
"slice_data",
"=",
"_get_slice_pixeldata",
"(",
"slice_",
")",
"slice_data",
"=",
"slice_data",
"[... | the slice and intercept calculation can cause the slices to have different dtypes
we should get the correct dtype that can cover all of them
:type sorted_slices: list of slices
:param sorted_slices: sliced sored in the correct order to create volume | [
"the",
"slice",
"and",
"intercept",
"calculation",
"can",
"cause",
"the",
"slices",
"to",
"have",
"different",
"dtypes",
"we",
"should",
"get",
"the",
"correct",
"dtype",
"that",
"can",
"cover",
"all",
"of",
"them",
":",
"type",
"sorted_slices",
":",
"list",... | train | https://github.com/icometrix/dicom2nifti/blob/1462ae5dd979fa3f276fe7a78ceb9b028121536f/dicom2nifti/common.py#L198-L222 |
icometrix/dicom2nifti | dicom2nifti/common.py | _get_slice_pixeldata | def _get_slice_pixeldata(dicom_slice):
"""
the slice and intercept calculation can cause the slices to have different dtypes
we should get the correct dtype that can cover all of them
:type dicom_slice: pydicom object
:param dicom_slice: slice to get the pixeldata for
"""
data = dicom_slice... | python | def _get_slice_pixeldata(dicom_slice):
"""
the slice and intercept calculation can cause the slices to have different dtypes
we should get the correct dtype that can cover all of them
:type dicom_slice: pydicom object
:param dicom_slice: slice to get the pixeldata for
"""
data = dicom_slice... | [
"def",
"_get_slice_pixeldata",
"(",
"dicom_slice",
")",
":",
"data",
"=",
"dicom_slice",
".",
"pixel_array",
"# fix overflow issues for signed data where BitsStored is lower than BitsAllocated and PixelReprentation = 1 (signed)",
"# for example a hitachi mri scan can have BitsAllocated 16 bu... | the slice and intercept calculation can cause the slices to have different dtypes
we should get the correct dtype that can cover all of them
:type dicom_slice: pydicom object
:param dicom_slice: slice to get the pixeldata for | [
"the",
"slice",
"and",
"intercept",
"calculation",
"can",
"cause",
"the",
"slices",
"to",
"have",
"different",
"dtypes",
"we",
"should",
"get",
"the",
"correct",
"dtype",
"that",
"can",
"cover",
"all",
"of",
"them"
] | train | https://github.com/icometrix/dicom2nifti/blob/1462ae5dd979fa3f276fe7a78ceb9b028121536f/dicom2nifti/common.py#L225-L245 |
icometrix/dicom2nifti | dicom2nifti/common.py | get_numpy_type | def get_numpy_type(dicom_header):
"""
Make NumPy format code, e.g. "uint16", "int32" etc
from two pieces of info:
mosaic.PixelRepresentation -- 0 for unsigned, 1 for signed;
mosaic.BitsAllocated -- 8, 16, or 32
:param dicom_header: the read dicom file/headers
:returns: numpy format string
... | python | def get_numpy_type(dicom_header):
"""
Make NumPy format code, e.g. "uint16", "int32" etc
from two pieces of info:
mosaic.PixelRepresentation -- 0 for unsigned, 1 for signed;
mosaic.BitsAllocated -- 8, 16, or 32
:param dicom_header: the read dicom file/headers
:returns: numpy format string
... | [
"def",
"get_numpy_type",
"(",
"dicom_header",
")",
":",
"format_string",
"=",
"'%sint%d'",
"%",
"(",
"(",
"'u'",
",",
"''",
")",
"[",
"dicom_header",
".",
"PixelRepresentation",
"]",
",",
"dicom_header",
".",
"BitsAllocated",
")",
"try",
":",
"numpy",
".",
... | Make NumPy format code, e.g. "uint16", "int32" etc
from two pieces of info:
mosaic.PixelRepresentation -- 0 for unsigned, 1 for signed;
mosaic.BitsAllocated -- 8, 16, or 32
:param dicom_header: the read dicom file/headers
:returns: numpy format string | [
"Make",
"NumPy",
"format",
"code",
"e",
".",
"g",
".",
"uint16",
"int32",
"etc",
"from",
"two",
"pieces",
"of",
"info",
":",
"mosaic",
".",
"PixelRepresentation",
"--",
"0",
"for",
"unsigned",
"1",
"for",
"signed",
";",
"mosaic",
".",
"BitsAllocated",
"-... | train | https://github.com/icometrix/dicom2nifti/blob/1462ae5dd979fa3f276fe7a78ceb9b028121536f/dicom2nifti/common.py#L260-L277 |
icometrix/dicom2nifti | dicom2nifti/common.py | get_fd_array_value | def get_fd_array_value(tag, count):
"""
Getters for data that also work with implicit transfersyntax
:param count: number of items in the array
:param tag: the tag to read
"""
if tag.VR == 'OB' or tag.VR == 'UN':
values = []
for i in range(count):
start = i * 8
... | python | def get_fd_array_value(tag, count):
"""
Getters for data that also work with implicit transfersyntax
:param count: number of items in the array
:param tag: the tag to read
"""
if tag.VR == 'OB' or tag.VR == 'UN':
values = []
for i in range(count):
start = i * 8
... | [
"def",
"get_fd_array_value",
"(",
"tag",
",",
"count",
")",
":",
"if",
"tag",
".",
"VR",
"==",
"'OB'",
"or",
"tag",
".",
"VR",
"==",
"'UN'",
":",
"values",
"=",
"[",
"]",
"for",
"i",
"in",
"range",
"(",
"count",
")",
":",
"start",
"=",
"i",
"*"... | Getters for data that also work with implicit transfersyntax
:param count: number of items in the array
:param tag: the tag to read | [
"Getters",
"for",
"data",
"that",
"also",
"work",
"with",
"implicit",
"transfersyntax"
] | train | https://github.com/icometrix/dicom2nifti/blob/1462ae5dd979fa3f276fe7a78ceb9b028121536f/dicom2nifti/common.py#L280-L294 |
icometrix/dicom2nifti | dicom2nifti/common.py | get_fd_value | def get_fd_value(tag):
"""
Getters for data that also work with implicit transfersyntax
:param tag: the tag to read
"""
if tag.VR == 'OB' or tag.VR == 'UN':
value = struct.unpack('d', tag.value)[0]
return value
return tag.value | python | def get_fd_value(tag):
"""
Getters for data that also work with implicit transfersyntax
:param tag: the tag to read
"""
if tag.VR == 'OB' or tag.VR == 'UN':
value = struct.unpack('d', tag.value)[0]
return value
return tag.value | [
"def",
"get_fd_value",
"(",
"tag",
")",
":",
"if",
"tag",
".",
"VR",
"==",
"'OB'",
"or",
"tag",
".",
"VR",
"==",
"'UN'",
":",
"value",
"=",
"struct",
".",
"unpack",
"(",
"'d'",
",",
"tag",
".",
"value",
")",
"[",
"0",
"]",
"return",
"value",
"r... | Getters for data that also work with implicit transfersyntax
:param tag: the tag to read | [
"Getters",
"for",
"data",
"that",
"also",
"work",
"with",
"implicit",
"transfersyntax"
] | train | https://github.com/icometrix/dicom2nifti/blob/1462ae5dd979fa3f276fe7a78ceb9b028121536f/dicom2nifti/common.py#L297-L306 |
icometrix/dicom2nifti | dicom2nifti/common.py | set_fd_value | def set_fd_value(tag, value):
"""
Setters for data that also work with implicit transfersyntax
:param value: the value to set on the tag
:param tag: the tag to read
"""
if tag.VR == 'OB' or tag.VR == 'UN':
value = struct.pack('d', value)
tag.value = value | python | def set_fd_value(tag, value):
"""
Setters for data that also work with implicit transfersyntax
:param value: the value to set on the tag
:param tag: the tag to read
"""
if tag.VR == 'OB' or tag.VR == 'UN':
value = struct.pack('d', value)
tag.value = value | [
"def",
"set_fd_value",
"(",
"tag",
",",
"value",
")",
":",
"if",
"tag",
".",
"VR",
"==",
"'OB'",
"or",
"tag",
".",
"VR",
"==",
"'UN'",
":",
"value",
"=",
"struct",
".",
"pack",
"(",
"'d'",
",",
"value",
")",
"tag",
".",
"value",
"=",
"value"
] | Setters for data that also work with implicit transfersyntax
:param value: the value to set on the tag
:param tag: the tag to read | [
"Setters",
"for",
"data",
"that",
"also",
"work",
"with",
"implicit",
"transfersyntax"
] | train | https://github.com/icometrix/dicom2nifti/blob/1462ae5dd979fa3f276fe7a78ceb9b028121536f/dicom2nifti/common.py#L309-L318 |
icometrix/dicom2nifti | dicom2nifti/common.py | get_fl_value | def get_fl_value(tag):
"""
Getters for data that also work with implicit transfersyntax
:param tag: the tag to read
"""
if tag.VR == 'OB' or tag.VR == 'UN':
value = struct.unpack('f', tag.value)[0]
return value
return tag.value | python | def get_fl_value(tag):
"""
Getters for data that also work with implicit transfersyntax
:param tag: the tag to read
"""
if tag.VR == 'OB' or tag.VR == 'UN':
value = struct.unpack('f', tag.value)[0]
return value
return tag.value | [
"def",
"get_fl_value",
"(",
"tag",
")",
":",
"if",
"tag",
".",
"VR",
"==",
"'OB'",
"or",
"tag",
".",
"VR",
"==",
"'UN'",
":",
"value",
"=",
"struct",
".",
"unpack",
"(",
"'f'",
",",
"tag",
".",
"value",
")",
"[",
"0",
"]",
"return",
"value",
"r... | Getters for data that also work with implicit transfersyntax
:param tag: the tag to read | [
"Getters",
"for",
"data",
"that",
"also",
"work",
"with",
"implicit",
"transfersyntax"
] | train | https://github.com/icometrix/dicom2nifti/blob/1462ae5dd979fa3f276fe7a78ceb9b028121536f/dicom2nifti/common.py#L321-L330 |
icometrix/dicom2nifti | dicom2nifti/common.py | get_is_value | def get_is_value(tag):
"""
Getters for data that also work with implicit transfersyntax
:param tag: the tag to read
"""
# data is int formatted as string so convert te string first and cast to int
if tag.VR == 'OB' or tag.VR == 'UN':
value = int(tag.value.decode("ascii").replace(" ", ""... | python | def get_is_value(tag):
"""
Getters for data that also work with implicit transfersyntax
:param tag: the tag to read
"""
# data is int formatted as string so convert te string first and cast to int
if tag.VR == 'OB' or tag.VR == 'UN':
value = int(tag.value.decode("ascii").replace(" ", ""... | [
"def",
"get_is_value",
"(",
"tag",
")",
":",
"# data is int formatted as string so convert te string first and cast to int",
"if",
"tag",
".",
"VR",
"==",
"'OB'",
"or",
"tag",
".",
"VR",
"==",
"'UN'",
":",
"value",
"=",
"int",
"(",
"tag",
".",
"value",
".",
"d... | Getters for data that also work with implicit transfersyntax
:param tag: the tag to read | [
"Getters",
"for",
"data",
"that",
"also",
"work",
"with",
"implicit",
"transfersyntax"
] | train | https://github.com/icometrix/dicom2nifti/blob/1462ae5dd979fa3f276fe7a78ceb9b028121536f/dicom2nifti/common.py#L333-L343 |
icometrix/dicom2nifti | dicom2nifti/common.py | get_ss_value | def get_ss_value(tag):
"""
Getters for data that also work with implicit transfersyntax
:param tag: the tag to read
"""
# data is int formatted as string so convert te string first and cast to int
if tag.VR == 'OB' or tag.VR == 'UN':
value = struct.unpack('h', tag.value)[0]
retu... | python | def get_ss_value(tag):
"""
Getters for data that also work with implicit transfersyntax
:param tag: the tag to read
"""
# data is int formatted as string so convert te string first and cast to int
if tag.VR == 'OB' or tag.VR == 'UN':
value = struct.unpack('h', tag.value)[0]
retu... | [
"def",
"get_ss_value",
"(",
"tag",
")",
":",
"# data is int formatted as string so convert te string first and cast to int",
"if",
"tag",
".",
"VR",
"==",
"'OB'",
"or",
"tag",
".",
"VR",
"==",
"'UN'",
":",
"value",
"=",
"struct",
".",
"unpack",
"(",
"'h'",
",",
... | Getters for data that also work with implicit transfersyntax
:param tag: the tag to read | [
"Getters",
"for",
"data",
"that",
"also",
"work",
"with",
"implicit",
"transfersyntax"
] | train | https://github.com/icometrix/dicom2nifti/blob/1462ae5dd979fa3f276fe7a78ceb9b028121536f/dicom2nifti/common.py#L346-L356 |
icometrix/dicom2nifti | dicom2nifti/common.py | set_ss_value | def set_ss_value(tag, value):
"""
Setter for data that also work with implicit transfersyntax
:param value: the value to set on the tag
:param tag: the tag to read
"""
if tag.VR == 'OB' or tag.VR == 'UN':
value = struct.pack('h', value)
tag.value = value | python | def set_ss_value(tag, value):
"""
Setter for data that also work with implicit transfersyntax
:param value: the value to set on the tag
:param tag: the tag to read
"""
if tag.VR == 'OB' or tag.VR == 'UN':
value = struct.pack('h', value)
tag.value = value | [
"def",
"set_ss_value",
"(",
"tag",
",",
"value",
")",
":",
"if",
"tag",
".",
"VR",
"==",
"'OB'",
"or",
"tag",
".",
"VR",
"==",
"'UN'",
":",
"value",
"=",
"struct",
".",
"pack",
"(",
"'h'",
",",
"value",
")",
"tag",
".",
"value",
"=",
"value"
] | Setter for data that also work with implicit transfersyntax
:param value: the value to set on the tag
:param tag: the tag to read | [
"Setter",
"for",
"data",
"that",
"also",
"work",
"with",
"implicit",
"transfersyntax"
] | train | https://github.com/icometrix/dicom2nifti/blob/1462ae5dd979fa3f276fe7a78ceb9b028121536f/dicom2nifti/common.py#L359-L368 |
icometrix/dicom2nifti | dicom2nifti/common.py | apply_scaling | def apply_scaling(data, dicom_headers):
"""
Rescale the data based on the RescaleSlope and RescaleOffset
Based on the scaling from pydicomseries
:param dicom_headers: dicom headers to use to retreive the scaling factors
:param data: the input data
"""
# Apply the rescaling if needed
pr... | python | def apply_scaling(data, dicom_headers):
"""
Rescale the data based on the RescaleSlope and RescaleOffset
Based on the scaling from pydicomseries
:param dicom_headers: dicom headers to use to retreive the scaling factors
:param data: the input data
"""
# Apply the rescaling if needed
pr... | [
"def",
"apply_scaling",
"(",
"data",
",",
"dicom_headers",
")",
":",
"# Apply the rescaling if needed",
"private_scale_slope_tag",
"=",
"Tag",
"(",
"0x2005",
",",
"0x100E",
")",
"private_scale_intercept_tag",
"=",
"Tag",
"(",
"0x2005",
",",
"0x100D",
")",
"if",
"'... | Rescale the data based on the RescaleSlope and RescaleOffset
Based on the scaling from pydicomseries
:param dicom_headers: dicom headers to use to retreive the scaling factors
:param data: the input data | [
"Rescale",
"the",
"data",
"based",
"on",
"the",
"RescaleSlope",
"and",
"RescaleOffset",
"Based",
"on",
"the",
"scaling",
"from",
"pydicomseries"
] | train | https://github.com/icometrix/dicom2nifti/blob/1462ae5dd979fa3f276fe7a78ceb9b028121536f/dicom2nifti/common.py#L371-L401 |
icometrix/dicom2nifti | dicom2nifti/common.py | write_bvec_file | def write_bvec_file(bvecs, bvec_file):
"""
Write an array of bvecs to a bvec file
:param bvecs: array with the vectors
:param bvec_file: filepath to write to
"""
if bvec_file is None:
return
logger.info('Saving BVEC file: %s' % bvec_file)
with open(bvec_file, 'w') as text_file:
... | python | def write_bvec_file(bvecs, bvec_file):
"""
Write an array of bvecs to a bvec file
:param bvecs: array with the vectors
:param bvec_file: filepath to write to
"""
if bvec_file is None:
return
logger.info('Saving BVEC file: %s' % bvec_file)
with open(bvec_file, 'w') as text_file:
... | [
"def",
"write_bvec_file",
"(",
"bvecs",
",",
"bvec_file",
")",
":",
"if",
"bvec_file",
"is",
"None",
":",
"return",
"logger",
".",
"info",
"(",
"'Saving BVEC file: %s'",
"%",
"bvec_file",
")",
"with",
"open",
"(",
"bvec_file",
",",
"'w'",
")",
"as",
"text_... | Write an array of bvecs to a bvec file
:param bvecs: array with the vectors
:param bvec_file: filepath to write to | [
"Write",
"an",
"array",
"of",
"bvecs",
"to",
"a",
"bvec",
"file"
] | train | https://github.com/icometrix/dicom2nifti/blob/1462ae5dd979fa3f276fe7a78ceb9b028121536f/dicom2nifti/common.py#L478-L492 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.