repo
stringlengths
7
55
path
stringlengths
4
127
func_name
stringlengths
1
88
original_string
stringlengths
75
19.8k
language
stringclasses
1 value
code
stringlengths
75
19.8k
code_tokens
list
docstring
stringlengths
3
17.3k
docstring_tokens
list
sha
stringlengths
40
40
url
stringlengths
87
242
partition
stringclasses
1 value
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", "." ]
d9c6551bbc87d45d9d1f0bc15e35b616d0002afd
https://github.com/poppy-project/pypot/blob/d9c6551bbc87d45d9d1f0bc15e35b616d0002afd/pypot/dynamixel/io/abstract_io.py#L298-L300
train
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", "." ]
d9c6551bbc87d45d9d1f0bc15e35b616d0002afd
https://github.com/poppy-project/pypot/blob/d9c6551bbc87d45d9d1f0bc15e35b616d0002afd/pypot/dynamixel/io/abstract_io.py#L302-L304
train
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", "." ]
d9c6551bbc87d45d9d1f0bc15e35b616d0002afd
https://github.com/poppy-project/pypot/blob/d9c6551bbc87d45d9d1f0bc15e35b616d0002afd/pypot/dynamixel/io/abstract_io.py#L306-L308
train
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", ")", ")", "for...
Sets the pid gain to the specified motors.
[ "Sets", "the", "pid", "gain", "to", "the", "specified", "motors", "." ]
d9c6551bbc87d45d9d1f0bc15e35b616d0002afd
https://github.com/poppy-project/pypot/blob/d9c6551bbc87d45d9d1f0bc15e35b616d0002afd/pypot/dynamixel/io/abstract_io.py#L310-L314
train
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", "=", "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.
[ "Gets", "the", "full", "control", "table", "for", "the", "specified", "motors", "." ]
d9c6551bbc87d45d9d1f0bc15e35b616d0002afd
https://github.com/poppy-project/pypot/blob/d9c6551bbc87d45d9d1f0bc15e35b616d0002afd/pypot/dynamixel/io/abstract_io.py#L318-L350
train
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", "." ]
d9c6551bbc87d45d9d1f0bc15e35b616d0002afd
https://github.com/poppy-project/pypot/blob/d9c6551bbc87d45d9d1f0bc15e35b616d0002afd/pypot/robot/config.py#L209-L252
train
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" ]
1462ae5dd979fa3f276fe7a78ceb9b028121536f
https://github.com/icometrix/dicom2nifti/blob/1462ae5dd979fa3f276fe7a78ceb9b028121536f/dicom2nifti/compressed_dicom.py#L41-L55
train
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" ]
1462ae5dd979fa3f276fe7a78ceb9b028121536f
https://github.com/icometrix/dicom2nifti/blob/1462ae5dd979fa3f276fe7a78ceb9b028121536f/dicom2nifti/compressed_dicom.py#L58-L71
train
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" ]
1462ae5dd979fa3f276fe7a78ceb9b028121536f
https://github.com/icometrix/dicom2nifti/blob/1462ae5dd979fa3f276fe7a78ceb9b028121536f/dicom2nifti/compressed_dicom.py#L74-L97
train
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" ]
1462ae5dd979fa3f276fe7a78ceb9b028121536f
https://github.com/icometrix/dicom2nifti/blob/1462ae5dd979fa3f276fe7a78ceb9b028121536f/dicom2nifti/compressed_dicom.py#L100-L116
train
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" ]
1462ae5dd979fa3f276fe7a78ceb9b028121536f
https://github.com/icometrix/dicom2nifti/blob/1462ae5dd979fa3f276fe7a78ceb9b028121536f/dicom2nifti/compressed_dicom.py#L119-L127
train
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", "." ]
1462ae5dd979fa3f276fe7a78ceb9b028121536f
https://github.com/icometrix/dicom2nifti/blob/1462ae5dd979fa3f276fe7a78ceb9b028121536f/scripts/dicomdiff.py#L14-L32
train
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" ]
1462ae5dd979fa3f276fe7a78ceb9b028121536f
https://github.com/icometrix/dicom2nifti/blob/1462ae5dd979fa3f276fe7a78ceb9b028121536f/dicom2nifti/image_volume.py#L166-L175
train
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", ")", ":", "for", "root", ",", "_", ",", "file_names", "in", "os", ".", "walk", "(", "dicom_directory", ")", ":", "for", "file_name", "in", "file_names", ":", "file_path", "=", "os", ".", "path", ".", "j...
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" ]
1462ae5dd979fa3f276fe7a78ceb9b028121536f
https://github.com/icometrix/dicom2nifti/blob/1462ae5dd979fa3f276fe7a78ceb9b028121536f/dicom2nifti/convert_dicom.py#L196-L216
train
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", ")", ":", "new_image", "=", "numpy", ".", "zeros", "(", "[", "image", ".", "dimensions", "[", "image", ".", "sagittal_orientation", ".", "normal_component", "]", ",", "image", ".", "dimensions", "[", "image", ".", "coro...
Reorganize the data for a 3d nifti
[ "Reorganize", "the", "data", "for", "a", "3d", "nifti" ]
1462ae5dd979fa3f276fe7a78ceb9b028121536f
https://github.com/icometrix/dicom2nifti/blob/1462ae5dd979fa3f276fe7a78ceb9b028121536f/dicom2nifti/image_reorientation.py#L112-L133
train
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",...
1462ae5dd979fa3f276fe7a78ceb9b028121536f
https://github.com/icometrix/dicom2nifti/blob/1462ae5dd979fa3f276fe7a78ceb9b028121536f/dicom2nifti/convert_philips.py#L31-L62
train
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" ]
1462ae5dd979fa3f276fe7a78ceb9b028121536f
https://github.com/icometrix/dicom2nifti/blob/1462ae5dd979fa3f276fe7a78ceb9b028121536f/dicom2nifti/convert_philips.py#L65-L72
train
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", ")", ":", "if", "not", "common", ".", "is_multiframe_dicom", "(", "dicom_input", ")", ":", "return", "False", "header", "=", "dicom_input", "[", "0", "]", "number_of_stack_slices", "=", "common", ".", "get_ss_value...
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" ]
1462ae5dd979fa3f276fe7a78ceb9b028121536f
https://github.com/icometrix/dicom2nifti/blob/1462ae5dd979fa3f276fe7a78ceb9b028121536f/dicom2nifti/convert_philips.py#L98-L114
train
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", "]", "slice_number_mr_tag", "=", "Tag", "(", "0x2001", ",", "0x100a", ")", "if", "slice_number_mr_tag", "not", "in", "header", ":", "return", "False", "grouped_d...
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" ]
1462ae5dd979fa3f276fe7a78ceb9b028121536f
https://github.com/icometrix/dicom2nifti/blob/1462ae5dd979fa3f276fe7a78ceb9b028121536f/dicom2nifti/convert_philips.py#L139-L155
train
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" ]
1462ae5dd979fa3f276fe7a78ceb9b028121536f
https://github.com/icometrix/dicom2nifti/blob/1462ae5dd979fa3f276fe7a78ceb9b028121536f/dicom2nifti/convert_philips.py#L172-L187
train
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" ]
1462ae5dd979fa3f276fe7a78ceb9b028121536f
https://github.com/icometrix/dicom2nifti/blob/1462ae5dd979fa3f276fe7a78ceb9b028121536f/dicom2nifti/convert_philips.py#L190-L202
train
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", ")", ":", "logger", ".", "info", "(", "'Read dicom file'", ")", "multiframe_dicom", "=", "dicom_input", "[", "0", "]", "logger", ".", "info", "(", "'Creating data block'", ")", "full_block", ...
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" ]
1462ae5dd979fa3f276fe7a78ceb9b028121536f
https://github.com/icometrix/dicom2nifti/blob/1462ae5dd979fa3f276fe7a78ceb9b028121536f/dicom2nifti/convert_philips.py#L216-L268
train
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", ")", ":", "logger", ".", "info", "(", "'Creating data block'", ")", "full_block", "=", "_singleframe_to_block", "(", "grouped_dicoms", ")", "logger", ".", "info", "(", "'Creating affine'", ")...
This function will convert a philips singleframe series to a nifti
[ "This", "function", "will", "convert", "a", "philips", "singleframe", "series", "to", "a", "nifti" ]
1462ae5dd979fa3f276fe7a78ceb9b028121536f
https://github.com/icometrix/dicom2nifti/blob/1462ae5dd979fa3f276fe7a78ceb9b028121536f/dicom2nifti/convert_philips.py#L271-L322
train
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" ]
1462ae5dd979fa3f276fe7a78ceb9b028121536f
https://github.com/icometrix/dicom2nifti/blob/1462ae5dd979fa3f276fe7a78ceb9b028121536f/dicom2nifti/convert_philips.py#L393-L419
train
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", ")", ":", "number_of_stack_slices", "=", "int", "(", "common", ".", "get_ss_value", "(", "multiframe_dicom", "[", "Tag", "(", "0x2001", ",", "0x105f", ")", "]", "[", "0", "]", "[", "Tag", "(", "0x2001",...
Generate a full datablock containing all stacks
[ "Generate", "a", "full", "datablock", "containing", "all", "stacks" ]
1462ae5dd979fa3f276fe7a78ceb9b028121536f
https://github.com/icometrix/dicom2nifti/blob/1462ae5dd979fa3f276fe7a78ceb9b028121536f/dicom2nifti/convert_philips.py#L422-L473
train
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", "numpy", ".", "count_nonzero", "(", "bvecs", ")", "==", "0", "or", "not", "numpy", ".", "count_nonzero", "(", "bvals", "[", "-", "1", "]", ")",...
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" ]
1462ae5dd979fa3f276fe7a78ceb9b028121536f
https://github.com/icometrix/dicom2nifti/blob/1462ae5dd979fa3f276fe7a78ceb9b028121536f/dicom2nifti/convert_philips.py#L548-L565
train
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'", ")", "dicom_input", "=", "_remove_duplicate_slices", "(", "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" ]
1462ae5dd979fa3f276fe7a78ceb9b028121536f
https://github.com/icometrix/dicom2nifti/blob/1462ae5dd979fa3f276fe7a78ceb9b028121536f/dicom2nifti/convert_generic.py#L29-L94
train
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", ")", ":", "increment", "=", "numpy", ".", "array", "(", "dicom_input", "[", "0", "]", ".", "ImagePositionPatient", ")", "-", "numpy", ".", "array", "(", "dicom_input", "[", "1", "]", ".", ...
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",...
1462ae5dd979fa3f276fe7a78ceb9b028121536f
https://github.com/icometrix/dicom2nifti/blob/1462ae5dd979fa3f276fe7a78ceb9b028121536f/dicom2nifti/convert_generic.py#L174-L209
train
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", ")", ":", "header", "=", "dicom_input", "[", "0", "]", "if", "'Manufacturer'", "not", "in", "header", "or", "'Modality'", "not", "in", "header", ":", "return", "False", "if", "header", ".", "Modality", ".", "upper",...
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" ]
1462ae5dd979fa3f276fe7a78ceb9b028121536f
https://github.com/icometrix/dicom2nifti/blob/1462ae5dd979fa3f276fe7a78ceb9b028121536f/dicom2nifti/common.py#L57-L77
train
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", ")", ":", "header", "=", "dicom_input", "[", "0", "]", "if", "'Manufacturer'", "not", "in", "header", "or", "'Modality'", "not", "in", "header", ":", "return", "False", "if", "header", ".", "Modality", ".", "upper", "(...
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" ]
1462ae5dd979fa3f276fe7a78ceb9b028121536f
https://github.com/icometrix/dicom2nifti/blob/1462ae5dd979fa3f276fe7a78ceb9b028121536f/dicom2nifti/common.py#L80-L100
train
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", ")", ":", "header", "=", "dicom_input", "[", "0", "]", "if", "'Manufacturer'", "not", "in", "header", "or", "'Modality'", "not", "in", "header", ":", "return", "False", "if", "header", ".", "Modality", ".", "upper",...
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" ]
1462ae5dd979fa3f276fe7a78ceb9b028121536f
https://github.com/icometrix/dicom2nifti/blob/1462ae5dd979fa3f276fe7a78ceb9b028121536f/dicom2nifti/common.py#L103-L123
train
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", ")", ":", "header", "=", "dicom_input", "[", "0", "]", "if", "'Manufacturer'", "not", "in", "header", "or", "'Modality'", "not", "in", "header", ":", "return", "False", "if", "header", ".", "Modality", ".", "upper",...
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" ]
1462ae5dd979fa3f276fe7a78ceb9b028121536f
https://github.com/icometrix/dicom2nifti/blob/1462ae5dd979fa3f276fe7a78ceb9b028121536f/dicom2nifti/common.py#L126-L146
train
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", "if", "dicom_slice", ".", "BitsAllocated", "!=", "dicom_slice", ".", "BitsStored", "and", "dicom_slice", ".", "HighBit", "==", "dicom_slice", ".", "BitsSto...
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" ]
1462ae5dd979fa3f276fe7a78ceb9b028121536f
https://github.com/icometrix/dicom2nifti/blob/1462ae5dd979fa3f276fe7a78ceb9b028121536f/dicom2nifti/common.py#L225-L245
train
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" ]
1462ae5dd979fa3f276fe7a78ceb9b028121536f
https://github.com/icometrix/dicom2nifti/blob/1462ae5dd979fa3f276fe7a78ceb9b028121536f/dicom2nifti/common.py#L309-L318
train
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" ]
1462ae5dd979fa3f276fe7a78ceb9b028121536f
https://github.com/icometrix/dicom2nifti/blob/1462ae5dd979fa3f276fe7a78ceb9b028121536f/dicom2nifti/common.py#L359-L368
train
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", ")", ":", "private_scale_slope_tag", "=", "Tag", "(", "0x2005", ",", "0x100E", ")", "private_scale_intercept_tag", "=", "Tag", "(", "0x2005", ",", "0x100D", ")", "if", "'RescaleSlope'", "in", "dicom_head...
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" ]
1462ae5dd979fa3f276fe7a78ceb9b028121536f
https://github.com/icometrix/dicom2nifti/blob/1462ae5dd979fa3f276fe7a78ceb9b028121536f/dicom2nifti/common.py#L371-L401
train
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" ]
1462ae5dd979fa3f276fe7a78ceb9b028121536f
https://github.com/icometrix/dicom2nifti/blob/1462ae5dd979fa3f276fe7a78ceb9b028121536f/dicom2nifti/common.py#L478-L492
train
icometrix/dicom2nifti
dicom2nifti/common.py
write_bval_file
def write_bval_file(bvals, bval_file): """ Write an array of bvals to a bval file :param bvals: array with the values :param bval_file: filepath to write to """ if bval_file is None: return logger.info('Saving BVAL file: %s' % bval_file) with open(bval_file, 'w') as text_file: ...
python
def write_bval_file(bvals, bval_file): """ Write an array of bvals to a bval file :param bvals: array with the values :param bval_file: filepath to write to """ if bval_file is None: return logger.info('Saving BVAL file: %s' % bval_file) with open(bval_file, 'w') as text_file: ...
[ "def", "write_bval_file", "(", "bvals", ",", "bval_file", ")", ":", "if", "bval_file", "is", "None", ":", "return", "logger", ".", "info", "(", "'Saving BVAL file: %s'", "%", "bval_file", ")", "with", "open", "(", "bval_file", ",", "'w'", ")", "as", "text_...
Write an array of bvals to a bval file :param bvals: array with the values :param bval_file: filepath to write to
[ "Write", "an", "array", "of", "bvals", "to", "a", "bval", "file" ]
1462ae5dd979fa3f276fe7a78ceb9b028121536f
https://github.com/icometrix/dicom2nifti/blob/1462ae5dd979fa3f276fe7a78ceb9b028121536f/dicom2nifti/common.py#L495-L507
train
icometrix/dicom2nifti
dicom2nifti/common.py
sort_dicoms
def sort_dicoms(dicoms): """ Sort the dicoms based om the image possition patient :param dicoms: list of dicoms """ # find most significant axis to use during sorting # the original way of sorting (first x than y than z) does not work in certain border situations # where for exampe the X wi...
python
def sort_dicoms(dicoms): """ Sort the dicoms based om the image possition patient :param dicoms: list of dicoms """ # find most significant axis to use during sorting # the original way of sorting (first x than y than z) does not work in certain border situations # where for exampe the X wi...
[ "def", "sort_dicoms", "(", "dicoms", ")", ":", "dicom_input_sorted_x", "=", "sorted", "(", "dicoms", ",", "key", "=", "lambda", "x", ":", "(", "x", ".", "ImagePositionPatient", "[", "0", "]", ")", ")", "dicom_input_sorted_y", "=", "sorted", "(", "dicoms", ...
Sort the dicoms based om the image possition patient :param dicoms: list of dicoms
[ "Sort", "the", "dicoms", "based", "om", "the", "image", "possition", "patient" ]
1462ae5dd979fa3f276fe7a78ceb9b028121536f
https://github.com/icometrix/dicom2nifti/blob/1462ae5dd979fa3f276fe7a78ceb9b028121536f/dicom2nifti/common.py#L614-L635
train
icometrix/dicom2nifti
dicom2nifti/common.py
validate_orientation
def validate_orientation(dicoms): """ Validate that all dicoms have the same orientation :param dicoms: list of dicoms """ first_image_orient1 = numpy.array(dicoms[0].ImageOrientationPatient)[0:3] first_image_orient2 = numpy.array(dicoms[0].ImageOrientationPatient)[3:6] for dicom_ in dicoms...
python
def validate_orientation(dicoms): """ Validate that all dicoms have the same orientation :param dicoms: list of dicoms """ first_image_orient1 = numpy.array(dicoms[0].ImageOrientationPatient)[0:3] first_image_orient2 = numpy.array(dicoms[0].ImageOrientationPatient)[3:6] for dicom_ in dicoms...
[ "def", "validate_orientation", "(", "dicoms", ")", ":", "first_image_orient1", "=", "numpy", ".", "array", "(", "dicoms", "[", "0", "]", ".", "ImageOrientationPatient", ")", "[", "0", ":", "3", "]", "first_image_orient2", "=", "numpy", ".", "array", "(", "...
Validate that all dicoms have the same orientation :param dicoms: list of dicoms
[ "Validate", "that", "all", "dicoms", "have", "the", "same", "orientation" ]
1462ae5dd979fa3f276fe7a78ceb9b028121536f
https://github.com/icometrix/dicom2nifti/blob/1462ae5dd979fa3f276fe7a78ceb9b028121536f/dicom2nifti/common.py#L696-L715
train
icometrix/dicom2nifti
dicom2nifti/common.py
set_tr_te
def set_tr_te(nifti_image, repetition_time, echo_time): """ Set the tr and te in the nifti headers :param echo_time: echo time :param repetition_time: repetition time :param nifti_image: nifti image to set the info to """ # set the repetition time in pixdim nifti_image.header.structarr[...
python
def set_tr_te(nifti_image, repetition_time, echo_time): """ Set the tr and te in the nifti headers :param echo_time: echo time :param repetition_time: repetition time :param nifti_image: nifti image to set the info to """ # set the repetition time in pixdim nifti_image.header.structarr[...
[ "def", "set_tr_te", "(", "nifti_image", ",", "repetition_time", ",", "echo_time", ")", ":", "nifti_image", ".", "header", ".", "structarr", "[", "'pixdim'", "]", "[", "4", "]", "=", "repetition_time", "/", "1000.0", "nifti_image", ".", "header", ".", "struct...
Set the tr and te in the nifti headers :param echo_time: echo time :param repetition_time: repetition time :param nifti_image: nifti image to set the info to
[ "Set", "the", "tr", "and", "te", "in", "the", "nifti", "headers" ]
1462ae5dd979fa3f276fe7a78ceb9b028121536f
https://github.com/icometrix/dicom2nifti/blob/1462ae5dd979fa3f276fe7a78ceb9b028121536f/dicom2nifti/common.py#L718-L732
train
icometrix/dicom2nifti
dicom2nifti/convert_ge.py
dicom_to_nifti
def dicom_to_nifti(dicom_input, output_file=None): """ This is the main dicom to nifti conversion fuction for ge images. As input ge images are required. It will then determine the type of images and do the correct conversion Examples: See unit test :param output_file: the filepath to the output n...
python
def dicom_to_nifti(dicom_input, output_file=None): """ This is the main dicom to nifti conversion fuction for ge images. As input ge images are required. It will then determine the type of images and do the correct conversion Examples: See unit test :param output_file: the filepath to the output n...
[ "def", "dicom_to_nifti", "(", "dicom_input", ",", "output_file", "=", "None", ")", ":", "assert", "common", ".", "is_ge", "(", "dicom_input", ")", "logger", ".", "info", "(", "'Reading and sorting dicom files'", ")", "grouped_dicoms", "=", "_get_grouped_dicoms", "...
This is the main dicom to nifti conversion fuction for ge images. As input ge images are required. It will then determine the type of images and do the correct conversion Examples: See unit test :param output_file: the filepath to the output nifti file :param dicom_input: list with dicom objects
[ "This", "is", "the", "main", "dicom", "to", "nifti", "conversion", "fuction", "for", "ge", "images", ".", "As", "input", "ge", "images", "are", "required", ".", "It", "will", "then", "determine", "the", "type", "of", "images", "and", "do", "the", "correc...
1462ae5dd979fa3f276fe7a78ceb9b028121536f
https://github.com/icometrix/dicom2nifti/blob/1462ae5dd979fa3f276fe7a78ceb9b028121536f/dicom2nifti/convert_ge.py#L32-L52
train
icometrix/dicom2nifti
dicom2nifti/convert_ge.py
_4d_to_nifti
def _4d_to_nifti(grouped_dicoms, output_file): """ This function will convert ge 4d series to a nifti """ # Create mosaic block logger.info('Creating data block') full_block = _get_full_block(grouped_dicoms) logger.info('Creating affine') # Create the nifti header info affine, slic...
python
def _4d_to_nifti(grouped_dicoms, output_file): """ This function will convert ge 4d series to a nifti """ # Create mosaic block logger.info('Creating data block') full_block = _get_full_block(grouped_dicoms) logger.info('Creating affine') # Create the nifti header info affine, slic...
[ "def", "_4d_to_nifti", "(", "grouped_dicoms", ",", "output_file", ")", ":", "logger", ".", "info", "(", "'Creating data block'", ")", "full_block", "=", "_get_full_block", "(", "grouped_dicoms", ")", "logger", ".", "info", "(", "'Creating affine'", ")", "affine", ...
This function will convert ge 4d series to a nifti
[ "This", "function", "will", "convert", "ge", "4d", "series", "to", "a", "nifti" ]
1462ae5dd979fa3f276fe7a78ceb9b028121536f
https://github.com/icometrix/dicom2nifti/blob/1462ae5dd979fa3f276fe7a78ceb9b028121536f/dicom2nifti/convert_ge.py#L91-L136
train
icometrix/dicom2nifti
dicom2nifti/convert_hitachi.py
dicom_to_nifti
def dicom_to_nifti(dicom_input, output_file=None): """ This is the main dicom to nifti conversion fuction for hitachi images. As input hitachi 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 hitachi images. As input hitachi 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_hitachi", "(", "dicom_input", ")", "logger", ".", "info", "(", "'Assuming anatomical data'", ")", "return", "convert_generic", ".", "dicom_to_nifti...
This is the main dicom to nifti conversion fuction for hitachi images. As input hitachi 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", "hitachi", "images", ".", "As", "input", "hitachi", "images", "are", "required", ".", "It", "will", "then", "determine", "the", "type", "of", "images", "and", "do", "the",...
1462ae5dd979fa3f276fe7a78ceb9b028121536f
https://github.com/icometrix/dicom2nifti/blob/1462ae5dd979fa3f276fe7a78ceb9b028121536f/dicom2nifti/convert_hitachi.py#L25-L41
train
icometrix/dicom2nifti
dicom2nifti/convert_siemens.py
dicom_to_nifti
def dicom_to_nifti(dicom_input, output_file=None): """ This is the main dicom to nifti conversion function for ge images. As input ge images are required. It will then determine the type of images and do the correct conversion :param output_file: filepath to the output nifti :param dicom_input: dir...
python
def dicom_to_nifti(dicom_input, output_file=None): """ This is the main dicom to nifti conversion function for ge images. As input ge images are required. It will then determine the type of images and do the correct conversion :param output_file: filepath to the output nifti :param dicom_input: dir...
[ "def", "dicom_to_nifti", "(", "dicom_input", ",", "output_file", "=", "None", ")", ":", "assert", "common", ".", "is_siemens", "(", "dicom_input", ")", "if", "_is_4d", "(", "dicom_input", ")", ":", "logger", ".", "info", "(", "'Found sequence type: MOSAIC 4D'", ...
This is the main dicom to nifti conversion function for ge images. As input ge images are required. It will then determine the type of images and do the correct conversion :param output_file: filepath to the output nifti :param dicom_input: directory with dicom files for 1 scan
[ "This", "is", "the", "main", "dicom", "to", "nifti", "conversion", "function", "for", "ge", "images", ".", "As", "input", "ge", "images", "are", "required", ".", "It", "will", "then", "determine", "the", "type", "of", "images", "and", "do", "the", "corre...
1462ae5dd979fa3f276fe7a78ceb9b028121536f
https://github.com/icometrix/dicom2nifti/blob/1462ae5dd979fa3f276fe7a78ceb9b028121536f/dicom2nifti/convert_siemens.py#L45-L66
train
icometrix/dicom2nifti
dicom2nifti/convert_siemens.py
_get_sorted_mosaics
def _get_sorted_mosaics(dicom_input): """ Search all mosaics in the dicom directory, sort and validate them """ # Order all dicom files by acquisition number sorted_mosaics = sorted(dicom_input, key=lambda x: x.AcquisitionNumber) for index in range(0, len(sorted_mosaics) - 1): # Validat...
python
def _get_sorted_mosaics(dicom_input): """ Search all mosaics in the dicom directory, sort and validate them """ # Order all dicom files by acquisition number sorted_mosaics = sorted(dicom_input, key=lambda x: x.AcquisitionNumber) for index in range(0, len(sorted_mosaics) - 1): # Validat...
[ "def", "_get_sorted_mosaics", "(", "dicom_input", ")", ":", "sorted_mosaics", "=", "sorted", "(", "dicom_input", ",", "key", "=", "lambda", "x", ":", "x", ".", "AcquisitionNumber", ")", "for", "index", "in", "range", "(", "0", ",", "len", "(", "sorted_mosa...
Search all mosaics in the dicom directory, sort and validate them
[ "Search", "all", "mosaics", "in", "the", "dicom", "directory", "sort", "and", "validate", "them" ]
1462ae5dd979fa3f276fe7a78ceb9b028121536f
https://github.com/icometrix/dicom2nifti/blob/1462ae5dd979fa3f276fe7a78ceb9b028121536f/dicom2nifti/convert_siemens.py#L324-L336
train
icometrix/dicom2nifti
dicom2nifti/convert_siemens.py
_mosaic_to_block
def _mosaic_to_block(mosaic): """ Convert a mosaic slice to a block of data by reading the headers, splitting the mosaic and appending """ # get the mosaic type mosaic_type = _get_mosaic_type(mosaic) # get the size of one tile format is 64p*64 or 80*80 or something similar matches = re.find...
python
def _mosaic_to_block(mosaic): """ Convert a mosaic slice to a block of data by reading the headers, splitting the mosaic and appending """ # get the mosaic type mosaic_type = _get_mosaic_type(mosaic) # get the size of one tile format is 64p*64 or 80*80 or something similar matches = re.find...
[ "def", "_mosaic_to_block", "(", "mosaic", ")", ":", "mosaic_type", "=", "_get_mosaic_type", "(", "mosaic", ")", "matches", "=", "re", ".", "findall", "(", "r'(\\d+)\\D+(\\d+)\\D*'", ",", "str", "(", "mosaic", "[", "Tag", "(", "0x0051", ",", "0x100b", ")", ...
Convert a mosaic slice to a block of data by reading the headers, splitting the mosaic and appending
[ "Convert", "a", "mosaic", "slice", "to", "a", "block", "of", "data", "by", "reading", "the", "headers", "splitting", "the", "mosaic", "and", "appending" ]
1462ae5dd979fa3f276fe7a78ceb9b028121536f
https://github.com/icometrix/dicom2nifti/blob/1462ae5dd979fa3f276fe7a78ceb9b028121536f/dicom2nifti/convert_siemens.py#L399-L440
train
icometrix/dicom2nifti
dicom2nifti/convert_siemens.py
_create_affine_siemens_mosaic
def _create_affine_siemens_mosaic(dicom_input): """ Function to create the affine matrix for a siemens mosaic dataset This will work for siemens dti and 4d if in mosaic format """ # read dicom series with pds dicom_header = dicom_input[0] # Create affine matrix (http://nipy.sourceforge.net/...
python
def _create_affine_siemens_mosaic(dicom_input): """ Function to create the affine matrix for a siemens mosaic dataset This will work for siemens dti and 4d if in mosaic format """ # read dicom series with pds dicom_header = dicom_input[0] # Create affine matrix (http://nipy.sourceforge.net/...
[ "def", "_create_affine_siemens_mosaic", "(", "dicom_input", ")", ":", "dicom_header", "=", "dicom_input", "[", "0", "]", "image_orient1", "=", "numpy", ".", "array", "(", "dicom_header", ".", "ImageOrientationPatient", ")", "[", "0", ":", "3", "]", "image_orient...
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" ]
1462ae5dd979fa3f276fe7a78ceb9b028121536f
https://github.com/icometrix/dicom2nifti/blob/1462ae5dd979fa3f276fe7a78ceb9b028121536f/dicom2nifti/convert_siemens.py#L443-L467
train
icometrix/dicom2nifti
dicom2nifti/resample.py
resample_single_nifti
def resample_single_nifti(input_nifti): """ Resample a gantry tilted image in place """ # read the input image input_image = nibabel.load(input_nifti) output_image = resample_nifti_images([input_image]) output_image.to_filename(input_nifti)
python
def resample_single_nifti(input_nifti): """ Resample a gantry tilted image in place """ # read the input image input_image = nibabel.load(input_nifti) output_image = resample_nifti_images([input_image]) output_image.to_filename(input_nifti)
[ "def", "resample_single_nifti", "(", "input_nifti", ")", ":", "input_image", "=", "nibabel", ".", "load", "(", "input_nifti", ")", "output_image", "=", "resample_nifti_images", "(", "[", "input_image", "]", ")", "output_image", ".", "to_filename", "(", "input_nift...
Resample a gantry tilted image in place
[ "Resample", "a", "gantry", "tilted", "image", "in", "place" ]
1462ae5dd979fa3f276fe7a78ceb9b028121536f
https://github.com/icometrix/dicom2nifti/blob/1462ae5dd979fa3f276fe7a78ceb9b028121536f/dicom2nifti/resample.py#L15-L22
train
icometrix/dicom2nifti
dicom2nifti/convert_dir.py
convert_directory
def convert_directory(dicom_directory, output_folder, compression=True, reorient=True): """ This function will order all dicom files by series and order them one by one :param compression: enable or disable gzip compression :param reorient: reorient the dicoms according to LAS orientation :param ou...
python
def convert_directory(dicom_directory, output_folder, compression=True, reorient=True): """ This function will order all dicom files by series and order them one by one :param compression: enable or disable gzip compression :param reorient: reorient the dicoms according to LAS orientation :param ou...
[ "def", "convert_directory", "(", "dicom_directory", ",", "output_folder", ",", "compression", "=", "True", ",", "reorient", "=", "True", ")", ":", "dicom_series", "=", "{", "}", "for", "root", ",", "_", ",", "files", "in", "os", ".", "walk", "(", "dicom_...
This function will order all dicom files by series and order them one by one :param compression: enable or disable gzip compression :param reorient: reorient the dicoms according to LAS orientation :param output_folder: folder to write the nifti files to :param dicom_directory: directory with dicom fil...
[ "This", "function", "will", "order", "all", "dicom", "files", "by", "series", "and", "order", "them", "one", "by", "one" ]
1462ae5dd979fa3f276fe7a78ceb9b028121536f
https://github.com/icometrix/dicom2nifti/blob/1462ae5dd979fa3f276fe7a78ceb9b028121536f/dicom2nifti/convert_dir.py#L34-L99
train
aegirhall/console-menu
consolemenu/menu_formatter.py
MenuFormatBuilder.clear_data
def clear_data(self): """ Clear menu data from previous menu generation. """ self.__header.title = None self.__header.subtitle = None self.__prologue.text = None self.__epilogue.text = None self.__items_section.items = None
python
def clear_data(self): """ Clear menu data from previous menu generation. """ self.__header.title = None self.__header.subtitle = None self.__prologue.text = None self.__epilogue.text = None self.__items_section.items = None
[ "def", "clear_data", "(", "self", ")", ":", "self", ".", "__header", ".", "title", "=", "None", "self", ".", "__header", ".", "subtitle", "=", "None", "self", ".", "__prologue", ".", "text", "=", "None", "self", ".", "__epilogue", ".", "text", "=", "...
Clear menu data from previous menu generation.
[ "Clear", "menu", "data", "from", "previous", "menu", "generation", "." ]
1a28959d6f1dd6ac79c87b11efd8529d05532422
https://github.com/aegirhall/console-menu/blob/1a28959d6f1dd6ac79c87b11efd8529d05532422/consolemenu/menu_formatter.py#L246-L254
train
aegirhall/console-menu
consolemenu/menu_component.py
MenuComponent.inner_horizontal_border
def inner_horizontal_border(self): """ The complete inner horizontal border section, including the left and right border verticals. Returns: str: The complete inner horizontal border. """ return u"{lm}{lv}{hz}{rv}".format(lm=' ' * self.margins.left, ...
python
def inner_horizontal_border(self): """ The complete inner horizontal border section, including the left and right border verticals. Returns: str: The complete inner horizontal border. """ return u"{lm}{lv}{hz}{rv}".format(lm=' ' * self.margins.left, ...
[ "def", "inner_horizontal_border", "(", "self", ")", ":", "return", "u\"{lm}{lv}{hz}{rv}\"", ".", "format", "(", "lm", "=", "' '", "*", "self", ".", "margins", ".", "left", ",", "lv", "=", "self", ".", "border_style", ".", "outer_vertical_inner_right", ",", "...
The complete inner horizontal border section, including the left and right border verticals. Returns: str: The complete inner horizontal border.
[ "The", "complete", "inner", "horizontal", "border", "section", "including", "the", "left", "and", "right", "border", "verticals", "." ]
1a28959d6f1dd6ac79c87b11efd8529d05532422
https://github.com/aegirhall/console-menu/blob/1a28959d6f1dd6ac79c87b11efd8529d05532422/consolemenu/menu_component.py#L123-L133
train
aegirhall/console-menu
consolemenu/menu_component.py
MenuComponent.outer_horizontal_border_bottom
def outer_horizontal_border_bottom(self): """ The complete outer bottom horizontal border section, including left and right margins. Returns: str: The bottom menu border. """ return u"{lm}{lv}{hz}{rv}".format(lm=' ' * self.margins.left, ...
python
def outer_horizontal_border_bottom(self): """ The complete outer bottom horizontal border section, including left and right margins. Returns: str: The bottom menu border. """ return u"{lm}{lv}{hz}{rv}".format(lm=' ' * self.margins.left, ...
[ "def", "outer_horizontal_border_bottom", "(", "self", ")", ":", "return", "u\"{lm}{lv}{hz}{rv}\"", ".", "format", "(", "lm", "=", "' '", "*", "self", ".", "margins", ".", "left", ",", "lv", "=", "self", ".", "border_style", ".", "bottom_left_corner", ",", "r...
The complete outer bottom horizontal border section, including left and right margins. Returns: str: The bottom menu border.
[ "The", "complete", "outer", "bottom", "horizontal", "border", "section", "including", "left", "and", "right", "margins", "." ]
1a28959d6f1dd6ac79c87b11efd8529d05532422
https://github.com/aegirhall/console-menu/blob/1a28959d6f1dd6ac79c87b11efd8529d05532422/consolemenu/menu_component.py#L145-L155
train
aegirhall/console-menu
consolemenu/menu_component.py
MenuComponent.outer_horizontal_border_top
def outer_horizontal_border_top(self): """ The complete outer top horizontal border section, including left and right margins. Returns: str: The top menu border. """ return u"{lm}{lv}{hz}{rv}".format(lm=' ' * self.margins.left, ...
python
def outer_horizontal_border_top(self): """ The complete outer top horizontal border section, including left and right margins. Returns: str: The top menu border. """ return u"{lm}{lv}{hz}{rv}".format(lm=' ' * self.margins.left, ...
[ "def", "outer_horizontal_border_top", "(", "self", ")", ":", "return", "u\"{lm}{lv}{hz}{rv}\"", ".", "format", "(", "lm", "=", "' '", "*", "self", ".", "margins", ".", "left", ",", "lv", "=", "self", ".", "border_style", ".", "top_left_corner", ",", "rv", ...
The complete outer top horizontal border section, including left and right margins. Returns: str: The top menu border.
[ "The", "complete", "outer", "top", "horizontal", "border", "section", "including", "left", "and", "right", "margins", "." ]
1a28959d6f1dd6ac79c87b11efd8529d05532422
https://github.com/aegirhall/console-menu/blob/1a28959d6f1dd6ac79c87b11efd8529d05532422/consolemenu/menu_component.py#L157-L167
train
aegirhall/console-menu
consolemenu/menu_component.py
MenuComponent.row
def row(self, content='', align='left'): """ A row of the menu, which comprises the left and right verticals plus the given content. Returns: str: A row of this menu component with the specified content. """ return u"{lm}{vert}{cont}{vert}".format(lm=' ' * self.margi...
python
def row(self, content='', align='left'): """ A row of the menu, which comprises the left and right verticals plus the given content. Returns: str: A row of this menu component with the specified content. """ return u"{lm}{vert}{cont}{vert}".format(lm=' ' * self.margi...
[ "def", "row", "(", "self", ",", "content", "=", "''", ",", "align", "=", "'left'", ")", ":", "return", "u\"{lm}{vert}{cont}{vert}\"", ".", "format", "(", "lm", "=", "' '", "*", "self", ".", "margins", ".", "left", ",", "vert", "=", "self", ".", "bord...
A row of the menu, which comprises the left and right verticals plus the given content. Returns: str: A row of this menu component with the specified content.
[ "A", "row", "of", "the", "menu", "which", "comprises", "the", "left", "and", "right", "verticals", "plus", "the", "given", "content", "." ]
1a28959d6f1dd6ac79c87b11efd8529d05532422
https://github.com/aegirhall/console-menu/blob/1a28959d6f1dd6ac79c87b11efd8529d05532422/consolemenu/menu_component.py#L169-L178
train
aegirhall/console-menu
consolemenu/format/menu_borders.py
MenuBorderStyleFactory.create_border
def create_border(self, border_style_type): """ Create a new MenuBorderStyle instance based on the given border style type. Args: border_style_type (int): an integer value from :obj:`MenuBorderStyleType`. Returns: :obj:`MenuBorderStyle`: a new MenuBorderStyle i...
python
def create_border(self, border_style_type): """ Create a new MenuBorderStyle instance based on the given border style type. Args: border_style_type (int): an integer value from :obj:`MenuBorderStyleType`. Returns: :obj:`MenuBorderStyle`: a new MenuBorderStyle i...
[ "def", "create_border", "(", "self", ",", "border_style_type", ")", ":", "if", "border_style_type", "==", "MenuBorderStyleType", ".", "ASCII_BORDER", ":", "return", "self", ".", "create_ascii_border", "(", ")", "elif", "border_style_type", "==", "MenuBorderStyleType",...
Create a new MenuBorderStyle instance based on the given border style type. Args: border_style_type (int): an integer value from :obj:`MenuBorderStyleType`. Returns: :obj:`MenuBorderStyle`: a new MenuBorderStyle instance of the specified style.
[ "Create", "a", "new", "MenuBorderStyle", "instance", "based", "on", "the", "given", "border", "style", "type", "." ]
1a28959d6f1dd6ac79c87b11efd8529d05532422
https://github.com/aegirhall/console-menu/blob/1a28959d6f1dd6ac79c87b11efd8529d05532422/consolemenu/format/menu_borders.py#L352-L378
train
aegirhall/console-menu
consolemenu/format/menu_borders.py
MenuBorderStyleFactory.is_win_python35_or_earlier
def is_win_python35_or_earlier(): """ Convenience method to determine if the current platform is Windows and Python version 3.5 or earlier. Returns: bool: True if the current platform is Windows and the Python interpreter is 3.5 or earlier; False otherwise. """ retu...
python
def is_win_python35_or_earlier(): """ Convenience method to determine if the current platform is Windows and Python version 3.5 or earlier. Returns: bool: True if the current platform is Windows and the Python interpreter is 3.5 or earlier; False otherwise. """ retu...
[ "def", "is_win_python35_or_earlier", "(", ")", ":", "return", "sys", ".", "platform", ".", "startswith", "(", "\"win\"", ")", "and", "sys", ".", "version_info", ".", "major", "<", "3", "or", "(", "sys", ".", "version_info", ".", "major", "==", "3", "and"...
Convenience method to determine if the current platform is Windows and Python version 3.5 or earlier. Returns: bool: True if the current platform is Windows and the Python interpreter is 3.5 or earlier; False otherwise.
[ "Convenience", "method", "to", "determine", "if", "the", "current", "platform", "is", "Windows", "and", "Python", "version", "3", ".", "5", "or", "earlier", "." ]
1a28959d6f1dd6ac79c87b11efd8529d05532422
https://github.com/aegirhall/console-menu/blob/1a28959d6f1dd6ac79c87b11efd8529d05532422/consolemenu/format/menu_borders.py#L454-L463
train
aegirhall/console-menu
consolemenu/items/submenu_item.py
SubmenuItem.set_menu
def set_menu(self, menu): """ Sets the menu of this item. Should be used instead of directly accessing the menu attribute for this class. :param ConsoleMenu menu: the menu """ self.menu = menu self.submenu.parent = menu
python
def set_menu(self, menu): """ Sets the menu of this item. Should be used instead of directly accessing the menu attribute for this class. :param ConsoleMenu menu: the menu """ self.menu = menu self.submenu.parent = menu
[ "def", "set_menu", "(", "self", ",", "menu", ")", ":", "self", ".", "menu", "=", "menu", "self", ".", "submenu", ".", "parent", "=", "menu" ]
Sets the menu of this item. Should be used instead of directly accessing the menu attribute for this class. :param ConsoleMenu menu: the menu
[ "Sets", "the", "menu", "of", "this", "item", ".", "Should", "be", "used", "instead", "of", "directly", "accessing", "the", "menu", "attribute", "for", "this", "class", "." ]
1a28959d6f1dd6ac79c87b11efd8529d05532422
https://github.com/aegirhall/console-menu/blob/1a28959d6f1dd6ac79c87b11efd8529d05532422/consolemenu/items/submenu_item.py#L19-L27
train
aegirhall/console-menu
consolemenu/validators/regex.py
RegexValidator.validate
def validate(self, input_string): """ Validate input_string against a regex pattern :return: True if match / False otherwise """ validation_result = False try: validation_result = bool(match(pattern=self.pattern, string=input_string)) except TypeError...
python
def validate(self, input_string): """ Validate input_string against a regex pattern :return: True if match / False otherwise """ validation_result = False try: validation_result = bool(match(pattern=self.pattern, string=input_string)) except TypeError...
[ "def", "validate", "(", "self", ",", "input_string", ")", ":", "validation_result", "=", "False", "try", ":", "validation_result", "=", "bool", "(", "match", "(", "pattern", "=", "self", ".", "pattern", ",", "string", "=", "input_string", ")", ")", "except...
Validate input_string against a regex pattern :return: True if match / False otherwise
[ "Validate", "input_string", "against", "a", "regex", "pattern" ]
1a28959d6f1dd6ac79c87b11efd8529d05532422
https://github.com/aegirhall/console-menu/blob/1a28959d6f1dd6ac79c87b11efd8529d05532422/consolemenu/validators/regex.py#L16-L30
train
aegirhall/console-menu
consolemenu/multiselect_menu.py
MultiSelectMenu.process_user_input
def process_user_input(self): """ This overrides the method in ConsoleMenu to allow for comma-delimited and range inputs. Examples: All of the following inputs would have the same result: * 1,2,3,4 * 1-4 * 1-2,3-4 * 1 -...
python
def process_user_input(self): """ This overrides the method in ConsoleMenu to allow for comma-delimited and range inputs. Examples: All of the following inputs would have the same result: * 1,2,3,4 * 1-4 * 1-2,3-4 * 1 -...
[ "def", "process_user_input", "(", "self", ")", ":", "user_input", "=", "self", ".", "screen", ".", "input", "(", ")", "try", ":", "indexes", "=", "self", ".", "__parse_range_list", "(", "user_input", ")", "indexes", "[", ":", "]", "=", "[", "x", "-", ...
This overrides the method in ConsoleMenu to allow for comma-delimited and range inputs. Examples: All of the following inputs would have the same result: * 1,2,3,4 * 1-4 * 1-2,3-4 * 1 - 4 * 1, 2, 3, 4 Raises: ...
[ "This", "overrides", "the", "method", "in", "ConsoleMenu", "to", "allow", "for", "comma", "-", "delimited", "and", "range", "inputs", "." ]
1a28959d6f1dd6ac79c87b11efd8529d05532422
https://github.com/aegirhall/console-menu/blob/1a28959d6f1dd6ac79c87b11efd8529d05532422/consolemenu/multiselect_menu.py#L43-L67
train
aegirhall/console-menu
consolemenu/console_menu.py
ConsoleMenu.remove_item
def remove_item(self, item): """ Remove the specified item from the menu. Args: item (MenuItem): the item to be removed. Returns: bool: True if the item was removed; False otherwise. """ for idx, _item in enumerate(self.items): if ite...
python
def remove_item(self, item): """ Remove the specified item from the menu. Args: item (MenuItem): the item to be removed. Returns: bool: True if the item was removed; False otherwise. """ for idx, _item in enumerate(self.items): if ite...
[ "def", "remove_item", "(", "self", ",", "item", ")", ":", "for", "idx", ",", "_item", "in", "enumerate", "(", "self", ".", "items", ")", ":", "if", "item", "==", "_item", ":", "del", "self", ".", "items", "[", "idx", "]", "return", "True", "return"...
Remove the specified item from the menu. Args: item (MenuItem): the item to be removed. Returns: bool: True if the item was removed; False otherwise.
[ "Remove", "the", "specified", "item", "from", "the", "menu", "." ]
1a28959d6f1dd6ac79c87b11efd8529d05532422
https://github.com/aegirhall/console-menu/blob/1a28959d6f1dd6ac79c87b11efd8529d05532422/consolemenu/console_menu.py#L116-L130
train
aegirhall/console-menu
consolemenu/console_menu.py
ConsoleMenu.remove_exit
def remove_exit(self): """ Remove the exit item if necessary. Used to make sure we only remove the exit item, not something else. Returns: bool: True if item needed to be removed, False otherwise. """ if self.items: if self.items[-1] is self.exit_item: ...
python
def remove_exit(self): """ Remove the exit item if necessary. Used to make sure we only remove the exit item, not something else. Returns: bool: True if item needed to be removed, False otherwise. """ if self.items: if self.items[-1] is self.exit_item: ...
[ "def", "remove_exit", "(", "self", ")", ":", "if", "self", ".", "items", ":", "if", "self", ".", "items", "[", "-", "1", "]", "is", "self", ".", "exit_item", ":", "del", "self", ".", "items", "[", "-", "1", "]", "return", "True", "return", "False...
Remove the exit item if necessary. Used to make sure we only remove the exit item, not something else. Returns: bool: True if item needed to be removed, False otherwise.
[ "Remove", "the", "exit", "item", "if", "necessary", ".", "Used", "to", "make", "sure", "we", "only", "remove", "the", "exit", "item", "not", "something", "else", "." ]
1a28959d6f1dd6ac79c87b11efd8529d05532422
https://github.com/aegirhall/console-menu/blob/1a28959d6f1dd6ac79c87b11efd8529d05532422/consolemenu/console_menu.py#L144-L155
train
aegirhall/console-menu
consolemenu/console_menu.py
ConsoleMenu.draw
def draw(self): """ Refresh the screen and redraw the menu. Should be called whenever something changes that needs to be redrawn. """ self.screen.printf(self.formatter.format(title=self.title, subtitle=self.subtitle, items=self.items, prol...
python
def draw(self): """ Refresh the screen and redraw the menu. Should be called whenever something changes that needs to be redrawn. """ self.screen.printf(self.formatter.format(title=self.title, subtitle=self.subtitle, items=self.items, prol...
[ "def", "draw", "(", "self", ")", ":", "self", ".", "screen", ".", "printf", "(", "self", ".", "formatter", ".", "format", "(", "title", "=", "self", ".", "title", ",", "subtitle", "=", "self", ".", "subtitle", ",", "items", "=", "self", ".", "items...
Refresh the screen and redraw the menu. Should be called whenever something changes that needs to be redrawn.
[ "Refresh", "the", "screen", "and", "redraw", "the", "menu", ".", "Should", "be", "called", "whenever", "something", "changes", "that", "needs", "to", "be", "redrawn", "." ]
1a28959d6f1dd6ac79c87b11efd8529d05532422
https://github.com/aegirhall/console-menu/blob/1a28959d6f1dd6ac79c87b11efd8529d05532422/consolemenu/console_menu.py#L226-L231
train
aegirhall/console-menu
consolemenu/console_menu.py
ConsoleMenu.process_user_input
def process_user_input(self): """ Gets the next single character and decides what to do with it """ user_input = self.get_input() try: num = int(user_input) except Exception: return if 0 < num < len(self.items) + 1: self.curren...
python
def process_user_input(self): """ Gets the next single character and decides what to do with it """ user_input = self.get_input() try: num = int(user_input) except Exception: return if 0 < num < len(self.items) + 1: self.curren...
[ "def", "process_user_input", "(", "self", ")", ":", "user_input", "=", "self", ".", "get_input", "(", ")", "try", ":", "num", "=", "int", "(", "user_input", ")", "except", "Exception", ":", "return", "if", "0", "<", "num", "<", "len", "(", "self", "....
Gets the next single character and decides what to do with it
[ "Gets", "the", "next", "single", "character", "and", "decides", "what", "to", "do", "with", "it" ]
1a28959d6f1dd6ac79c87b11efd8529d05532422
https://github.com/aegirhall/console-menu/blob/1a28959d6f1dd6ac79c87b11efd8529d05532422/consolemenu/console_menu.py#L297-L311
train
aegirhall/console-menu
consolemenu/console_menu.py
ConsoleMenu.go_down
def go_down(self): """ Go down one, wrap to beginning if necessary """ if self.current_option < len(self.items) - 1: self.current_option += 1 else: self.current_option = 0 self.draw()
python
def go_down(self): """ Go down one, wrap to beginning if necessary """ if self.current_option < len(self.items) - 1: self.current_option += 1 else: self.current_option = 0 self.draw()
[ "def", "go_down", "(", "self", ")", ":", "if", "self", ".", "current_option", "<", "len", "(", "self", ".", "items", ")", "-", "1", ":", "self", ".", "current_option", "+=", "1", "else", ":", "self", ".", "current_option", "=", "0", "self", ".", "d...
Go down one, wrap to beginning if necessary
[ "Go", "down", "one", "wrap", "to", "beginning", "if", "necessary" ]
1a28959d6f1dd6ac79c87b11efd8529d05532422
https://github.com/aegirhall/console-menu/blob/1a28959d6f1dd6ac79c87b11efd8529d05532422/consolemenu/console_menu.py#L323-L331
train
aegirhall/console-menu
consolemenu/console_menu.py
ConsoleMenu.go_up
def go_up(self): """ Go up one, wrap to end if necessary """ if self.current_option > 0: self.current_option += -1 else: self.current_option = len(self.items) - 1 self.draw()
python
def go_up(self): """ Go up one, wrap to end if necessary """ if self.current_option > 0: self.current_option += -1 else: self.current_option = len(self.items) - 1 self.draw()
[ "def", "go_up", "(", "self", ")", ":", "if", "self", ".", "current_option", ">", "0", ":", "self", ".", "current_option", "+=", "-", "1", "else", ":", "self", ".", "current_option", "=", "len", "(", "self", ".", "items", ")", "-", "1", "self", ".",...
Go up one, wrap to end if necessary
[ "Go", "up", "one", "wrap", "to", "end", "if", "necessary" ]
1a28959d6f1dd6ac79c87b11efd8529d05532422
https://github.com/aegirhall/console-menu/blob/1a28959d6f1dd6ac79c87b11efd8529d05532422/consolemenu/console_menu.py#L333-L341
train
aegirhall/console-menu
consolemenu/selection_menu.py
SelectionMenu.get_selection
def get_selection(cls, strings, title="Select an option", subtitle=None, exit_option=True, _menu=None): """ Single-method way of getting a selection out of a list of strings. Args: strings (:obj:`list` of :obj:`str`): The list of strings this menu should be built from. ...
python
def get_selection(cls, strings, title="Select an option", subtitle=None, exit_option=True, _menu=None): """ Single-method way of getting a selection out of a list of strings. Args: strings (:obj:`list` of :obj:`str`): The list of strings this menu should be built from. ...
[ "def", "get_selection", "(", "cls", ",", "strings", ",", "title", "=", "\"Select an option\"", ",", "subtitle", "=", "None", ",", "exit_option", "=", "True", ",", "_menu", "=", "None", ")", ":", "menu", "=", "cls", "(", "strings", ",", "title", ",", "s...
Single-method way of getting a selection out of a list of strings. Args: strings (:obj:`list` of :obj:`str`): The list of strings this menu should be built from. title (str): The title of the menu. subtitle (str): The subtitle of the menu. exit_option (bool): Sp...
[ "Single", "-", "method", "way", "of", "getting", "a", "selection", "out", "of", "a", "list", "of", "strings", "." ]
1a28959d6f1dd6ac79c87b11efd8529d05532422
https://github.com/aegirhall/console-menu/blob/1a28959d6f1dd6ac79c87b11efd8529d05532422/consolemenu/selection_menu.py#L29-L50
train
timothyb0912/pylogit
pylogit/choice_tools.py
ensure_object_is_ordered_dict
def ensure_object_is_ordered_dict(item, title): """ Checks that the item is an OrderedDict. If not, raises ValueError. """ assert isinstance(title, str) if not isinstance(item, OrderedDict): msg = "{} must be an OrderedDict. {} passed instead." raise TypeError(msg.format(title, type...
python
def ensure_object_is_ordered_dict(item, title): """ Checks that the item is an OrderedDict. If not, raises ValueError. """ assert isinstance(title, str) if not isinstance(item, OrderedDict): msg = "{} must be an OrderedDict. {} passed instead." raise TypeError(msg.format(title, type...
[ "def", "ensure_object_is_ordered_dict", "(", "item", ",", "title", ")", ":", "assert", "isinstance", "(", "title", ",", "str", ")", "if", "not", "isinstance", "(", "item", ",", "OrderedDict", ")", ":", "msg", "=", "\"{} must be an OrderedDict. {} passed instead.\"...
Checks that the item is an OrderedDict. If not, raises ValueError.
[ "Checks", "that", "the", "item", "is", "an", "OrderedDict", ".", "If", "not", "raises", "ValueError", "." ]
f83b0fd6debaa7358d87c3828428f6d4ead71357
https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/choice_tools.py#L73-L83
train
timothyb0912/pylogit
pylogit/choice_tools.py
ensure_object_is_string
def ensure_object_is_string(item, title): """ Checks that the item is a string. If not, raises ValueError. """ assert isinstance(title, str) if not isinstance(item, str): msg = "{} must be a string. {} passed instead." raise TypeError(msg.format(title, type(item))) return None
python
def ensure_object_is_string(item, title): """ Checks that the item is a string. If not, raises ValueError. """ assert isinstance(title, str) if not isinstance(item, str): msg = "{} must be a string. {} passed instead." raise TypeError(msg.format(title, type(item))) return None
[ "def", "ensure_object_is_string", "(", "item", ",", "title", ")", ":", "assert", "isinstance", "(", "title", ",", "str", ")", "if", "not", "isinstance", "(", "item", ",", "str", ")", ":", "msg", "=", "\"{} must be a string. {} passed instead.\"", "raise", "Typ...
Checks that the item is a string. If not, raises ValueError.
[ "Checks", "that", "the", "item", "is", "a", "string", ".", "If", "not", "raises", "ValueError", "." ]
f83b0fd6debaa7358d87c3828428f6d4ead71357
https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/choice_tools.py#L86-L96
train
timothyb0912/pylogit
pylogit/choice_tools.py
ensure_object_is_ndarray
def ensure_object_is_ndarray(item, title): """ Ensures that a given mapping matrix is a dense numpy array. Raises a helpful TypeError if otherwise. """ assert isinstance(title, str) if not isinstance(item, np.ndarray): msg = "{} must be a np.ndarray. {} passed instead." raise Ty...
python
def ensure_object_is_ndarray(item, title): """ Ensures that a given mapping matrix is a dense numpy array. Raises a helpful TypeError if otherwise. """ assert isinstance(title, str) if not isinstance(item, np.ndarray): msg = "{} must be a np.ndarray. {} passed instead." raise Ty...
[ "def", "ensure_object_is_ndarray", "(", "item", ",", "title", ")", ":", "assert", "isinstance", "(", "title", ",", "str", ")", "if", "not", "isinstance", "(", "item", ",", "np", ".", "ndarray", ")", ":", "msg", "=", "\"{} must be a np.ndarray. {} passed instea...
Ensures that a given mapping matrix is a dense numpy array. Raises a helpful TypeError if otherwise.
[ "Ensures", "that", "a", "given", "mapping", "matrix", "is", "a", "dense", "numpy", "array", ".", "Raises", "a", "helpful", "TypeError", "if", "otherwise", "." ]
f83b0fd6debaa7358d87c3828428f6d4ead71357
https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/choice_tools.py#L99-L110
train
timothyb0912/pylogit
pylogit/choice_tools.py
ensure_columns_are_in_dataframe
def ensure_columns_are_in_dataframe(columns, dataframe, col_title='', data_title='data'): """ Checks whether each column in `columns` is in `dataframe`. Raises ValueError if any of the columns are not...
python
def ensure_columns_are_in_dataframe(columns, dataframe, col_title='', data_title='data'): """ Checks whether each column in `columns` is in `dataframe`. Raises ValueError if any of the columns are not...
[ "def", "ensure_columns_are_in_dataframe", "(", "columns", ",", "dataframe", ",", "col_title", "=", "''", ",", "data_title", "=", "'data'", ")", ":", "assert", "isinstance", "(", "columns", ",", "Iterable", ")", "assert", "isinstance", "(", "dataframe", ",", "p...
Checks whether each column in `columns` is in `dataframe`. Raises ValueError if any of the columns are not in the dataframe. Parameters ---------- columns : list of strings. Each string should represent a column heading in dataframe. dataframe : pandas DataFrame. Dataframe containin...
[ "Checks", "whether", "each", "column", "in", "columns", "is", "in", "dataframe", ".", "Raises", "ValueError", "if", "any", "of", "the", "columns", "are", "not", "in", "the", "dataframe", "." ]
f83b0fd6debaa7358d87c3828428f6d4ead71357
https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/choice_tools.py#L113-L156
train
timothyb0912/pylogit
pylogit/choice_tools.py
check_argument_type
def check_argument_type(long_form, specification_dict): """ Ensures that long_form is a pandas dataframe and that specification_dict is an OrderedDict, raising a ValueError otherwise. Parameters ---------- long_form : pandas dataframe. Contains one row for each available alternative, fo...
python
def check_argument_type(long_form, specification_dict): """ Ensures that long_form is a pandas dataframe and that specification_dict is an OrderedDict, raising a ValueError otherwise. Parameters ---------- long_form : pandas dataframe. Contains one row for each available alternative, fo...
[ "def", "check_argument_type", "(", "long_form", ",", "specification_dict", ")", ":", "if", "not", "isinstance", "(", "long_form", ",", "pd", ".", "DataFrame", ")", ":", "msg", "=", "\"long_form should be a pandas dataframe. It is a {}\"", "raise", "TypeError", "(", ...
Ensures that long_form is a pandas dataframe and that specification_dict is an OrderedDict, raising a ValueError otherwise. Parameters ---------- long_form : pandas dataframe. Contains one row for each available alternative, for each observation. specification_dict : OrderedDict. Ke...
[ "Ensures", "that", "long_form", "is", "a", "pandas", "dataframe", "and", "that", "specification_dict", "is", "an", "OrderedDict", "raising", "a", "ValueError", "otherwise", "." ]
f83b0fd6debaa7358d87c3828428f6d4ead71357
https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/choice_tools.py#L159-L194
train
timothyb0912/pylogit
pylogit/choice_tools.py
ensure_alt_id_in_long_form
def ensure_alt_id_in_long_form(alt_id_col, long_form): """ Ensures alt_id_col is in long_form, and raises a ValueError if not. Parameters ---------- alt_id_col : str. Column name which denotes the column in `long_form` that contains the alternative ID for each row in `long_form`. ...
python
def ensure_alt_id_in_long_form(alt_id_col, long_form): """ Ensures alt_id_col is in long_form, and raises a ValueError if not. Parameters ---------- alt_id_col : str. Column name which denotes the column in `long_form` that contains the alternative ID for each row in `long_form`. ...
[ "def", "ensure_alt_id_in_long_form", "(", "alt_id_col", ",", "long_form", ")", ":", "if", "alt_id_col", "not", "in", "long_form", ".", "columns", ":", "msg", "=", "\"alt_id_col == {} is not a column in long_form.\"", "raise", "ValueError", "(", "msg", ".", "format", ...
Ensures alt_id_col is in long_form, and raises a ValueError if not. Parameters ---------- alt_id_col : str. Column name which denotes the column in `long_form` that contains the alternative ID for each row in `long_form`. long_form : pandas dataframe. Contains one row for each a...
[ "Ensures", "alt_id_col", "is", "in", "long_form", "and", "raises", "a", "ValueError", "if", "not", "." ]
f83b0fd6debaa7358d87c3828428f6d4ead71357
https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/choice_tools.py#L197-L217
train
timothyb0912/pylogit
pylogit/choice_tools.py
ensure_specification_cols_are_in_dataframe
def ensure_specification_cols_are_in_dataframe(specification, dataframe): """ Checks whether each column in `specification` is in `dataframe`. Raises ValueError if any of the columns are not in the dataframe. Parameters ---------- specification : OrderedDict. Keys are a proper subset of...
python
def ensure_specification_cols_are_in_dataframe(specification, dataframe): """ Checks whether each column in `specification` is in `dataframe`. Raises ValueError if any of the columns are not in the dataframe. Parameters ---------- specification : OrderedDict. Keys are a proper subset of...
[ "def", "ensure_specification_cols_are_in_dataframe", "(", "specification", ",", "dataframe", ")", ":", "try", ":", "assert", "isinstance", "(", "specification", ",", "OrderedDict", ")", "except", "AssertionError", ":", "raise", "TypeError", "(", "\"`specification` must ...
Checks whether each column in `specification` is in `dataframe`. Raises ValueError if any of the columns are not in the dataframe. Parameters ---------- specification : OrderedDict. Keys are a proper subset of the columns in `data`. Values are either a list or a single string, "all_diff...
[ "Checks", "whether", "each", "column", "in", "specification", "is", "in", "dataframe", ".", "Raises", "ValueError", "if", "any", "of", "the", "columns", "are", "not", "in", "the", "dataframe", "." ]
f83b0fd6debaa7358d87c3828428f6d4ead71357
https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/choice_tools.py#L220-L264
train
timothyb0912/pylogit
pylogit/choice_tools.py
check_keys_and_values_of_name_dictionary
def check_keys_and_values_of_name_dictionary(names, specification_dict, num_alts): """ Check the validity of the keys and values in the names dictionary. Parameters ---------- names : OrderedDict, optional. ...
python
def check_keys_and_values_of_name_dictionary(names, specification_dict, num_alts): """ Check the validity of the keys and values in the names dictionary. Parameters ---------- names : OrderedDict, optional. ...
[ "def", "check_keys_and_values_of_name_dictionary", "(", "names", ",", "specification_dict", ",", "num_alts", ")", ":", "if", "names", ".", "keys", "(", ")", "!=", "specification_dict", ".", "keys", "(", ")", ":", "msg", "=", "\"names.keys() does not equal specificat...
Check the validity of the keys and values in the names dictionary. Parameters ---------- names : OrderedDict, optional. Should have the same keys as `specification_dict`. For each key: - if the corresponding value in `specification_dict` is "all_same", then there should b...
[ "Check", "the", "validity", "of", "the", "keys", "and", "values", "in", "the", "names", "dictionary", "." ]
f83b0fd6debaa7358d87c3828428f6d4ead71357
https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/choice_tools.py#L340-L417
train
timothyb0912/pylogit
pylogit/choice_tools.py
ensure_all_columns_are_used
def ensure_all_columns_are_used(num_vars_accounted_for, dataframe, data_title='long_data'): """ Ensure that all of the columns from dataframe are in the list of used_cols. Will raise a helpful UserWarning if otherwise. Parameters -----...
python
def ensure_all_columns_are_used(num_vars_accounted_for, dataframe, data_title='long_data'): """ Ensure that all of the columns from dataframe are in the list of used_cols. Will raise a helpful UserWarning if otherwise. Parameters -----...
[ "def", "ensure_all_columns_are_used", "(", "num_vars_accounted_for", ",", "dataframe", ",", "data_title", "=", "'long_data'", ")", ":", "dataframe_vars", "=", "set", "(", "dataframe", ".", "columns", ".", "tolist", "(", ")", ")", "num_dataframe_vars", "=", "len", ...
Ensure that all of the columns from dataframe are in the list of used_cols. Will raise a helpful UserWarning if otherwise. Parameters ---------- num_vars_accounted_for : int. Denotes the number of variables used in one's function. dataframe : pandas dataframe. Contains all of the da...
[ "Ensure", "that", "all", "of", "the", "columns", "from", "dataframe", "are", "in", "the", "list", "of", "used_cols", ".", "Will", "raise", "a", "helpful", "UserWarning", "if", "otherwise", "." ]
f83b0fd6debaa7358d87c3828428f6d4ead71357
https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/choice_tools.py#L420-L463
train
timothyb0912/pylogit
pylogit/choice_tools.py
check_dataframe_for_duplicate_records
def check_dataframe_for_duplicate_records(obs_id_col, alt_id_col, df): """ Checks a cross-sectional dataframe of long-format data for duplicate observations. Duplicate observations are defined as rows with the same observation id value and the same alternative id value. Parameters ---------- ...
python
def check_dataframe_for_duplicate_records(obs_id_col, alt_id_col, df): """ Checks a cross-sectional dataframe of long-format data for duplicate observations. Duplicate observations are defined as rows with the same observation id value and the same alternative id value. Parameters ---------- ...
[ "def", "check_dataframe_for_duplicate_records", "(", "obs_id_col", ",", "alt_id_col", ",", "df", ")", ":", "if", "df", ".", "duplicated", "(", "subset", "=", "[", "obs_id_col", ",", "alt_id_col", "]", ")", ".", "any", "(", ")", ":", "msg", "=", "\"One or m...
Checks a cross-sectional dataframe of long-format data for duplicate observations. Duplicate observations are defined as rows with the same observation id value and the same alternative id value. Parameters ---------- obs_id_col : str. Denotes the column in `df` that contains the observatio...
[ "Checks", "a", "cross", "-", "sectional", "dataframe", "of", "long", "-", "format", "data", "for", "duplicate", "observations", ".", "Duplicate", "observations", "are", "defined", "as", "rows", "with", "the", "same", "observation", "id", "value", "and", "the",...
f83b0fd6debaa7358d87c3828428f6d4ead71357
https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/choice_tools.py#L466-L491
train
timothyb0912/pylogit
pylogit/choice_tools.py
ensure_num_chosen_alts_equals_num_obs
def ensure_num_chosen_alts_equals_num_obs(obs_id_col, choice_col, df): """ Checks that the total number of recorded choices equals the total number of observations. If this is not the case, raise helpful ValueError messages. Parameters ---------- obs_id_col : str. Denotes the column in ...
python
def ensure_num_chosen_alts_equals_num_obs(obs_id_col, choice_col, df): """ Checks that the total number of recorded choices equals the total number of observations. If this is not the case, raise helpful ValueError messages. Parameters ---------- obs_id_col : str. Denotes the column in ...
[ "def", "ensure_num_chosen_alts_equals_num_obs", "(", "obs_id_col", ",", "choice_col", ",", "df", ")", ":", "num_obs", "=", "df", "[", "obs_id_col", "]", ".", "unique", "(", ")", ".", "shape", "[", "0", "]", "num_choices", "=", "df", "[", "choice_col", "]",...
Checks that the total number of recorded choices equals the total number of observations. If this is not the case, raise helpful ValueError messages. Parameters ---------- obs_id_col : str. Denotes the column in `df` that contains the observation ID values for each row. choice_col :...
[ "Checks", "that", "the", "total", "number", "of", "recorded", "choices", "equals", "the", "total", "number", "of", "observations", ".", "If", "this", "is", "not", "the", "case", "raise", "helpful", "ValueError", "messages", "." ]
f83b0fd6debaa7358d87c3828428f6d4ead71357
https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/choice_tools.py#L494-L526
train
timothyb0912/pylogit
pylogit/choice_tools.py
check_type_and_values_of_alt_name_dict
def check_type_and_values_of_alt_name_dict(alt_name_dict, alt_id_col, df): """ Ensures that `alt_name_dict` is a dictionary and that its keys are in the alternative id column of `df`. Raises helpful errors if either condition is not met. Parameters ---------- alt_name_dict : dict. A...
python
def check_type_and_values_of_alt_name_dict(alt_name_dict, alt_id_col, df): """ Ensures that `alt_name_dict` is a dictionary and that its keys are in the alternative id column of `df`. Raises helpful errors if either condition is not met. Parameters ---------- alt_name_dict : dict. A...
[ "def", "check_type_and_values_of_alt_name_dict", "(", "alt_name_dict", ",", "alt_id_col", ",", "df", ")", ":", "if", "not", "isinstance", "(", "alt_name_dict", ",", "dict", ")", ":", "msg", "=", "\"alt_name_dict should be a dictionary. Passed value was a {}\"", "raise", ...
Ensures that `alt_name_dict` is a dictionary and that its keys are in the alternative id column of `df`. Raises helpful errors if either condition is not met. Parameters ---------- alt_name_dict : dict. A dictionary whose keys are the possible values in `df[alt_id_col].unique()`. Th...
[ "Ensures", "that", "alt_name_dict", "is", "a", "dictionary", "and", "that", "its", "keys", "are", "in", "the", "alternative", "id", "column", "of", "df", ".", "Raises", "helpful", "errors", "if", "either", "condition", "is", "not", "met", "." ]
f83b0fd6debaa7358d87c3828428f6d4ead71357
https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/choice_tools.py#L529-L560
train
timothyb0912/pylogit
pylogit/choice_tools.py
ensure_ridge_is_scalar_or_none
def ensure_ridge_is_scalar_or_none(ridge): """ Ensures that `ridge` is either None or a scalar value. Raises a helpful TypeError otherwise. Parameters ---------- ridge : int, float, long, or None. Scalar value or None, determining the L2-ridge regression penalty. Returns ------...
python
def ensure_ridge_is_scalar_or_none(ridge): """ Ensures that `ridge` is either None or a scalar value. Raises a helpful TypeError otherwise. Parameters ---------- ridge : int, float, long, or None. Scalar value or None, determining the L2-ridge regression penalty. Returns ------...
[ "def", "ensure_ridge_is_scalar_or_none", "(", "ridge", ")", ":", "if", "(", "ridge", "is", "not", "None", ")", "and", "not", "isinstance", "(", "ridge", ",", "Number", ")", ":", "msg_1", "=", "\"ridge should be None or an int, float, or long.\"", "msg_2", "=", "...
Ensures that `ridge` is either None or a scalar value. Raises a helpful TypeError otherwise. Parameters ---------- ridge : int, float, long, or None. Scalar value or None, determining the L2-ridge regression penalty. Returns ------- None.
[ "Ensures", "that", "ridge", "is", "either", "None", "or", "a", "scalar", "value", ".", "Raises", "a", "helpful", "TypeError", "otherwise", "." ]
f83b0fd6debaa7358d87c3828428f6d4ead71357
https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/choice_tools.py#L563-L582
train
timothyb0912/pylogit
pylogit/choice_tools.py
get_original_order_unique_ids
def get_original_order_unique_ids(id_array): """ Get the unique id's of id_array, in their original order of appearance. Parameters ---------- id_array : 1D ndarray. Should contain the ids that we want to extract the unique values from. Returns ------- original_order_unique_ids...
python
def get_original_order_unique_ids(id_array): """ Get the unique id's of id_array, in their original order of appearance. Parameters ---------- id_array : 1D ndarray. Should contain the ids that we want to extract the unique values from. Returns ------- original_order_unique_ids...
[ "def", "get_original_order_unique_ids", "(", "id_array", ")", ":", "assert", "isinstance", "(", "id_array", ",", "np", ".", "ndarray", ")", "assert", "len", "(", "id_array", ".", "shape", ")", "==", "1", "original_unique_id_indices", "=", "np", ".", "sort", ...
Get the unique id's of id_array, in their original order of appearance. Parameters ---------- id_array : 1D ndarray. Should contain the ids that we want to extract the unique values from. Returns ------- original_order_unique_ids : 1D ndarray. Contains the unique ids from `id_a...
[ "Get", "the", "unique", "id", "s", "of", "id_array", "in", "their", "original", "order", "of", "appearance", "." ]
f83b0fd6debaa7358d87c3828428f6d4ead71357
https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/choice_tools.py#L718-L745
train
timothyb0912/pylogit
pylogit/choice_tools.py
create_sparse_mapping
def create_sparse_mapping(id_array, unique_ids=None): """ Will create a scipy.sparse compressed-sparse-row matrix that maps each row represented by an element in id_array to the corresponding value of the unique ids in id_array. Parameters ---------- id_array : 1D ndarray of ints. E...
python
def create_sparse_mapping(id_array, unique_ids=None): """ Will create a scipy.sparse compressed-sparse-row matrix that maps each row represented by an element in id_array to the corresponding value of the unique ids in id_array. Parameters ---------- id_array : 1D ndarray of ints. E...
[ "def", "create_sparse_mapping", "(", "id_array", ",", "unique_ids", "=", "None", ")", ":", "if", "unique_ids", "is", "None", ":", "unique_ids", "=", "get_original_order_unique_ids", "(", "id_array", ")", "assert", "isinstance", "(", "unique_ids", ",", "np", ".",...
Will create a scipy.sparse compressed-sparse-row matrix that maps each row represented by an element in id_array to the corresponding value of the unique ids in id_array. Parameters ---------- id_array : 1D ndarray of ints. Each element should represent some id related to the corresponding ...
[ "Will", "create", "a", "scipy", ".", "sparse", "compressed", "-", "sparse", "-", "row", "matrix", "that", "maps", "each", "row", "represented", "by", "an", "element", "in", "id_array", "to", "the", "corresponding", "value", "of", "the", "unique", "ids", "i...
f83b0fd6debaa7358d87c3828428f6d4ead71357
https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/choice_tools.py#L776-L832
train
timothyb0912/pylogit
pylogit/choice_tools.py
check_wide_data_for_blank_choices
def check_wide_data_for_blank_choices(choice_col, wide_data): """ Checks `wide_data` for null values in the choice column, and raises a helpful ValueError if null values are found. Parameters ---------- choice_col : str. Denotes the column in `wide_data` that is used to record each ...
python
def check_wide_data_for_blank_choices(choice_col, wide_data): """ Checks `wide_data` for null values in the choice column, and raises a helpful ValueError if null values are found. Parameters ---------- choice_col : str. Denotes the column in `wide_data` that is used to record each ...
[ "def", "check_wide_data_for_blank_choices", "(", "choice_col", ",", "wide_data", ")", ":", "if", "wide_data", "[", "choice_col", "]", ".", "isnull", "(", ")", ".", "any", "(", ")", ":", "msg_1", "=", "\"One or more of the values in wide_data[choice_col] is null.\"", ...
Checks `wide_data` for null values in the choice column, and raises a helpful ValueError if null values are found. Parameters ---------- choice_col : str. Denotes the column in `wide_data` that is used to record each observation's choice. wide_data : pandas dataframe. Contai...
[ "Checks", "wide_data", "for", "null", "values", "in", "the", "choice", "column", "and", "raises", "a", "helpful", "ValueError", "if", "null", "values", "are", "found", "." ]
f83b0fd6debaa7358d87c3828428f6d4ead71357
https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/choice_tools.py#L1258-L1280
train
timothyb0912/pylogit
pylogit/choice_tools.py
ensure_unique_obs_ids_in_wide_data
def ensure_unique_obs_ids_in_wide_data(obs_id_col, wide_data): """ Ensures that there is one observation per row in wide_data. Raises a helpful ValueError if otherwise. Parameters ---------- obs_id_col : str. Denotes the column in `wide_data` that contains the observation ID val...
python
def ensure_unique_obs_ids_in_wide_data(obs_id_col, wide_data): """ Ensures that there is one observation per row in wide_data. Raises a helpful ValueError if otherwise. Parameters ---------- obs_id_col : str. Denotes the column in `wide_data` that contains the observation ID val...
[ "def", "ensure_unique_obs_ids_in_wide_data", "(", "obs_id_col", ",", "wide_data", ")", ":", "if", "len", "(", "wide_data", "[", "obs_id_col", "]", ".", "unique", "(", ")", ")", "!=", "wide_data", ".", "shape", "[", "0", "]", ":", "msg", "=", "\"The values ...
Ensures that there is one observation per row in wide_data. Raises a helpful ValueError if otherwise. Parameters ---------- obs_id_col : str. Denotes the column in `wide_data` that contains the observation ID values for each row. wide_data : pandas dataframe. Contains one ro...
[ "Ensures", "that", "there", "is", "one", "observation", "per", "row", "in", "wide_data", ".", "Raises", "a", "helpful", "ValueError", "if", "otherwise", "." ]
f83b0fd6debaa7358d87c3828428f6d4ead71357
https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/choice_tools.py#L1283-L1306
train
timothyb0912/pylogit
pylogit/choice_tools.py
ensure_chosen_alternatives_are_in_user_alt_ids
def ensure_chosen_alternatives_are_in_user_alt_ids(choice_col, wide_data, availability_vars): """ Ensures that all chosen alternatives in `wide_df` are present in the `availability_vars` dict. Raises a help...
python
def ensure_chosen_alternatives_are_in_user_alt_ids(choice_col, wide_data, availability_vars): """ Ensures that all chosen alternatives in `wide_df` are present in the `availability_vars` dict. Raises a help...
[ "def", "ensure_chosen_alternatives_are_in_user_alt_ids", "(", "choice_col", ",", "wide_data", ",", "availability_vars", ")", ":", "if", "not", "wide_data", "[", "choice_col", "]", ".", "isin", "(", "availability_vars", ".", "keys", "(", ")", ")", ".", "all", "("...
Ensures that all chosen alternatives in `wide_df` are present in the `availability_vars` dict. Raises a helpful ValueError if not. Parameters ---------- choice_col : str. Denotes the column in `wide_data` that contains a one if the alternative pertaining to the given row was the observe...
[ "Ensures", "that", "all", "chosen", "alternatives", "in", "wide_df", "are", "present", "in", "the", "availability_vars", "dict", ".", "Raises", "a", "helpful", "ValueError", "if", "not", "." ]
f83b0fd6debaa7358d87c3828428f6d4ead71357
https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/choice_tools.py#L1309-L1342
train
timothyb0912/pylogit
pylogit/choice_tools.py
ensure_each_wide_obs_chose_an_available_alternative
def ensure_each_wide_obs_chose_an_available_alternative(obs_id_col, choice_col, availability_vars, wide_data): """ Checks whether or not each ob...
python
def ensure_each_wide_obs_chose_an_available_alternative(obs_id_col, choice_col, availability_vars, wide_data): """ Checks whether or not each ob...
[ "def", "ensure_each_wide_obs_chose_an_available_alternative", "(", "obs_id_col", ",", "choice_col", ",", "availability_vars", ",", "wide_data", ")", ":", "wide_availability_values", "=", "wide_data", "[", "list", "(", "availability_vars", ".", "values", "(", ")", ")", ...
Checks whether or not each observation with a restricted choice set chose an alternative that was personally available to him or her. Will raise a helpful ValueError if this is not the case. Parameters ---------- obs_id_col : str. Denotes the column in `wide_data` that contains the observat...
[ "Checks", "whether", "or", "not", "each", "observation", "with", "a", "restricted", "choice", "set", "chose", "an", "alternative", "that", "was", "personally", "available", "to", "him", "or", "her", ".", "Will", "raise", "a", "helpful", "ValueError", "if", "...
f83b0fd6debaa7358d87c3828428f6d4ead71357
https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/choice_tools.py#L1345-L1397
train
timothyb0912/pylogit
pylogit/choice_tools.py
ensure_all_wide_alt_ids_are_chosen
def ensure_all_wide_alt_ids_are_chosen(choice_col, alt_specific_vars, availability_vars, wide_data): """ Checks to make sure all user-specified alternative id's, both in `alt_specific_vars` a...
python
def ensure_all_wide_alt_ids_are_chosen(choice_col, alt_specific_vars, availability_vars, wide_data): """ Checks to make sure all user-specified alternative id's, both in `alt_specific_vars` a...
[ "def", "ensure_all_wide_alt_ids_are_chosen", "(", "choice_col", ",", "alt_specific_vars", ",", "availability_vars", ",", "wide_data", ")", ":", "sorted_alt_ids", "=", "np", ".", "sort", "(", "wide_data", "[", "choice_col", "]", ".", "unique", "(", ")", ")", "try...
Checks to make sure all user-specified alternative id's, both in `alt_specific_vars` and `availability_vars` are observed in the choice column of `wide_data`.
[ "Checks", "to", "make", "sure", "all", "user", "-", "specified", "alternative", "id", "s", "both", "in", "alt_specific_vars", "and", "availability_vars", "are", "observed", "in", "the", "choice", "column", "of", "wide_data", "." ]
f83b0fd6debaa7358d87c3828428f6d4ead71357
https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/choice_tools.py#L1400-L1428
train
timothyb0912/pylogit
pylogit/choice_tools.py
ensure_contiguity_in_observation_rows
def ensure_contiguity_in_observation_rows(obs_id_vector): """ Ensures that all rows pertaining to a given choice situation are located next to one another. Raises a helpful ValueError otherwise. This check is needed because the hessian calculation function requires the design matrix to have contigui...
python
def ensure_contiguity_in_observation_rows(obs_id_vector): """ Ensures that all rows pertaining to a given choice situation are located next to one another. Raises a helpful ValueError otherwise. This check is needed because the hessian calculation function requires the design matrix to have contigui...
[ "def", "ensure_contiguity_in_observation_rows", "(", "obs_id_vector", ")", ":", "contiguity_check_array", "=", "(", "obs_id_vector", "[", "1", ":", "]", "-", "obs_id_vector", "[", ":", "-", "1", "]", ")", ">=", "0", "if", "not", "contiguity_check_array", ".", ...
Ensures that all rows pertaining to a given choice situation are located next to one another. Raises a helpful ValueError otherwise. This check is needed because the hessian calculation function requires the design matrix to have contiguity in rows with the same observation id. Parameters ---------...
[ "Ensures", "that", "all", "rows", "pertaining", "to", "a", "given", "choice", "situation", "are", "located", "next", "to", "one", "another", ".", "Raises", "a", "helpful", "ValueError", "otherwise", ".", "This", "check", "is", "needed", "because", "the", "he...
f83b0fd6debaa7358d87c3828428f6d4ead71357
https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/choice_tools.py#L1431-L1461
train
timothyb0912/pylogit
pylogit/bootstrap_sampler.py
relate_obs_ids_to_chosen_alts
def relate_obs_ids_to_chosen_alts(obs_id_array, alt_id_array, choice_array): """ Creates a dictionary that relates each unique alternative id to the set of observations ids that chose the given alternative. Parameters ---------- ...
python
def relate_obs_ids_to_chosen_alts(obs_id_array, alt_id_array, choice_array): """ Creates a dictionary that relates each unique alternative id to the set of observations ids that chose the given alternative. Parameters ---------- ...
[ "def", "relate_obs_ids_to_chosen_alts", "(", "obs_id_array", ",", "alt_id_array", ",", "choice_array", ")", ":", "chosen_alts_to_obs_ids", "=", "{", "}", "for", "alt_id", "in", "np", ".", "sort", "(", "np", ".", "unique", "(", "alt_id_array", ")", ")", ":", ...
Creates a dictionary that relates each unique alternative id to the set of observations ids that chose the given alternative. Parameters ---------- obs_id_array : 1D ndarray of ints. Should be a long-format array of observation ids. Each element should correspond to the unique id of the...
[ "Creates", "a", "dictionary", "that", "relates", "each", "unique", "alternative", "id", "to", "the", "set", "of", "observations", "ids", "that", "chose", "the", "given", "alternative", "." ]
f83b0fd6debaa7358d87c3828428f6d4ead71357
https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/bootstrap_sampler.py#L13-L55
train
timothyb0912/pylogit
pylogit/bootstrap_sampler.py
create_cross_sectional_bootstrap_samples
def create_cross_sectional_bootstrap_samples(obs_id_array, alt_id_array, choice_array, num_samples, seed=None): """ Determines the u...
python
def create_cross_sectional_bootstrap_samples(obs_id_array, alt_id_array, choice_array, num_samples, seed=None): """ Determines the u...
[ "def", "create_cross_sectional_bootstrap_samples", "(", "obs_id_array", ",", "alt_id_array", ",", "choice_array", ",", "num_samples", ",", "seed", "=", "None", ")", ":", "chosen_alts_to_obs_ids", "=", "relate_obs_ids_to_chosen_alts", "(", "obs_id_array", ",", "alt_id_arra...
Determines the unique observations that will be present in each bootstrap sample. This function DOES NOT create the new design matrices or a new long-format dataframe for each bootstrap sample. Note that these will be correct bootstrap samples for cross-sectional datasets. This function will not work co...
[ "Determines", "the", "unique", "observations", "that", "will", "be", "present", "in", "each", "bootstrap", "sample", ".", "This", "function", "DOES", "NOT", "create", "the", "new", "design", "matrices", "or", "a", "new", "long", "-", "format", "dataframe", "...
f83b0fd6debaa7358d87c3828428f6d4ead71357
https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/bootstrap_sampler.py#L95-L177
train
timothyb0912/pylogit
pylogit/bootstrap_sampler.py
create_bootstrap_id_array
def create_bootstrap_id_array(obs_id_per_sample): """ Creates a 2D ndarray that contains the 'bootstrap ids' for each replication of each unit of observation that is an the set of bootstrap samples. Parameters ---------- obs_id_per_sample : 2D ndarray of ints. Should have one row for ea...
python
def create_bootstrap_id_array(obs_id_per_sample): """ Creates a 2D ndarray that contains the 'bootstrap ids' for each replication of each unit of observation that is an the set of bootstrap samples. Parameters ---------- obs_id_per_sample : 2D ndarray of ints. Should have one row for ea...
[ "def", "create_bootstrap_id_array", "(", "obs_id_per_sample", ")", ":", "n_rows", ",", "n_cols", "=", "obs_id_per_sample", ".", "shape", "bootstrap_id_array", "=", "np", ".", "tile", "(", "np", ".", "arange", "(", "n_cols", ")", "+", "1", ",", "n_rows", ")",...
Creates a 2D ndarray that contains the 'bootstrap ids' for each replication of each unit of observation that is an the set of bootstrap samples. Parameters ---------- obs_id_per_sample : 2D ndarray of ints. Should have one row for each bootsrap sample. Should have one column for each ob...
[ "Creates", "a", "2D", "ndarray", "that", "contains", "the", "bootstrap", "ids", "for", "each", "replication", "of", "each", "unit", "of", "observation", "that", "is", "an", "the", "set", "of", "bootstrap", "samples", "." ]
f83b0fd6debaa7358d87c3828428f6d4ead71357
https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/bootstrap_sampler.py#L180-L204
train
timothyb0912/pylogit
pylogit/bootstrap_sampler.py
check_column_existence
def check_column_existence(col_name, df, presence=True): """ Checks whether or not `col_name` is in `df` and raises a helpful error msg if the desired condition is not met. Parameters ---------- col_name : str. Should represent a column whose presence in `df` is to be checked. df : ...
python
def check_column_existence(col_name, df, presence=True): """ Checks whether or not `col_name` is in `df` and raises a helpful error msg if the desired condition is not met. Parameters ---------- col_name : str. Should represent a column whose presence in `df` is to be checked. df : ...
[ "def", "check_column_existence", "(", "col_name", ",", "df", ",", "presence", "=", "True", ")", ":", "if", "presence", ":", "if", "col_name", "not", "in", "df", ".", "columns", ":", "msg", "=", "\"Ensure that `{}` is in `df.columns`.\"", "raise", "ValueError", ...
Checks whether or not `col_name` is in `df` and raises a helpful error msg if the desired condition is not met. Parameters ---------- col_name : str. Should represent a column whose presence in `df` is to be checked. df : pandas DataFrame. The dataframe that will be checked for the ...
[ "Checks", "whether", "or", "not", "col_name", "is", "in", "df", "and", "raises", "a", "helpful", "error", "msg", "if", "the", "desired", "condition", "is", "not", "met", "." ]
f83b0fd6debaa7358d87c3828428f6d4ead71357
https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/bootstrap_sampler.py#L245-L273
train
timothyb0912/pylogit
pylogit/bootstrap_sampler.py
ensure_resampled_obs_ids_in_df
def ensure_resampled_obs_ids_in_df(resampled_obs_ids, orig_obs_id_array): """ Checks whether all ids in `resampled_obs_ids` are in `orig_obs_id_array`. Raises a helpful ValueError if not. Parameters ---------- resampled_obs_ids : 1D ndarray of ints. Should contain the observation ids of...
python
def ensure_resampled_obs_ids_in_df(resampled_obs_ids, orig_obs_id_array): """ Checks whether all ids in `resampled_obs_ids` are in `orig_obs_id_array`. Raises a helpful ValueError if not. Parameters ---------- resampled_obs_ids : 1D ndarray of ints. Should contain the observation ids of...
[ "def", "ensure_resampled_obs_ids_in_df", "(", "resampled_obs_ids", ",", "orig_obs_id_array", ")", ":", "if", "not", "np", ".", "in1d", "(", "resampled_obs_ids", ",", "orig_obs_id_array", ")", ".", "all", "(", ")", ":", "msg", "=", "\"All values in `resampled_obs_ids...
Checks whether all ids in `resampled_obs_ids` are in `orig_obs_id_array`. Raises a helpful ValueError if not. Parameters ---------- resampled_obs_ids : 1D ndarray of ints. Should contain the observation ids of the observational units that will be used in the current bootstrap sample. ...
[ "Checks", "whether", "all", "ids", "in", "resampled_obs_ids", "are", "in", "orig_obs_id_array", ".", "Raises", "a", "helpful", "ValueError", "if", "not", "." ]
f83b0fd6debaa7358d87c3828428f6d4ead71357
https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/bootstrap_sampler.py#L276-L298
train
timothyb0912/pylogit
pylogit/bootstrap_sampler.py
create_bootstrap_dataframe
def create_bootstrap_dataframe(orig_df, obs_id_col, resampled_obs_ids_1d, groupby_dict, boot_id_col="bootstrap_id"): """ Will create the altered dataframe of data needed to estimate a choi...
python
def create_bootstrap_dataframe(orig_df, obs_id_col, resampled_obs_ids_1d, groupby_dict, boot_id_col="bootstrap_id"): """ Will create the altered dataframe of data needed to estimate a choi...
[ "def", "create_bootstrap_dataframe", "(", "orig_df", ",", "obs_id_col", ",", "resampled_obs_ids_1d", ",", "groupby_dict", ",", "boot_id_col", "=", "\"bootstrap_id\"", ")", ":", "check_column_existence", "(", "obs_id_col", ",", "orig_df", ",", "presence", "=", "True", ...
Will create the altered dataframe of data needed to estimate a choice model with the particular observations that belong to the current bootstrap sample. Parameters ---------- orig_df : pandas DataFrame. Should be long-format dataframe containing the data used to estimate the desire...
[ "Will", "create", "the", "altered", "dataframe", "of", "data", "needed", "to", "estimate", "a", "choice", "model", "with", "the", "particular", "observations", "that", "belong", "to", "the", "current", "bootstrap", "sample", "." ]
f83b0fd6debaa7358d87c3828428f6d4ead71357
https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/bootstrap_sampler.py#L301-L360
train
timothyb0912/pylogit
pylogit/bootstrap.py
get_param_names
def get_param_names(model_obj): """ Extracts all the names to be displayed for the estimated parameters. Parameters ---------- model_obj : an instance of an MNDC object. Should have the following attributes: `['ind_var_names', 'intercept_names', 'shape_names', 'nest_names']`. R...
python
def get_param_names(model_obj): """ Extracts all the names to be displayed for the estimated parameters. Parameters ---------- model_obj : an instance of an MNDC object. Should have the following attributes: `['ind_var_names', 'intercept_names', 'shape_names', 'nest_names']`. R...
[ "def", "get_param_names", "(", "model_obj", ")", ":", "all_names", "=", "deepcopy", "(", "model_obj", ".", "ind_var_names", ")", "if", "model_obj", ".", "intercept_names", "is", "not", "None", ":", "all_names", "=", "model_obj", ".", "intercept_names", "+", "a...
Extracts all the names to be displayed for the estimated parameters. Parameters ---------- model_obj : an instance of an MNDC object. Should have the following attributes: `['ind_var_names', 'intercept_names', 'shape_names', 'nest_names']`. Returns ------- all_names : list of s...
[ "Extracts", "all", "the", "names", "to", "be", "displayed", "for", "the", "estimated", "parameters", "." ]
f83b0fd6debaa7358d87c3828428f6d4ead71357
https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/bootstrap.py#L46-L75
train
timothyb0912/pylogit
pylogit/bootstrap.py
get_param_list_for_prediction
def get_param_list_for_prediction(model_obj, replicates): """ Create the `param_list` argument for use with `model_obj.predict`. Parameters ---------- model_obj : an instance of an MNDC object. Should have the following attributes: `['ind_var_names', 'intercept_names', 'shape_names'...
python
def get_param_list_for_prediction(model_obj, replicates): """ Create the `param_list` argument for use with `model_obj.predict`. Parameters ---------- model_obj : an instance of an MNDC object. Should have the following attributes: `['ind_var_names', 'intercept_names', 'shape_names'...
[ "def", "get_param_list_for_prediction", "(", "model_obj", ",", "replicates", ")", ":", "ensure_samples_is_ndim_ndarray", "(", "replicates", ",", "ndim", "=", "2", ",", "name", "=", "'replicates'", ")", "num_idx_coefs", "=", "len", "(", "model_obj", ".", "ind_var_n...
Create the `param_list` argument for use with `model_obj.predict`. Parameters ---------- model_obj : an instance of an MNDC object. Should have the following attributes: `['ind_var_names', 'intercept_names', 'shape_names', 'nest_names']`. This model should have already undergone a c...
[ "Create", "the", "param_list", "argument", "for", "use", "with", "model_obj", ".", "predict", "." ]
f83b0fd6debaa7358d87c3828428f6d4ead71357
https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/bootstrap.py#L78-L135
train
timothyb0912/pylogit
pylogit/bootstrap.py
Boot.generate_bootstrap_replicates
def generate_bootstrap_replicates(self, num_samples, mnl_obj=None, mnl_init_vals=None, mnl_fit_kwargs=None, extract_init_vals=None...
python
def generate_bootstrap_replicates(self, num_samples, mnl_obj=None, mnl_init_vals=None, mnl_fit_kwargs=None, extract_init_vals=None...
[ "def", "generate_bootstrap_replicates", "(", "self", ",", "num_samples", ",", "mnl_obj", "=", "None", ",", "mnl_init_vals", "=", "None", ",", "mnl_fit_kwargs", "=", "None", ",", "extract_init_vals", "=", "None", ",", "print_res", "=", "False", ",", "method", "...
Generates the bootstrap replicates for one's given model and dataset. Parameters ---------- num_samples : positive int. Specifies the number of bootstrap samples that are to be drawn. mnl_obj : an instance of pylogit.MNL or None, optional. Should be the MNL model...
[ "Generates", "the", "bootstrap", "replicates", "for", "one", "s", "given", "model", "and", "dataset", "." ]
f83b0fd6debaa7358d87c3828428f6d4ead71357
https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/bootstrap.py#L183-L356
train
timothyb0912/pylogit
pylogit/bootstrap.py
Boot.generate_jackknife_replicates
def generate_jackknife_replicates(self, mnl_obj=None, mnl_init_vals=None, mnl_fit_kwargs=None, extract_init_vals=None, print_res=F...
python
def generate_jackknife_replicates(self, mnl_obj=None, mnl_init_vals=None, mnl_fit_kwargs=None, extract_init_vals=None, print_res=F...
[ "def", "generate_jackknife_replicates", "(", "self", ",", "mnl_obj", "=", "None", ",", "mnl_init_vals", "=", "None", ",", "mnl_fit_kwargs", "=", "None", ",", "extract_init_vals", "=", "None", ",", "print_res", "=", "False", ",", "method", "=", "\"BFGS\"", ",",...
Generates the jackknife replicates for one's given model and dataset. Parameters ---------- mnl_obj : an instance of pylogit.MNL or None, optional. Should be the MNL model object that is used to provide starting values for the final model being estimated. If None, then o...
[ "Generates", "the", "jackknife", "replicates", "for", "one", "s", "given", "model", "and", "dataset", "." ]
f83b0fd6debaa7358d87c3828428f6d4ead71357
https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/bootstrap.py#L358-L495
train
timothyb0912/pylogit
pylogit/bootstrap.py
Boot.calc_log_likes_for_replicates
def calc_log_likes_for_replicates(self, replicates='bootstrap', num_draws=None, seed=None): """ Calculate the log-likelihood value of one's replicates, given one's dataset. ...
python
def calc_log_likes_for_replicates(self, replicates='bootstrap', num_draws=None, seed=None): """ Calculate the log-likelihood value of one's replicates, given one's dataset. ...
[ "def", "calc_log_likes_for_replicates", "(", "self", ",", "replicates", "=", "'bootstrap'", ",", "num_draws", "=", "None", ",", "seed", "=", "None", ")", ":", "ensure_replicates_kwarg_validity", "(", "replicates", ")", "replicate_vec", "=", "getattr", "(", "self",...
Calculate the log-likelihood value of one's replicates, given one's dataset. Parameters ---------- replicates : str in {'bootstrap', 'jackknife'}. Denotes which set of replicates should have their log-likelihoods calculated. num_draws : int greater than z...
[ "Calculate", "the", "log", "-", "likelihood", "value", "of", "one", "s", "replicates", "given", "one", "s", "dataset", "." ]
f83b0fd6debaa7358d87c3828428f6d4ead71357
https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/bootstrap.py#L497-L591
train
timothyb0912/pylogit
pylogit/bootstrap.py
Boot.calc_gradient_norm_for_replicates
def calc_gradient_norm_for_replicates(self, replicates='bootstrap', ridge=None, constrained_pos=None, weights=None): """ Calculate the E...
python
def calc_gradient_norm_for_replicates(self, replicates='bootstrap', ridge=None, constrained_pos=None, weights=None): """ Calculate the E...
[ "def", "calc_gradient_norm_for_replicates", "(", "self", ",", "replicates", "=", "'bootstrap'", ",", "ridge", "=", "None", ",", "constrained_pos", "=", "None", ",", "weights", "=", "None", ")", ":", "ensure_replicates_kwarg_validity", "(", "replicates", ")", "esti...
Calculate the Euclidean-norm of the gradient of one's replicates, given one's dataset. Parameters ---------- replicates : str in {'bootstrap', 'jackknife'}. Denotes which set of replicates should have their log-likelihoods calculated. ridge : float or Non...
[ "Calculate", "the", "Euclidean", "-", "norm", "of", "the", "gradient", "of", "one", "s", "replicates", "given", "one", "s", "dataset", "." ]
f83b0fd6debaa7358d87c3828428f6d4ead71357
https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/bootstrap.py#L593-L661
train