repository_name
stringlengths
7
55
func_path_in_repository
stringlengths
4
223
func_name
stringlengths
1
134
whole_func_string
stringlengths
75
104k
language
stringclasses
1 value
func_code_string
stringlengths
75
104k
func_code_tokens
listlengths
19
28.4k
func_documentation_string
stringlengths
1
46.9k
func_documentation_tokens
listlengths
1
1.97k
split_name
stringclasses
1 value
func_code_url
stringlengths
87
315
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" ]
train
https://github.com/icometrix/dicom2nifti/blob/1462ae5dd979fa3f276fe7a78ceb9b028121536f/dicom2nifti/common.py#L495-L507
icometrix/dicom2nifti
dicom2nifti/common.py
create_affine
def create_affine(sorted_dicoms): """ Function to generate the affine matrix for a dicom series This method was based on (http://nipy.org/nibabel/dicom/dicom_orientation.html) :param sorted_dicoms: list with sorted dicom files """ # Create affine matrix (http://nipy.sourceforge.net/nibabel/dic...
python
def create_affine(sorted_dicoms): """ Function to generate the affine matrix for a dicom series This method was based on (http://nipy.org/nibabel/dicom/dicom_orientation.html) :param sorted_dicoms: list with sorted dicom files """ # Create affine matrix (http://nipy.sourceforge.net/nibabel/dic...
[ "def", "create_affine", "(", "sorted_dicoms", ")", ":", "# Create affine matrix (http://nipy.sourceforge.net/nibabel/dicom/dicom_orientation.html#dicom-slice-affine)", "image_orient1", "=", "numpy", ".", "array", "(", "sorted_dicoms", "[", "0", "]", ".", "ImageOrientationPatient"...
Function to generate the affine matrix for a dicom series This method was based on (http://nipy.org/nibabel/dicom/dicom_orientation.html) :param sorted_dicoms: list with sorted dicom files
[ "Function", "to", "generate", "the", "affine", "matrix", "for", "a", "dicom", "series", "This", "method", "was", "based", "on", "(", "http", ":", "//", "nipy", ".", "org", "/", "nibabel", "/", "dicom", "/", "dicom_orientation", ".", "html", ")" ]
train
https://github.com/icometrix/dicom2nifti/blob/1462ae5dd979fa3f276fe7a78ceb9b028121536f/dicom2nifti/common.py#L510-L545
icometrix/dicom2nifti
dicom2nifti/common.py
is_orthogonal
def is_orthogonal(dicoms, log_details=False): """ Validate that volume is orthonormal :param dicoms: check that we have a volume without skewing """ first_image_orient1 = numpy.array(dicoms[0].ImageOrientationPatient)[0:3] first_image_orient2 = numpy.array(dicoms[0].ImageOrientationPatient)[3:6...
python
def is_orthogonal(dicoms, log_details=False): """ Validate that volume is orthonormal :param dicoms: check that we have a volume without skewing """ first_image_orient1 = numpy.array(dicoms[0].ImageOrientationPatient)[0:3] first_image_orient2 = numpy.array(dicoms[0].ImageOrientationPatient)[3:6...
[ "def", "is_orthogonal", "(", "dicoms", ",", "log_details", "=", "False", ")", ":", "first_image_orient1", "=", "numpy", ".", "array", "(", "dicoms", "[", "0", "]", ".", "ImageOrientationPatient", ")", "[", "0", ":", "3", "]", "first_image_orient2", "=", "n...
Validate that volume is orthonormal :param dicoms: check that we have a volume without skewing
[ "Validate", "that", "volume", "is", "orthonormal" ]
train
https://github.com/icometrix/dicom2nifti/blob/1462ae5dd979fa3f276fe7a78ceb9b028121536f/dicom2nifti/common.py#L558-L585
icometrix/dicom2nifti
dicom2nifti/common.py
is_orthogonal_nifti
def is_orthogonal_nifti(nifti_file): """ Validate that volume is orthonormal :param dicoms: check that we have a volume without skewing """ nifti_image = nibabel.load(nifti_file) affine = nifti_image.affine transformed_x = numpy.transpose(numpy.dot(affine, [[1], [0], [0], [0]]))[0][:3] ...
python
def is_orthogonal_nifti(nifti_file): """ Validate that volume is orthonormal :param dicoms: check that we have a volume without skewing """ nifti_image = nibabel.load(nifti_file) affine = nifti_image.affine transformed_x = numpy.transpose(numpy.dot(affine, [[1], [0], [0], [0]]))[0][:3] ...
[ "def", "is_orthogonal_nifti", "(", "nifti_file", ")", ":", "nifti_image", "=", "nibabel", ".", "load", "(", "nifti_file", ")", "affine", "=", "nifti_image", ".", "affine", "transformed_x", "=", "numpy", ".", "transpose", "(", "numpy", ".", "dot", "(", "affin...
Validate that volume is orthonormal :param dicoms: check that we have a volume without skewing
[ "Validate", "that", "volume", "is", "orthonormal" ]
train
https://github.com/icometrix/dicom2nifti/blob/1462ae5dd979fa3f276fe7a78ceb9b028121536f/dicom2nifti/common.py#L588-L611
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", ")", ":", "# 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 will only slightly change causing the values to remain equal on multiple ...
Sort the dicoms based om the image possition patient :param dicoms: list of dicoms
[ "Sort", "the", "dicoms", "based", "om", "the", "image", "possition", "patient" ]
train
https://github.com/icometrix/dicom2nifti/blob/1462ae5dd979fa3f276fe7a78ceb9b028121536f/dicom2nifti/common.py#L614-L635
icometrix/dicom2nifti
dicom2nifti/common.py
validate_slice_increment
def validate_slice_increment(dicoms): """ Validate that the distance between all slices is equal (or very close to) :param dicoms: list of dicoms """ first_image_position = numpy.array(dicoms[0].ImagePositionPatient) previous_image_position = numpy.array(dicoms[1].ImagePositionPatient) inc...
python
def validate_slice_increment(dicoms): """ Validate that the distance between all slices is equal (or very close to) :param dicoms: list of dicoms """ first_image_position = numpy.array(dicoms[0].ImagePositionPatient) previous_image_position = numpy.array(dicoms[1].ImagePositionPatient) inc...
[ "def", "validate_slice_increment", "(", "dicoms", ")", ":", "first_image_position", "=", "numpy", ".", "array", "(", "dicoms", "[", "0", "]", ".", "ImagePositionPatient", ")", "previous_image_position", "=", "numpy", ".", "array", "(", "dicoms", "[", "1", "]",...
Validate that the distance between all slices is equal (or very close to) :param dicoms: list of dicoms
[ "Validate", "that", "the", "distance", "between", "all", "slices", "is", "equal", "(", "or", "very", "close", "to", ")" ]
train
https://github.com/icometrix/dicom2nifti/blob/1462ae5dd979fa3f276fe7a78ceb9b028121536f/dicom2nifti/common.py#L638-L660
icometrix/dicom2nifti
dicom2nifti/common.py
is_slice_increment_inconsistent
def is_slice_increment_inconsistent(dicoms): """ Validate that the distance between all slices is equal (or very close to) :param dicoms: list of dicoms """ sliceincrement_inconsistent = False first_image_position = numpy.array(dicoms[0].ImagePositionPatient) previous_image_position = numpy...
python
def is_slice_increment_inconsistent(dicoms): """ Validate that the distance between all slices is equal (or very close to) :param dicoms: list of dicoms """ sliceincrement_inconsistent = False first_image_position = numpy.array(dicoms[0].ImagePositionPatient) previous_image_position = numpy...
[ "def", "is_slice_increment_inconsistent", "(", "dicoms", ")", ":", "sliceincrement_inconsistent", "=", "False", "first_image_position", "=", "numpy", ".", "array", "(", "dicoms", "[", "0", "]", ".", "ImagePositionPatient", ")", "previous_image_position", "=", "numpy",...
Validate that the distance between all slices is equal (or very close to) :param dicoms: list of dicoms
[ "Validate", "that", "the", "distance", "between", "all", "slices", "is", "equal", "(", "or", "very", "close", "to", ")" ]
train
https://github.com/icometrix/dicom2nifti/blob/1462ae5dd979fa3f276fe7a78ceb9b028121536f/dicom2nifti/common.py#L663-L680
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" ]
train
https://github.com/icometrix/dicom2nifti/blob/1462ae5dd979fa3f276fe7a78ceb9b028121536f/dicom2nifti/common.py#L696-L715
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", ")", ":", "# set the repetition time in pixdim", "nifti_image", ".", "header", ".", "structarr", "[", "'pixdim'", "]", "[", "4", "]", "=", "repetition_time", "/", "1000.0", "# set tr...
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" ]
train
https://github.com/icometrix/dicom2nifti/blob/1462ae5dd979fa3f276fe7a78ceb9b028121536f/dicom2nifti/common.py#L718-L732
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...
train
https://github.com/icometrix/dicom2nifti/blob/1462ae5dd979fa3f276fe7a78ceb9b028121536f/dicom2nifti/convert_ge.py#L32-L52
icometrix/dicom2nifti
dicom2nifti/convert_ge.py
_is_diffusion_imaging
def _is_diffusion_imaging(grouped_dicoms): """ Use this function to detect if a dicom series is a ge dti dataset NOTE: We already assume this is a 4D dataset """ # we already assume 4D images as input # check if contains dti bval information bval_tag = Tag(0x0043, 0x1039) # put this there ...
python
def _is_diffusion_imaging(grouped_dicoms): """ Use this function to detect if a dicom series is a ge dti dataset NOTE: We already assume this is a 4D dataset """ # we already assume 4D images as input # check if contains dti bval information bval_tag = Tag(0x0043, 0x1039) # put this there ...
[ "def", "_is_diffusion_imaging", "(", "grouped_dicoms", ")", ":", "# we already assume 4D images as input", "# check if contains dti bval information", "bval_tag", "=", "Tag", "(", "0x0043", ",", "0x1039", ")", "# put this there as this is a slow step and used a lot", "found_bval", ...
Use this function to detect if a dicom series is a ge dti dataset NOTE: We already assume this is a 4D dataset
[ "Use", "this", "function", "to", "detect", "if", "a", "dicom", "series", "is", "a", "ge", "dti", "dataset", "NOTE", ":", "We", "already", "assume", "this", "is", "a", "4D", "dataset" ]
train
https://github.com/icometrix/dicom2nifti/blob/1462ae5dd979fa3f276fe7a78ceb9b028121536f/dicom2nifti/convert_ge.py#L71-L88
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", ")", ":", "# Create mosaic block", "logger", ".", "info", "(", "'Creating data block'", ")", "full_block", "=", "_get_full_block", "(", "grouped_dicoms", ")", "logger", ".", "info", "(", "'Creating af...
This function will convert ge 4d series to a nifti
[ "This", "function", "will", "convert", "ge", "4d", "series", "to", "a", "nifti" ]
train
https://github.com/icometrix/dicom2nifti/blob/1462ae5dd979fa3f276fe7a78ceb9b028121536f/dicom2nifti/convert_ge.py#L91-L136
icometrix/dicom2nifti
dicom2nifti/convert_ge.py
_get_full_block
def _get_full_block(grouped_dicoms): """ Generate a full datablock containing all timepoints """ # For each slice / mosaic create a data volume block data_blocks = [] for index in range(0, len(grouped_dicoms)): logger.info('Creating block %s of %s' % (index + 1, len(grouped_dicoms))) ...
python
def _get_full_block(grouped_dicoms): """ Generate a full datablock containing all timepoints """ # For each slice / mosaic create a data volume block data_blocks = [] for index in range(0, len(grouped_dicoms)): logger.info('Creating block %s of %s' % (index + 1, len(grouped_dicoms))) ...
[ "def", "_get_full_block", "(", "grouped_dicoms", ")", ":", "# For each slice / mosaic create a data volume block", "data_blocks", "=", "[", "]", "for", "index", "in", "range", "(", "0", ",", "len", "(", "grouped_dicoms", ")", ")", ":", "logger", ".", "info", "("...
Generate a full datablock containing all timepoints
[ "Generate", "a", "full", "datablock", "containing", "all", "timepoints" ]
train
https://github.com/icometrix/dicom2nifti/blob/1462ae5dd979fa3f276fe7a78ceb9b028121536f/dicom2nifti/convert_ge.py#L139-L165
icometrix/dicom2nifti
dicom2nifti/convert_ge.py
_get_grouped_dicoms
def _get_grouped_dicoms(dicom_input): """ Search all dicoms in the dicom directory, sort and validate them fast_read = True will only read the headers not the data """ # Order all dicom files by InstanceNumber dicoms = sorted(dicom_input, key=lambda x: x.InstanceNumber) # now group per st...
python
def _get_grouped_dicoms(dicom_input): """ Search all dicoms in the dicom directory, sort and validate them fast_read = True will only read the headers not the data """ # Order all dicom files by InstanceNumber dicoms = sorted(dicom_input, key=lambda x: x.InstanceNumber) # now group per st...
[ "def", "_get_grouped_dicoms", "(", "dicom_input", ")", ":", "# Order all dicom files by InstanceNumber", "dicoms", "=", "sorted", "(", "dicom_input", ",", "key", "=", "lambda", "x", ":", "x", ".", "InstanceNumber", ")", "# now group per stack", "grouped_dicoms", "=", ...
Search all dicoms in the dicom directory, sort and validate them fast_read = True will only read the headers not the data
[ "Search", "all", "dicoms", "in", "the", "dicom", "directory", "sort", "and", "validate", "them" ]
train
https://github.com/icometrix/dicom2nifti/blob/1462ae5dd979fa3f276fe7a78ceb9b028121536f/dicom2nifti/convert_ge.py#L176-L214
icometrix/dicom2nifti
dicom2nifti/convert_ge.py
_get_bvals_bvecs
def _get_bvals_bvecs(grouped_dicoms): """ Write the bvals from the sorted dicom files to a bval file """ # loop over all timepoints and create a list with all bvals and bvecs bvals = numpy.zeros([len(grouped_dicoms)], dtype=numpy.int32) bvecs = numpy.zeros([len(grouped_dicoms), 3]) for grou...
python
def _get_bvals_bvecs(grouped_dicoms): """ Write the bvals from the sorted dicom files to a bval file """ # loop over all timepoints and create a list with all bvals and bvecs bvals = numpy.zeros([len(grouped_dicoms)], dtype=numpy.int32) bvecs = numpy.zeros([len(grouped_dicoms), 3]) for grou...
[ "def", "_get_bvals_bvecs", "(", "grouped_dicoms", ")", ":", "# loop over all timepoints and create a list with all bvals and bvecs", "bvals", "=", "numpy", ".", "zeros", "(", "[", "len", "(", "grouped_dicoms", ")", "]", ",", "dtype", "=", "numpy", ".", "int32", ")",...
Write the bvals from the sorted dicom files to a bval file
[ "Write", "the", "bvals", "from", "the", "sorted", "dicom", "files", "to", "a", "bval", "file" ]
train
https://github.com/icometrix/dicom2nifti/blob/1462ae5dd979fa3f276fe7a78ceb9b028121536f/dicom2nifti/convert_ge.py#L217-L259
icometrix/dicom2nifti
dicom2nifti/convert_ge.py
_create_bvals_bvecs
def _create_bvals_bvecs(grouped_dicoms, bval_file, bvec_file): """ Write the bvals from the sorted dicom files to a bval file """ # get the bvals and bvecs bvals, bvecs = _get_bvals_bvecs(grouped_dicoms) # save the found bvecs to the file common.write_bval_file(bvals, bval_file) common...
python
def _create_bvals_bvecs(grouped_dicoms, bval_file, bvec_file): """ Write the bvals from the sorted dicom files to a bval file """ # get the bvals and bvecs bvals, bvecs = _get_bvals_bvecs(grouped_dicoms) # save the found bvecs to the file common.write_bval_file(bvals, bval_file) common...
[ "def", "_create_bvals_bvecs", "(", "grouped_dicoms", ",", "bval_file", ",", "bvec_file", ")", ":", "# get the bvals and bvecs", "bvals", ",", "bvecs", "=", "_get_bvals_bvecs", "(", "grouped_dicoms", ")", "# save the found bvecs to the file", "common", ".", "write_bval_fil...
Write the bvals from the sorted dicom files to a bval file
[ "Write", "the", "bvals", "from", "the", "sorted", "dicom", "files", "to", "a", "bval", "file" ]
train
https://github.com/icometrix/dicom2nifti/blob/1462ae5dd979fa3f276fe7a78ceb9b028121536f/dicom2nifti/convert_ge.py#L262-L274
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", ")", "# TODO add validations and conversion for DTI and fMRI once testdata is available", "logger", ".", "info", "(", "'Assum...
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",...
train
https://github.com/icometrix/dicom2nifti/blob/1462ae5dd979fa3f276fe7a78ceb9b028121536f/dicom2nifti/convert_hitachi.py#L25-L41
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...
train
https://github.com/icometrix/dicom2nifti/blob/1462ae5dd979fa3f276fe7a78ceb9b028121536f/dicom2nifti/convert_siemens.py#L45-L66
icometrix/dicom2nifti
dicom2nifti/convert_siemens.py
_is_mosaic
def _is_mosaic(dicom_input): """ Use this function to detect if a dicom series is a siemens 4d dataset NOTE: Only the first slice will be checked so you can only provide an already sorted dicom directory (containing one series) """ # for grouped dicoms if type(dicom_input) is list and type(d...
python
def _is_mosaic(dicom_input): """ Use this function to detect if a dicom series is a siemens 4d dataset NOTE: Only the first slice will be checked so you can only provide an already sorted dicom directory (containing one series) """ # for grouped dicoms if type(dicom_input) is list and type(d...
[ "def", "_is_mosaic", "(", "dicom_input", ")", ":", "# for grouped dicoms", "if", "type", "(", "dicom_input", ")", "is", "list", "and", "type", "(", "dicom_input", "[", "0", "]", ")", "is", "list", ":", "header", "=", "dicom_input", "[", "0", "]", "[", ...
Use this function to detect if a dicom series is a siemens 4d dataset NOTE: Only the first slice will be checked so you can only provide an already sorted dicom directory (containing one series)
[ "Use", "this", "function", "to", "detect", "if", "a", "dicom", "series", "is", "a", "siemens", "4d", "dataset", "NOTE", ":", "Only", "the", "first", "slice", "will", "be", "checked", "so", "you", "can", "only", "provide", "an", "already", "sorted", "dico...
train
https://github.com/icometrix/dicom2nifti/blob/1462ae5dd979fa3f276fe7a78ceb9b028121536f/dicom2nifti/convert_siemens.py#L69-L88
icometrix/dicom2nifti
dicom2nifti/convert_siemens.py
_mosaic_4d_to_nifti
def _mosaic_4d_to_nifti(dicom_input, output_file): """ This function will convert siemens 4d series to a nifti Some inspiration on which fields can be used was taken from http://slicer.org/doc/html/DICOMDiffusionVolumePlugin_8py_source.html """ # Get the sorted mosaics logger.info('Sorting d...
python
def _mosaic_4d_to_nifti(dicom_input, output_file): """ This function will convert siemens 4d series to a nifti Some inspiration on which fields can be used was taken from http://slicer.org/doc/html/DICOMDiffusionVolumePlugin_8py_source.html """ # Get the sorted mosaics logger.info('Sorting d...
[ "def", "_mosaic_4d_to_nifti", "(", "dicom_input", ",", "output_file", ")", ":", "# Get the sorted mosaics", "logger", ".", "info", "(", "'Sorting dicom slices'", ")", "sorted_mosaics", "=", "_get_sorted_mosaics", "(", "dicom_input", ")", "common", ".", "validate_orienta...
This function will convert siemens 4d series to a nifti Some inspiration on which fields can be used was taken from http://slicer.org/doc/html/DICOMDiffusionVolumePlugin_8py_source.html
[ "This", "function", "will", "convert", "siemens", "4d", "series", "to", "a", "nifti", "Some", "inspiration", "on", "which", "fields", "can", "be", "used", "was", "taken", "from", "http", ":", "//", "slicer", ".", "org", "/", "doc", "/", "html", "/", "D...
train
https://github.com/icometrix/dicom2nifti/blob/1462ae5dd979fa3f276fe7a78ceb9b028121536f/dicom2nifti/convert_siemens.py#L133-L182
icometrix/dicom2nifti
dicom2nifti/convert_siemens.py
_classic_4d_to_nifti
def _classic_4d_to_nifti(grouped_dicoms, output_file): """ This function will convert siemens 4d series to a nifti Some inspiration on which fields can be used was taken from http://slicer.org/doc/html/DICOMDiffusionVolumePlugin_8py_source.html """ # Get the sorted mosaics all_dicoms = [i fo...
python
def _classic_4d_to_nifti(grouped_dicoms, output_file): """ This function will convert siemens 4d series to a nifti Some inspiration on which fields can be used was taken from http://slicer.org/doc/html/DICOMDiffusionVolumePlugin_8py_source.html """ # Get the sorted mosaics all_dicoms = [i fo...
[ "def", "_classic_4d_to_nifti", "(", "grouped_dicoms", ",", "output_file", ")", ":", "# Get the sorted mosaics", "all_dicoms", "=", "[", "i", "for", "sl", "in", "grouped_dicoms", "for", "i", "in", "sl", "]", "# combine into 1 list for validating", "common", ".", "val...
This function will convert siemens 4d series to a nifti Some inspiration on which fields can be used was taken from http://slicer.org/doc/html/DICOMDiffusionVolumePlugin_8py_source.html
[ "This", "function", "will", "convert", "siemens", "4d", "series", "to", "a", "nifti", "Some", "inspiration", "on", "which", "fields", "can", "be", "used", "was", "taken", "from", "http", ":", "//", "slicer", ".", "org", "/", "doc", "/", "html", "/", "D...
train
https://github.com/icometrix/dicom2nifti/blob/1462ae5dd979fa3f276fe7a78ceb9b028121536f/dicom2nifti/convert_siemens.py#L185-L236
icometrix/dicom2nifti
dicom2nifti/convert_siemens.py
_classic_get_grouped_dicoms
def _classic_get_grouped_dicoms(dicom_input): """ Search all dicoms in the dicom directory, sort and validate them fast_read = True will only read the headers not the data """ # Loop overall files and build dict # Order all dicom files by InstanceNumber if [d for d in dicom_input if 'Instan...
python
def _classic_get_grouped_dicoms(dicom_input): """ Search all dicoms in the dicom directory, sort and validate them fast_read = True will only read the headers not the data """ # Loop overall files and build dict # Order all dicom files by InstanceNumber if [d for d in dicom_input if 'Instan...
[ "def", "_classic_get_grouped_dicoms", "(", "dicom_input", ")", ":", "# Loop overall files and build dict", "# Order all dicom files by InstanceNumber", "if", "[", "d", "for", "d", "in", "dicom_input", "if", "'InstanceNumber'", "in", "d", "]", ":", "dicoms", "=", "sorted...
Search all dicoms in the dicom directory, sort and validate them fast_read = True will only read the headers not the data
[ "Search", "all", "dicoms", "in", "the", "dicom", "directory", "sort", "and", "validate", "them" ]
train
https://github.com/icometrix/dicom2nifti/blob/1462ae5dd979fa3f276fe7a78ceb9b028121536f/dicom2nifti/convert_siemens.py#L239-L267
icometrix/dicom2nifti
dicom2nifti/convert_siemens.py
_classic_get_full_block
def _classic_get_full_block(grouped_dicoms): """ Generate a full datablock containing all timepoints """ # For each slice / mosaic create a data volume block data_blocks = [] for index in range(0, len(grouped_dicoms)): logger.info('Creating block %s of %s' % (index + 1, len(grouped_dicom...
python
def _classic_get_full_block(grouped_dicoms): """ Generate a full datablock containing all timepoints """ # For each slice / mosaic create a data volume block data_blocks = [] for index in range(0, len(grouped_dicoms)): logger.info('Creating block %s of %s' % (index + 1, len(grouped_dicom...
[ "def", "_classic_get_full_block", "(", "grouped_dicoms", ")", ":", "# For each slice / mosaic create a data volume block", "data_blocks", "=", "[", "]", "for", "index", "in", "range", "(", "0", ",", "len", "(", "grouped_dicoms", ")", ")", ":", "logger", ".", "info...
Generate a full datablock containing all timepoints
[ "Generate", "a", "full", "datablock", "containing", "all", "timepoints" ]
train
https://github.com/icometrix/dicom2nifti/blob/1462ae5dd979fa3f276fe7a78ceb9b028121536f/dicom2nifti/convert_siemens.py#L270-L289
icometrix/dicom2nifti
dicom2nifti/convert_siemens.py
_mosaic_get_full_block
def _mosaic_get_full_block(sorted_mosaics): """ Generate a full datablock containing all timepoints """ # For each slice / mosaic create a data volume block data_blocks = [] for index in range(0, len(sorted_mosaics)): data_blocks.append(_mosaic_to_block(sorted_mosaics[index])) # Add...
python
def _mosaic_get_full_block(sorted_mosaics): """ Generate a full datablock containing all timepoints """ # For each slice / mosaic create a data volume block data_blocks = [] for index in range(0, len(sorted_mosaics)): data_blocks.append(_mosaic_to_block(sorted_mosaics[index])) # Add...
[ "def", "_mosaic_get_full_block", "(", "sorted_mosaics", ")", ":", "# For each slice / mosaic create a data volume block", "data_blocks", "=", "[", "]", "for", "index", "in", "range", "(", "0", ",", "len", "(", "sorted_mosaics", ")", ")", ":", "data_blocks", ".", "...
Generate a full datablock containing all timepoints
[ "Generate", "a", "full", "datablock", "containing", "all", "timepoints" ]
train
https://github.com/icometrix/dicom2nifti/blob/1462ae5dd979fa3f276fe7a78ceb9b028121536f/dicom2nifti/convert_siemens.py#L300-L321
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", ")", ":", "# Order all dicom files by acquisition number", "sorted_mosaics", "=", "sorted", "(", "dicom_input", ",", "key", "=", "lambda", "x", ":", "x", ".", "AcquisitionNumber", ")", "for", "index", "in", "range", ...
Search all mosaics in the dicom directory, sort and validate them
[ "Search", "all", "mosaics", "in", "the", "dicom", "directory", "sort", "and", "validate", "them" ]
train
https://github.com/icometrix/dicom2nifti/blob/1462ae5dd979fa3f276fe7a78ceb9b028121536f/dicom2nifti/convert_siemens.py#L324-L336
icometrix/dicom2nifti
dicom2nifti/convert_siemens.py
_get_asconv_headers
def _get_asconv_headers(mosaic): """ Getter for the asconv headers (asci header info stored in the dicom) """ asconv_headers = re.findall(r'### ASCCONV BEGIN(.*)### ASCCONV END ###', mosaic[Tag(0x0029, 0x1020)].value.decode(encoding='ISO-8859-1'), ...
python
def _get_asconv_headers(mosaic): """ Getter for the asconv headers (asci header info stored in the dicom) """ asconv_headers = re.findall(r'### ASCCONV BEGIN(.*)### ASCCONV END ###', mosaic[Tag(0x0029, 0x1020)].value.decode(encoding='ISO-8859-1'), ...
[ "def", "_get_asconv_headers", "(", "mosaic", ")", ":", "asconv_headers", "=", "re", ".", "findall", "(", "r'### ASCCONV BEGIN(.*)### ASCCONV END ###'", ",", "mosaic", "[", "Tag", "(", "0x0029", ",", "0x1020", ")", "]", ".", "value", ".", "decode", "(", "encodi...
Getter for the asconv headers (asci header info stored in the dicom)
[ "Getter", "for", "the", "asconv", "headers", "(", "asci", "header", "info", "stored", "in", "the", "dicom", ")" ]
train
https://github.com/icometrix/dicom2nifti/blob/1462ae5dd979fa3f276fe7a78ceb9b028121536f/dicom2nifti/convert_siemens.py#L339-L347
icometrix/dicom2nifti
dicom2nifti/convert_siemens.py
_get_mosaic_type
def _get_mosaic_type(mosaic): """ Check the extra ascconv headers for the mosaic type based on the slice position We always assume axial in this case the implementation resembles the last lines of documentation in https://www.icts.uiowa.edu/confluence/plugins/viewsource/viewpagesrc.action?pageId=547...
python
def _get_mosaic_type(mosaic): """ Check the extra ascconv headers for the mosaic type based on the slice position We always assume axial in this case the implementation resembles the last lines of documentation in https://www.icts.uiowa.edu/confluence/plugins/viewsource/viewpagesrc.action?pageId=547...
[ "def", "_get_mosaic_type", "(", "mosaic", ")", ":", "ascconv_headers", "=", "_get_asconv_headers", "(", "mosaic", ")", "try", ":", "size", "=", "int", "(", "re", ".", "findall", "(", "r'sSliceArray\\.lSize\\s*=\\s*(\\d+)'", ",", "ascconv_headers", ")", "[", "0",...
Check the extra ascconv headers for the mosaic type based on the slice position We always assume axial in this case the implementation resembles the last lines of documentation in https://www.icts.uiowa.edu/confluence/plugins/viewsource/viewpagesrc.action?pageId=54756326
[ "Check", "the", "extra", "ascconv", "headers", "for", "the", "mosaic", "type", "based", "on", "the", "slice", "position", "We", "always", "assume", "axial", "in", "this", "case", "the", "implementation", "resembles", "the", "last", "lines", "of", "documentatio...
train
https://github.com/icometrix/dicom2nifti/blob/1462ae5dd979fa3f276fe7a78ceb9b028121536f/dicom2nifti/convert_siemens.py#L350-L396
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", ")", ":", "# 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", ".", "findall", "(", "r'(\\d+)\\D+(\\d+)...
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" ]
train
https://github.com/icometrix/dicom2nifti/blob/1462ae5dd979fa3f276fe7a78ceb9b028121536f/dicom2nifti/convert_siemens.py#L399-L440
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", ")", ":", "# read dicom series with pds", "dicom_header", "=", "dicom_input", "[", "0", "]", "# Create affine matrix (http://nipy.sourceforge.net/nibabel/dicom/dicom_orientation.html#dicom-slice-affine)", "image_orient1", "=",...
Function to create the affine matrix for a siemens mosaic dataset This will work for siemens dti and 4d if in mosaic format
[ "Function", "to", "create", "the", "affine", "matrix", "for", "a", "siemens", "mosaic", "dataset", "This", "will", "work", "for", "siemens", "dti", "and", "4d", "if", "in", "mosaic", "format" ]
train
https://github.com/icometrix/dicom2nifti/blob/1462ae5dd979fa3f276fe7a78ceb9b028121536f/dicom2nifti/convert_siemens.py#L443-L467
icometrix/dicom2nifti
dicom2nifti/convert_siemens.py
_create_bvals
def _create_bvals(sorted_dicoms, bval_file): """ Write the bvals from the sorted dicom files to a bval file """ bvals = [] for index in range(0, len(sorted_dicoms)): if type(sorted_dicoms[0]) is list: dicom_headers = sorted_dicoms[index][0] else: dicom_headers...
python
def _create_bvals(sorted_dicoms, bval_file): """ Write the bvals from the sorted dicom files to a bval file """ bvals = [] for index in range(0, len(sorted_dicoms)): if type(sorted_dicoms[0]) is list: dicom_headers = sorted_dicoms[index][0] else: dicom_headers...
[ "def", "_create_bvals", "(", "sorted_dicoms", ",", "bval_file", ")", ":", "bvals", "=", "[", "]", "for", "index", "in", "range", "(", "0", ",", "len", "(", "sorted_dicoms", ")", ")", ":", "if", "type", "(", "sorted_dicoms", "[", "0", "]", ")", "is", ...
Write the bvals from the sorted dicom files to a bval file
[ "Write", "the", "bvals", "from", "the", "sorted", "dicom", "files", "to", "a", "bval", "file" ]
train
https://github.com/icometrix/dicom2nifti/blob/1462ae5dd979fa3f276fe7a78ceb9b028121536f/dicom2nifti/convert_siemens.py#L470-L484
icometrix/dicom2nifti
dicom2nifti/convert_siemens.py
_create_bvecs
def _create_bvecs(sorted_dicoms, bvec_file): """ Calculate the bvecs and write the to a bvec file # inspired by dicom2nii from mricron # see http://users.fmrib.ox.ac.uk/~robson/internal/Dicom2Nifti111.m """ if type(sorted_dicoms[0]) is list: dicom_headers = sorted_dicoms[0][0] else:...
python
def _create_bvecs(sorted_dicoms, bvec_file): """ Calculate the bvecs and write the to a bvec file # inspired by dicom2nii from mricron # see http://users.fmrib.ox.ac.uk/~robson/internal/Dicom2Nifti111.m """ if type(sorted_dicoms[0]) is list: dicom_headers = sorted_dicoms[0][0] else:...
[ "def", "_create_bvecs", "(", "sorted_dicoms", ",", "bvec_file", ")", ":", "if", "type", "(", "sorted_dicoms", "[", "0", "]", ")", "is", "list", ":", "dicom_headers", "=", "sorted_dicoms", "[", "0", "]", "[", "0", "]", "else", ":", "dicom_headers", "=", ...
Calculate the bvecs and write the to a bvec file # inspired by dicom2nii from mricron # see http://users.fmrib.ox.ac.uk/~robson/internal/Dicom2Nifti111.m
[ "Calculate", "the", "bvecs", "and", "write", "the", "to", "a", "bvec", "file", "#", "inspired", "by", "dicom2nii", "from", "mricron", "#", "see", "http", ":", "//", "users", ".", "fmrib", ".", "ox", ".", "ac", ".", "uk", "/", "~robson", "/", "interna...
train
https://github.com/icometrix/dicom2nifti/blob/1462ae5dd979fa3f276fe7a78ceb9b028121536f/dicom2nifti/convert_siemens.py#L487-L536
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", ")", ":", "# read the input image", "input_image", "=", "nibabel", ".", "load", "(", "input_nifti", ")", "output_image", "=", "resample_nifti_images", "(", "[", "input_image", "]", ")", "output_image", ".", "to_fil...
Resample a gantry tilted image in place
[ "Resample", "a", "gantry", "tilted", "image", "in", "place" ]
train
https://github.com/icometrix/dicom2nifti/blob/1462ae5dd979fa3f276fe7a78ceb9b028121536f/dicom2nifti/resample.py#L15-L22
icometrix/dicom2nifti
dicom2nifti/resample.py
resample_nifti_images
def resample_nifti_images(nifti_images): """ In this function we will create an orthogonal image and resample the original images to this space In this calculation we work in 3 spaces / coordinate systems - original image coordinates - world coordinates - "projected" coordinates This last...
python
def resample_nifti_images(nifti_images): """ In this function we will create an orthogonal image and resample the original images to this space In this calculation we work in 3 spaces / coordinate systems - original image coordinates - world coordinates - "projected" coordinates This last...
[ "def", "resample_nifti_images", "(", "nifti_images", ")", ":", "# get the smallest voxelsize and use that", "voxel_size", "=", "nifti_images", "[", "0", "]", ".", "header", ".", "get_zooms", "(", ")", "for", "nifti_image", "in", "nifti_images", "[", "1", ":", "]",...
In this function we will create an orthogonal image and resample the original images to this space In this calculation we work in 3 spaces / coordinate systems - original image coordinates - world coordinates - "projected" coordinates This last one is a new rotated "orthogonal" coordinates system...
[ "In", "this", "function", "we", "will", "create", "an", "orthogonal", "image", "and", "resample", "the", "original", "images", "to", "this", "space" ]
train
https://github.com/icometrix/dicom2nifti/blob/1462ae5dd979fa3f276fe7a78ceb9b028121536f/dicom2nifti/resample.py#L25-L128
icometrix/dicom2nifti
dicom2nifti/resample.py
_create_affine
def _create_affine(x_axis, y_axis, z_axis, image_pos, voxel_sizes): """ Function to generate the affine matrix for a dicom series This method was based on (http://nipy.org/nibabel/dicom/dicom_orientation.html) :param sorted_dicoms: list with sorted dicom files """ # Create affine matrix (http:...
python
def _create_affine(x_axis, y_axis, z_axis, image_pos, voxel_sizes): """ Function to generate the affine matrix for a dicom series This method was based on (http://nipy.org/nibabel/dicom/dicom_orientation.html) :param sorted_dicoms: list with sorted dicom files """ # Create affine matrix (http:...
[ "def", "_create_affine", "(", "x_axis", ",", "y_axis", ",", "z_axis", ",", "image_pos", ",", "voxel_sizes", ")", ":", "# Create affine matrix (http://nipy.sourceforge.net/nibabel/dicom/dicom_orientation.html#dicom-slice-affine)", "affine", "=", "numpy", ".", "array", "(", "...
Function to generate the affine matrix for a dicom series This method was based on (http://nipy.org/nibabel/dicom/dicom_orientation.html) :param sorted_dicoms: list with sorted dicom files
[ "Function", "to", "generate", "the", "affine", "matrix", "for", "a", "dicom", "series", "This", "method", "was", "based", "on", "(", "http", ":", "//", "nipy", ".", "org", "/", "nibabel", "/", "dicom", "/", "dicom_orientation", ".", "html", ")" ]
train
https://github.com/icometrix/dicom2nifti/blob/1462ae5dd979fa3f276fe7a78ceb9b028121536f/dicom2nifti/resample.py#L131-L146
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", ")", ":", "# sort dicom files by series uid", "dicom_series", "=", "{", "}", "for", "root", ",", "_", ",", "files", "in", "...
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" ]
train
https://github.com/icometrix/dicom2nifti/blob/1462ae5dd979fa3f276fe7a78ceb9b028121536f/dicom2nifti/convert_dir.py#L34-L99
icometrix/dicom2nifti
dicom2nifti/convert_dir.py
_is_valid_imaging_dicom
def _is_valid_imaging_dicom(dicom_header): """ Function will do some basic checks to see if this is a valid imaging dicom """ # if it is philips and multiframe dicom then we assume it is ok try: if common.is_philips([dicom_header]): if common.is_multiframe_dicom([dicom_header]): ...
python
def _is_valid_imaging_dicom(dicom_header): """ Function will do some basic checks to see if this is a valid imaging dicom """ # if it is philips and multiframe dicom then we assume it is ok try: if common.is_philips([dicom_header]): if common.is_multiframe_dicom([dicom_header]): ...
[ "def", "_is_valid_imaging_dicom", "(", "dicom_header", ")", ":", "# if it is philips and multiframe dicom then we assume it is ok", "try", ":", "if", "common", ".", "is_philips", "(", "[", "dicom_header", "]", ")", ":", "if", "common", ".", "is_multiframe_dicom", "(", ...
Function will do some basic checks to see if this is a valid imaging dicom
[ "Function", "will", "do", "some", "basic", "checks", "to", "see", "if", "this", "is", "a", "valid", "imaging", "dicom" ]
train
https://github.com/icometrix/dicom2nifti/blob/1462ae5dd979fa3f276fe7a78ceb9b028121536f/dicom2nifti/convert_dir.py#L102-L130
icometrix/dicom2nifti
dicom2nifti/convert_dir.py
_remove_accents
def _remove_accents(filename): """ Function that will try to remove accents from a unicode string to be used in a filename. input filename should be either an ascii or unicode string """ # noinspection PyBroadException try: filename = filename.replace(" ", "_") if isinstance(file...
python
def _remove_accents(filename): """ Function that will try to remove accents from a unicode string to be used in a filename. input filename should be either an ascii or unicode string """ # noinspection PyBroadException try: filename = filename.replace(" ", "_") if isinstance(file...
[ "def", "_remove_accents", "(", "filename", ")", ":", "# noinspection PyBroadException", "try", ":", "filename", "=", "filename", ".", "replace", "(", "\" \"", ",", "\"_\"", ")", "if", "isinstance", "(", "filename", ",", "type", "(", "six", ".", "u", "(", "...
Function that will try to remove accents from a unicode string to be used in a filename. input filename should be either an ascii or unicode string
[ "Function", "that", "will", "try", "to", "remove", "accents", "from", "a", "unicode", "string", "to", "be", "used", "in", "a", "filename", ".", "input", "filename", "should", "be", "either", "an", "ascii", "or", "unicode", "string" ]
train
https://github.com/icometrix/dicom2nifti/blob/1462ae5dd979fa3f276fe7a78ceb9b028121536f/dicom2nifti/convert_dir.py#L133-L153
icometrix/dicom2nifti
dicom2nifti/convert_dir.py
_remove_accents_
def _remove_accents_(filename): """ Function that will try to remove accents from a unicode string to be used in a filename. input filename should be either an ascii or unicode string """ if isinstance(filename, type(six.u(''))): unicode_filename = filename else: unicode_filename...
python
def _remove_accents_(filename): """ Function that will try to remove accents from a unicode string to be used in a filename. input filename should be either an ascii or unicode string """ if isinstance(filename, type(six.u(''))): unicode_filename = filename else: unicode_filename...
[ "def", "_remove_accents_", "(", "filename", ")", ":", "if", "isinstance", "(", "filename", ",", "type", "(", "six", ".", "u", "(", "''", ")", ")", ")", ":", "unicode_filename", "=", "filename", "else", ":", "unicode_filename", "=", "six", ".", "u", "("...
Function that will try to remove accents from a unicode string to be used in a filename. input filename should be either an ascii or unicode string
[ "Function", "that", "will", "try", "to", "remove", "accents", "from", "a", "unicode", "string", "to", "be", "used", "in", "a", "filename", ".", "input", "filename", "should", "be", "either", "an", "ascii", "or", "unicode", "string" ]
train
https://github.com/icometrix/dicom2nifti/blob/1462ae5dd979fa3f276fe7a78ceb9b028121536f/dicom2nifti/convert_dir.py#L156-L175
aegirhall/console-menu
consolemenu/menu_formatter.py
MenuFormatBuilder.set_border_style
def set_border_style(self, border_style): """ Set the border style using the specified MenuBorderStyle instance. :param border_style: the instance of MenuBorderStyle to use for border style formatting. """ if not isinstance(border_style, MenuBorderStyle): raise TypeEr...
python
def set_border_style(self, border_style): """ Set the border style using the specified MenuBorderStyle instance. :param border_style: the instance of MenuBorderStyle to use for border style formatting. """ if not isinstance(border_style, MenuBorderStyle): raise TypeEr...
[ "def", "set_border_style", "(", "self", ",", "border_style", ")", ":", "if", "not", "isinstance", "(", "border_style", ",", "MenuBorderStyle", ")", ":", "raise", "TypeError", "(", "'border_style must be type MenuBorderStyle'", ")", "self", ".", "__header", ".", "s...
Set the border style using the specified MenuBorderStyle instance. :param border_style: the instance of MenuBorderStyle to use for border style formatting.
[ "Set", "the", "border", "style", "using", "the", "specified", "MenuBorderStyle", "instance", ".", ":", "param", "border_style", ":", "the", "instance", "of", "MenuBorderStyle", "to", "use", "for", "border", "style", "formatting", "." ]
train
https://github.com/aegirhall/console-menu/blob/1a28959d6f1dd6ac79c87b11efd8529d05532422/consolemenu/menu_formatter.py#L31-L44
aegirhall/console-menu
consolemenu/menu_formatter.py
MenuFormatBuilder.set_border_style_type
def set_border_style_type(self, border_style_type): """ Set the border style using the specified border style type. The border style type should be an integer value recognized by the border style factory for this formatter instance. The built-in border style types are provided by the `Me...
python
def set_border_style_type(self, border_style_type): """ Set the border style using the specified border style type. The border style type should be an integer value recognized by the border style factory for this formatter instance. The built-in border style types are provided by the `Me...
[ "def", "set_border_style_type", "(", "self", ",", "border_style_type", ")", ":", "style", "=", "self", ".", "__border_style_factory", ".", "create_border", "(", "border_style_type", ")", "self", ".", "set_border_style", "(", "style", ")", "return", "self" ]
Set the border style using the specified border style type. The border style type should be an integer value recognized by the border style factory for this formatter instance. The built-in border style types are provided by the `MenuBorderStyleType` class, or custom border style types can be pr...
[ "Set", "the", "border", "style", "using", "the", "specified", "border", "style", "type", ".", "The", "border", "style", "type", "should", "be", "an", "integer", "value", "recognized", "by", "the", "border", "style", "factory", "for", "this", "formatter", "in...
train
https://github.com/aegirhall/console-menu/blob/1a28959d6f1dd6ac79c87b11efd8529d05532422/consolemenu/menu_formatter.py#L46-L56
aegirhall/console-menu
consolemenu/menu_formatter.py
MenuFormatBuilder.set_bottom_margin
def set_bottom_margin(self, bottom_margin): """ Set the bottom margin of the menu. This will determine the number of console lines appear between the bottom of the menu border and the menu input prompt. :param bottom_margin: an integer value """ self.__footer.style.margin...
python
def set_bottom_margin(self, bottom_margin): """ Set the bottom margin of the menu. This will determine the number of console lines appear between the bottom of the menu border and the menu input prompt. :param bottom_margin: an integer value """ self.__footer.style.margin...
[ "def", "set_bottom_margin", "(", "self", ",", "bottom_margin", ")", ":", "self", ".", "__footer", ".", "style", ".", "margins", ".", "bottom", "=", "bottom_margin", "return", "self" ]
Set the bottom margin of the menu. This will determine the number of console lines appear between the bottom of the menu border and the menu input prompt. :param bottom_margin: an integer value
[ "Set", "the", "bottom", "margin", "of", "the", "menu", ".", "This", "will", "determine", "the", "number", "of", "console", "lines", "appear", "between", "the", "bottom", "of", "the", "menu", "border", "and", "the", "menu", "input", "prompt", ".", ":", "p...
train
https://github.com/aegirhall/console-menu/blob/1a28959d6f1dd6ac79c87b11efd8529d05532422/consolemenu/menu_formatter.py#L70-L77
aegirhall/console-menu
consolemenu/menu_formatter.py
MenuFormatBuilder.set_left_margin
def set_left_margin(self, left_margin): """ Set the left margin of the menu. This will determine the number of spaces between the left edge of the screen and the left menu border. :param left_margin: an integer value """ self.__header.style.margins.left = left_margin ...
python
def set_left_margin(self, left_margin): """ Set the left margin of the menu. This will determine the number of spaces between the left edge of the screen and the left menu border. :param left_margin: an integer value """ self.__header.style.margins.left = left_margin ...
[ "def", "set_left_margin", "(", "self", ",", "left_margin", ")", ":", "self", ".", "__header", ".", "style", ".", "margins", ".", "left", "=", "left_margin", "self", ".", "__prologue", ".", "style", ".", "margins", ".", "left", "=", "left_margin", "self", ...
Set the left margin of the menu. This will determine the number of spaces between the left edge of the screen and the left menu border. :param left_margin: an integer value
[ "Set", "the", "left", "margin", "of", "the", "menu", ".", "This", "will", "determine", "the", "number", "of", "spaces", "between", "the", "left", "edge", "of", "the", "screen", "and", "the", "left", "menu", "border", ".", ":", "param", "left_margin", ":"...
train
https://github.com/aegirhall/console-menu/blob/1a28959d6f1dd6ac79c87b11efd8529d05532422/consolemenu/menu_formatter.py#L79-L91
aegirhall/console-menu
consolemenu/menu_formatter.py
MenuFormatBuilder.set_right_margin
def set_right_margin(self, right_margin): """ Set the right margin of the menu. This will determine the number of spaces between the right edge of the screen and the right menu border. :param right_margin: an integer value """ self.__header.style.margins.right = right_ma...
python
def set_right_margin(self, right_margin): """ Set the right margin of the menu. This will determine the number of spaces between the right edge of the screen and the right menu border. :param right_margin: an integer value """ self.__header.style.margins.right = right_ma...
[ "def", "set_right_margin", "(", "self", ",", "right_margin", ")", ":", "self", ".", "__header", ".", "style", ".", "margins", ".", "right", "=", "right_margin", "self", ".", "__prologue", ".", "style", ".", "margins", ".", "right", "=", "right_margin", "se...
Set the right margin of the menu. This will determine the number of spaces between the right edge of the screen and the right menu border. :param right_margin: an integer value
[ "Set", "the", "right", "margin", "of", "the", "menu", ".", "This", "will", "determine", "the", "number", "of", "spaces", "between", "the", "right", "edge", "of", "the", "screen", "and", "the", "right", "menu", "border", ".", ":", "param", "right_margin", ...
train
https://github.com/aegirhall/console-menu/blob/1a28959d6f1dd6ac79c87b11efd8529d05532422/consolemenu/menu_formatter.py#L93-L105
aegirhall/console-menu
consolemenu/menu_formatter.py
MenuFormatBuilder.set_top_margin
def set_top_margin(self, top_margin): """ Set the top margin of the menu. This will determine the number of console lines between the top edge of the screen and the top menu border. :param top_margin: an integer value """ self.__header.style.margins.top = top_margin ...
python
def set_top_margin(self, top_margin): """ Set the top margin of the menu. This will determine the number of console lines between the top edge of the screen and the top menu border. :param top_margin: an integer value """ self.__header.style.margins.top = top_margin ...
[ "def", "set_top_margin", "(", "self", ",", "top_margin", ")", ":", "self", ".", "__header", ".", "style", ".", "margins", ".", "top", "=", "top_margin", "return", "self" ]
Set the top margin of the menu. This will determine the number of console lines between the top edge of the screen and the top menu border. :param top_margin: an integer value
[ "Set", "the", "top", "margin", "of", "the", "menu", ".", "This", "will", "determine", "the", "number", "of", "console", "lines", "between", "the", "top", "edge", "of", "the", "screen", "and", "the", "top", "menu", "border", ".", ":", "param", "top_margin...
train
https://github.com/aegirhall/console-menu/blob/1a28959d6f1dd6ac79c87b11efd8529d05532422/consolemenu/menu_formatter.py#L107-L114
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", "." ]
train
https://github.com/aegirhall/console-menu/blob/1a28959d6f1dd6ac79c87b11efd8529d05532422/consolemenu/menu_formatter.py#L246-L254
aegirhall/console-menu
consolemenu/menu_formatter.py
MenuFormatBuilder.format
def format(self, title=None, subtitle=None, prologue_text=None, epilogue_text=None, items=None): """ Format the menu and return as a string. :return: a string representation of the formatted menu. """ self.clear_data() content = '' # Header Section if tit...
python
def format(self, title=None, subtitle=None, prologue_text=None, epilogue_text=None, items=None): """ Format the menu and return as a string. :return: a string representation of the formatted menu. """ self.clear_data() content = '' # Header Section if tit...
[ "def", "format", "(", "self", ",", "title", "=", "None", ",", "subtitle", "=", "None", ",", "prologue_text", "=", "None", ",", "epilogue_text", "=", "None", ",", "items", "=", "None", ")", ":", "self", ".", "clear_data", "(", ")", "content", "=", "''...
Format the menu and return as a string. :return: a string representation of the formatted menu.
[ "Format", "the", "menu", "and", "return", "as", "a", "string", ".", ":", "return", ":", "a", "string", "representation", "of", "the", "formatted", "menu", "." ]
train
https://github.com/aegirhall/console-menu/blob/1a28959d6f1dd6ac79c87b11efd8529d05532422/consolemenu/menu_formatter.py#L256-L288
aegirhall/console-menu
consolemenu/validators/url.py
UrlValidator.validate
def validate(self, input_string): """ Validate url :return: True if match / False otherwise """ parsed_url = urlparse(url=input_string) return bool(parsed_url.scheme and parsed_url.netloc)
python
def validate(self, input_string): """ Validate url :return: True if match / False otherwise """ parsed_url = urlparse(url=input_string) return bool(parsed_url.scheme and parsed_url.netloc)
[ "def", "validate", "(", "self", ",", "input_string", ")", ":", "parsed_url", "=", "urlparse", "(", "url", "=", "input_string", ")", "return", "bool", "(", "parsed_url", ".", "scheme", "and", "parsed_url", ".", "netloc", ")" ]
Validate url :return: True if match / False otherwise
[ "Validate", "url" ]
train
https://github.com/aegirhall/console-menu/blob/1a28959d6f1dd6ac79c87b11efd8529d05532422/consolemenu/validators/url.py#L19-L26
aegirhall/console-menu
consolemenu/menu_component.py
MenuComponent.calculate_border_width
def calculate_border_width(self): """ Calculate the width of the menu border. This will be the width of the maximum allowable dimensions (usually the screen size), minus the left and right margins and the newline character. For example, given a maximum width of 80 characters, with left a...
python
def calculate_border_width(self): """ Calculate the width of the menu border. This will be the width of the maximum allowable dimensions (usually the screen size), minus the left and right margins and the newline character. For example, given a maximum width of 80 characters, with left a...
[ "def", "calculate_border_width", "(", "self", ")", ":", "return", "self", ".", "max_dimension", ".", "width", "-", "self", ".", "margins", ".", "left", "-", "self", ".", "margins", ".", "right", "-", "1" ]
Calculate the width of the menu border. This will be the width of the maximum allowable dimensions (usually the screen size), minus the left and right margins and the newline character. For example, given a maximum width of 80 characters, with left and right margins both set to 1, the border wid...
[ "Calculate", "the", "width", "of", "the", "menu", "border", ".", "This", "will", "be", "the", "width", "of", "the", "maximum", "allowable", "dimensions", "(", "usually", "the", "screen", "size", ")", "minus", "the", "left", "and", "right", "margins", "and"...
train
https://github.com/aegirhall/console-menu/blob/1a28959d6f1dd6ac79c87b11efd8529d05532422/consolemenu/menu_component.py#L80-L90
aegirhall/console-menu
consolemenu/menu_component.py
MenuComponent.calculate_content_width
def calculate_content_width(self): """ Calculate the width of inner content of the border. This will be the width of the menu borders, minus the left and right padding, and minus the two vertical border characters. For example, given a border width of 77, with left and right margins eac...
python
def calculate_content_width(self): """ Calculate the width of inner content of the border. This will be the width of the menu borders, minus the left and right padding, and minus the two vertical border characters. For example, given a border width of 77, with left and right margins eac...
[ "def", "calculate_content_width", "(", "self", ")", ":", "return", "self", ".", "calculate_border_width", "(", ")", "-", "self", ".", "padding", ".", "left", "-", "self", ".", "padding", ".", "right", "-", "2" ]
Calculate the width of inner content of the border. This will be the width of the menu borders, minus the left and right padding, and minus the two vertical border characters. For example, given a border width of 77, with left and right margins each set to 2, the content width would be 71 (77 -...
[ "Calculate", "the", "width", "of", "inner", "content", "of", "the", "border", ".", "This", "will", "be", "the", "width", "of", "the", "menu", "borders", "minus", "the", "left", "and", "right", "padding", "and", "minus", "the", "two", "vertical", "border", ...
train
https://github.com/aegirhall/console-menu/blob/1a28959d6f1dd6ac79c87b11efd8529d05532422/consolemenu/menu_component.py#L92-L102
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", "." ]
train
https://github.com/aegirhall/console-menu/blob/1a28959d6f1dd6ac79c87b11efd8529d05532422/consolemenu/menu_component.py#L123-L133
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", "." ]
train
https://github.com/aegirhall/console-menu/blob/1a28959d6f1dd6ac79c87b11efd8529d05532422/consolemenu/menu_component.py#L145-L155
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", "." ]
train
https://github.com/aegirhall/console-menu/blob/1a28959d6f1dd6ac79c87b11efd8529d05532422/consolemenu/menu_component.py#L157-L167
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", "." ]
train
https://github.com/aegirhall/console-menu/blob/1a28959d6f1dd6ac79c87b11efd8529d05532422/consolemenu/menu_component.py#L169-L178
aegirhall/console-menu
consolemenu/menu_component.py
MenuItemsSection.show_item_bottom_border
def show_item_bottom_border(self, item_text, flag): """ Sets a flag that will show a bottom border for an item with the specified text. :param item_text: the text property of the item :param flag: boolean specifying if the border should be shown. """ if flag: ...
python
def show_item_bottom_border(self, item_text, flag): """ Sets a flag that will show a bottom border for an item with the specified text. :param item_text: the text property of the item :param flag: boolean specifying if the border should be shown. """ if flag: ...
[ "def", "show_item_bottom_border", "(", "self", ",", "item_text", ",", "flag", ")", ":", "if", "flag", ":", "self", ".", "__bottom_border_dict", "[", "item_text", "]", "=", "True", "else", ":", "self", ".", "__bottom_border_dict", ".", "pop", "(", "item_text"...
Sets a flag that will show a bottom border for an item with the specified text. :param item_text: the text property of the item :param flag: boolean specifying if the border should be shown.
[ "Sets", "a", "flag", "that", "will", "show", "a", "bottom", "border", "for", "an", "item", "with", "the", "specified", "text", ".", ":", "param", "item_text", ":", "the", "text", "property", "of", "the", "item", ":", "param", "flag", ":", "boolean", "s...
train
https://github.com/aegirhall/console-menu/blob/1a28959d6f1dd6ac79c87b11efd8529d05532422/consolemenu/menu_component.py#L297-L306
aegirhall/console-menu
consolemenu/menu_component.py
MenuItemsSection.show_item_top_border
def show_item_top_border(self, item_text, flag): """ Sets a flag that will show a top border for an item with the specified text. :param item_text: the text property of the item :param flag: boolean specifying if the border should be shown. """ if flag: self._...
python
def show_item_top_border(self, item_text, flag): """ Sets a flag that will show a top border for an item with the specified text. :param item_text: the text property of the item :param flag: boolean specifying if the border should be shown. """ if flag: self._...
[ "def", "show_item_top_border", "(", "self", ",", "item_text", ",", "flag", ")", ":", "if", "flag", ":", "self", ".", "__top_border_dict", "[", "item_text", "]", "=", "True", "else", ":", "self", ".", "__top_border_dict", ".", "pop", "(", "item_text", ",", ...
Sets a flag that will show a top border for an item with the specified text. :param item_text: the text property of the item :param flag: boolean specifying if the border should be shown.
[ "Sets", "a", "flag", "that", "will", "show", "a", "top", "border", "for", "an", "item", "with", "the", "specified", "text", ".", ":", "param", "item_text", ":", "the", "text", "property", "of", "the", "item", ":", "param", "flag", ":", "boolean", "spec...
train
https://github.com/aegirhall/console-menu/blob/1a28959d6f1dd6ac79c87b11efd8529d05532422/consolemenu/menu_component.py#L308-L317
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", "." ]
train
https://github.com/aegirhall/console-menu/blob/1a28959d6f1dd6ac79c87b11efd8529d05532422/consolemenu/format/menu_borders.py#L352-L378
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", "." ]
train
https://github.com/aegirhall/console-menu/blob/1a28959d6f1dd6ac79c87b11efd8529d05532422/consolemenu/format/menu_borders.py#L454-L463
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", "." ]
train
https://github.com/aegirhall/console-menu/blob/1a28959d6f1dd6ac79c87b11efd8529d05532422/consolemenu/items/submenu_item.py#L19-L27
aegirhall/console-menu
consolemenu/items/submenu_item.py
SubmenuItem.clean_up
def clean_up(self): """ This class overrides this method """ self.submenu.join() self.menu.clear_screen() self.menu.resume()
python
def clean_up(self): """ This class overrides this method """ self.submenu.join() self.menu.clear_screen() self.menu.resume()
[ "def", "clean_up", "(", "self", ")", ":", "self", ".", "submenu", ".", "join", "(", ")", "self", ".", "menu", ".", "clear_screen", "(", ")", "self", ".", "menu", ".", "resume", "(", ")" ]
This class overrides this method
[ "This", "class", "overrides", "this", "method" ]
train
https://github.com/aegirhall/console-menu/blob/1a28959d6f1dd6ac79c87b11efd8529d05532422/consolemenu/items/submenu_item.py#L42-L48
aegirhall/console-menu
consolemenu/prompt_utils.py
PromptFormatter.format_prompt
def format_prompt(prompt=None, default=None, enable_quit=False, quit_string='q', quit_message='(enter q to Quit)'): """ Format the prompt. :param prompt: the prompt message. :param default: the default answer if user does not provide a response. :param enab...
python
def format_prompt(prompt=None, default=None, enable_quit=False, quit_string='q', quit_message='(enter q to Quit)'): """ Format the prompt. :param prompt: the prompt message. :param default: the default answer if user does not provide a response. :param enab...
[ "def", "format_prompt", "(", "prompt", "=", "None", ",", "default", "=", "None", ",", "enable_quit", "=", "False", ",", "quit_string", "=", "'q'", ",", "quit_message", "=", "'(enter q to Quit)'", ")", ":", "if", "prompt", "is", "None", ":", "return", "None...
Format the prompt. :param prompt: the prompt message. :param default: the default answer if user does not provide a response. :param enable_quit: specifies whether the user can cancel out of the input prompt. :param quit_string: the string whcih the user must input in order to quit. ...
[ "Format", "the", "prompt", ".", ":", "param", "prompt", ":", "the", "prompt", "message", ".", ":", "param", "default", ":", "the", "default", "answer", "if", "user", "does", "not", "provide", "a", "response", ".", ":", "param", "enable_quit", ":", "speci...
train
https://github.com/aegirhall/console-menu/blob/1a28959d6f1dd6ac79c87b11efd8529d05532422/consolemenu/prompt_utils.py#L15-L34
aegirhall/console-menu
consolemenu/prompt_utils.py
PromptUtils.confirm_answer
def confirm_answer(self, answer, message=None): """ Prompts the user to confirm a question with a yes/no prompt. If no message is specified, the default message is: "You entered {}. Is this correct?" :param answer: the answer to confirm. :param message: a message to display rath...
python
def confirm_answer(self, answer, message=None): """ Prompts the user to confirm a question with a yes/no prompt. If no message is specified, the default message is: "You entered {}. Is this correct?" :param answer: the answer to confirm. :param message: a message to display rath...
[ "def", "confirm_answer", "(", "self", ",", "answer", ",", "message", "=", "None", ")", ":", "if", "message", "is", "None", ":", "message", "=", "\"\\nYou entered {0}. Is this correct?\"", ".", "format", "(", "answer", ")", "return", "self", ".", "prompt_for_y...
Prompts the user to confirm a question with a yes/no prompt. If no message is specified, the default message is: "You entered {}. Is this correct?" :param answer: the answer to confirm. :param message: a message to display rather than the default message. :return: True if the user confi...
[ "Prompts", "the", "user", "to", "confirm", "a", "question", "with", "a", "yes", "/", "no", "prompt", ".", "If", "no", "message", "is", "specified", "the", "default", "message", "is", ":", "You", "entered", "{}", ".", "Is", "this", "correct?", ":", "par...
train
https://github.com/aegirhall/console-menu/blob/1a28959d6f1dd6ac79c87b11efd8529d05532422/consolemenu/prompt_utils.py#L64-L74
aegirhall/console-menu
consolemenu/prompt_utils.py
PromptUtils.enter_to_continue
def enter_to_continue(self, message=None): """ Creates a console prompt with the given message, or defaults to 'Press [Enter] to continue' if no message is provided. :param message: """ if message: message = message.rstrip() + ' ' else: mes...
python
def enter_to_continue(self, message=None): """ Creates a console prompt with the given message, or defaults to 'Press [Enter] to continue' if no message is provided. :param message: """ if message: message = message.rstrip() + ' ' else: mes...
[ "def", "enter_to_continue", "(", "self", ",", "message", "=", "None", ")", ":", "if", "message", ":", "message", "=", "message", ".", "rstrip", "(", ")", "+", "' '", "else", ":", "message", "=", "'Press [Enter] to continue '", "self", ".", "__screen", ".",...
Creates a console prompt with the given message, or defaults to 'Press [Enter] to continue' if no message is provided. :param message:
[ "Creates", "a", "console", "prompt", "with", "the", "given", "message", "or", "defaults", "to", "Press", "[", "Enter", "]", "to", "continue", "if", "no", "message", "is", "provided", ".", ":", "param", "message", ":" ]
train
https://github.com/aegirhall/console-menu/blob/1a28959d6f1dd6ac79c87b11efd8529d05532422/consolemenu/prompt_utils.py#L76-L86
aegirhall/console-menu
consolemenu/prompt_utils.py
PromptUtils.input
def input(self, prompt=None, default=None, validators=None, enable_quit=False, quit_string='q', quit_message='(enter q to Quit)'): """ Prompt the user for input. :param prompt: the message to prompt the user. :param default: the default value to suggest as an answer. ...
python
def input(self, prompt=None, default=None, validators=None, enable_quit=False, quit_string='q', quit_message='(enter q to Quit)'): """ Prompt the user for input. :param prompt: the message to prompt the user. :param default: the default value to suggest as an answer. ...
[ "def", "input", "(", "self", ",", "prompt", "=", "None", ",", "default", "=", "None", ",", "validators", "=", "None", ",", "enable_quit", "=", "False", ",", "quit_string", "=", "'q'", ",", "quit_message", "=", "'(enter q to Quit)'", ")", ":", "prompt", "...
Prompt the user for input. :param prompt: the message to prompt the user. :param default: the default value to suggest as an answer. :param validators: list of validators to perform input validation. :param enable_quit: specifies whether the user can cancel out of the input prompt. ...
[ "Prompt", "the", "user", "for", "input", ".", ":", "param", "prompt", ":", "the", "message", "to", "prompt", "the", "user", ".", ":", "param", "default", ":", "the", "default", "value", "to", "suggest", "as", "an", "answer", ".", ":", "param", "validat...
train
https://github.com/aegirhall/console-menu/blob/1a28959d6f1dd6ac79c87b11efd8529d05532422/consolemenu/prompt_utils.py#L88-L114
aegirhall/console-menu
consolemenu/prompt_utils.py
PromptUtils.input_password
def input_password(self, message=None): """ Prompt the user for a password. This is equivalent to the input() method, but does not echo inputted characters to the screen. :param message: the prompt message. """ message = self.__prompt_formatter.format_prompt(message) ...
python
def input_password(self, message=None): """ Prompt the user for a password. This is equivalent to the input() method, but does not echo inputted characters to the screen. :param message: the prompt message. """ message = self.__prompt_formatter.format_prompt(message) ...
[ "def", "input_password", "(", "self", ",", "message", "=", "None", ")", ":", "message", "=", "self", ".", "__prompt_formatter", ".", "format_prompt", "(", "message", ")", "try", ":", "if", "message", ":", "return", "getpass", ".", "getpass", "(", "message"...
Prompt the user for a password. This is equivalent to the input() method, but does not echo inputted characters to the screen. :param message: the prompt message.
[ "Prompt", "the", "user", "for", "a", "password", ".", "This", "is", "equivalent", "to", "the", "input", "()", "method", "but", "does", "not", "echo", "inputted", "characters", "to", "the", "screen", ".", ":", "param", "message", ":", "the", "prompt", "me...
train
https://github.com/aegirhall/console-menu/blob/1a28959d6f1dd6ac79c87b11efd8529d05532422/consolemenu/prompt_utils.py#L116-L130
aegirhall/console-menu
consolemenu/prompt_utils.py
PromptUtils.prompt_and_confirm_password
def prompt_and_confirm_password(self, message): """ Method to prompt for a password using the given message, then prompt for a confirmation password, and verify that they match. :param message: the prompt message :return: the password """ while True: ...
python
def prompt_and_confirm_password(self, message): """ Method to prompt for a password using the given message, then prompt for a confirmation password, and verify that they match. :param message: the prompt message :return: the password """ while True: ...
[ "def", "prompt_and_confirm_password", "(", "self", ",", "message", ")", ":", "while", "True", ":", "pwd", "=", "self", ".", "input_password", "(", "message", ")", "cpwd", "=", "self", ".", "input_password", "(", "\"Confirm password\"", ")", "if", "pwd", "=="...
Method to prompt for a password using the given message, then prompt for a confirmation password, and verify that they match. :param message: the prompt message :return: the password
[ "Method", "to", "prompt", "for", "a", "password", "using", "the", "given", "message", "then", "prompt", "for", "a", "confirmation", "password", "and", "verify", "that", "they", "match", ".", ":", "param", "message", ":", "the", "prompt", "message", ":", "r...
train
https://github.com/aegirhall/console-menu/blob/1a28959d6f1dd6ac79c87b11efd8529d05532422/consolemenu/prompt_utils.py#L146-L159
aegirhall/console-menu
consolemenu/prompt_utils.py
PromptUtils.prompt_for_bilateral_choice
def prompt_for_bilateral_choice(self, prompt, option1, option2): """ Prompt the user for a response that must be one of the two supplied choices. NOTE: The user input verification is case-insensitive, but will return the original case provided by the given options. """ if...
python
def prompt_for_bilateral_choice(self, prompt, option1, option2): """ Prompt the user for a response that must be one of the two supplied choices. NOTE: The user input verification is case-insensitive, but will return the original case provided by the given options. """ if...
[ "def", "prompt_for_bilateral_choice", "(", "self", ",", "prompt", ",", "option1", ",", "option2", ")", ":", "if", "prompt", "is", "None", ":", "prompt", "=", "''", "prompt", "=", "prompt", ".", "rstrip", "(", ")", "+", "' ('", "+", "option1", "+", "'/'...
Prompt the user for a response that must be one of the two supplied choices. NOTE: The user input verification is case-insensitive, but will return the original case provided by the given options.
[ "Prompt", "the", "user", "for", "a", "response", "that", "must", "be", "one", "of", "the", "two", "supplied", "choices", ".", "NOTE", ":", "The", "user", "input", "verification", "is", "case", "-", "insensitive", "but", "will", "return", "the", "original",...
train
https://github.com/aegirhall/console-menu/blob/1a28959d6f1dd6ac79c87b11efd8529d05532422/consolemenu/prompt_utils.py#L161-L175
aegirhall/console-menu
consolemenu/prompt_utils.py
PromptUtils.prompt_for_trilateral_choice
def prompt_for_trilateral_choice(self, prompt, option1, option2, option3): """ Prompt the user for a response that must be one of the three supplied choices. NOTE: The user input verification is case-insensitive, but will return the original case provided by the given options. ""...
python
def prompt_for_trilateral_choice(self, prompt, option1, option2, option3): """ Prompt the user for a response that must be one of the three supplied choices. NOTE: The user input verification is case-insensitive, but will return the original case provided by the given options. ""...
[ "def", "prompt_for_trilateral_choice", "(", "self", ",", "prompt", ",", "option1", ",", "option2", ",", "option3", ")", ":", "if", "prompt", "is", "None", ":", "prompt", "=", "''", "prompt", "=", "prompt", ".", "rstrip", "(", ")", "+", "' ('", "+", "op...
Prompt the user for a response that must be one of the three supplied choices. NOTE: The user input verification is case-insensitive, but will return the original case provided by the given options.
[ "Prompt", "the", "user", "for", "a", "response", "that", "must", "be", "one", "of", "the", "three", "supplied", "choices", ".", "NOTE", ":", "The", "user", "input", "verification", "is", "case", "-", "insensitive", "but", "will", "return", "the", "original...
train
https://github.com/aegirhall/console-menu/blob/1a28959d6f1dd6ac79c87b11efd8529d05532422/consolemenu/prompt_utils.py#L177-L193
aegirhall/console-menu
consolemenu/prompt_utils.py
PromptUtils.prompt_for_numbered_choice
def prompt_for_numbered_choice(self, choices, title=None, prompt=">"): """ Displays a numbered vertical list of choices from the provided list of strings. :param choices: list of choices to display :param title: optional title to display above the numbered list :param prompt: pro...
python
def prompt_for_numbered_choice(self, choices, title=None, prompt=">"): """ Displays a numbered vertical list of choices from the provided list of strings. :param choices: list of choices to display :param title: optional title to display above the numbered list :param prompt: pro...
[ "def", "prompt_for_numbered_choice", "(", "self", ",", "choices", ",", "title", "=", "None", ",", "prompt", "=", "\">\"", ")", ":", "if", "choices", "is", "None", "or", "len", "(", "choices", ")", "<", "1", ":", "raise", "Exception", "(", "'choices list ...
Displays a numbered vertical list of choices from the provided list of strings. :param choices: list of choices to display :param title: optional title to display above the numbered list :param prompt: prompt string. Default is ">" :return: an int representing the selected index.
[ "Displays", "a", "numbered", "vertical", "list", "of", "choices", "from", "the", "provided", "list", "of", "strings", ".", ":", "param", "choices", ":", "list", "of", "choices", "to", "display", ":", "param", "title", ":", "optional", "title", "to", "displ...
train
https://github.com/aegirhall/console-menu/blob/1a28959d6f1dd6ac79c87b11efd8529d05532422/consolemenu/prompt_utils.py#L204-L231
aegirhall/console-menu
consolemenu/prompt_utils.py
PromptUtils.validate_input
def validate_input(self, input_string, validators): """ Validate the given input string against the specified list of validators. :param input_string: the input string to verify. :param validators: the list of validators. :raises InvalidValidator if the list of validators does no...
python
def validate_input(self, input_string, validators): """ Validate the given input string against the specified list of validators. :param input_string: the input string to verify. :param validators: the list of validators. :raises InvalidValidator if the list of validators does no...
[ "def", "validate_input", "(", "self", ",", "input_string", ",", "validators", ")", ":", "validation_result", "=", "True", "if", "isinstance", "(", "validators", ",", "BaseValidator", ")", ":", "validators", "=", "[", "validators", "]", "elif", "validators", "i...
Validate the given input string against the specified list of validators. :param input_string: the input string to verify. :param validators: the list of validators. :raises InvalidValidator if the list of validators does not provide a valid InputValidator class. :return: a boolean repre...
[ "Validate", "the", "given", "input", "string", "against", "the", "specified", "list", "of", "validators", ".", ":", "param", "input_string", ":", "the", "input", "string", "to", "verify", ".", ":", "param", "validators", ":", "the", "list", "of", "validators...
train
https://github.com/aegirhall/console-menu/blob/1a28959d6f1dd6ac79c87b11efd8529d05532422/consolemenu/prompt_utils.py#L233-L260
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" ]
train
https://github.com/aegirhall/console-menu/blob/1a28959d6f1dd6ac79c87b11efd8529d05532422/consolemenu/validators/regex.py#L16-L30
aegirhall/console-menu
consolemenu/multiselect_menu.py
MultiSelectMenu.append_item
def append_item(self, item): """ Add an item to the end of the menu before the exit item. Note that Multi-Select Menus will not allow a SubmenuItem to be added, as multi-select menus are expected to be used only for executing multiple actions. Args: item (:obj:`Menu...
python
def append_item(self, item): """ Add an item to the end of the menu before the exit item. Note that Multi-Select Menus will not allow a SubmenuItem to be added, as multi-select menus are expected to be used only for executing multiple actions. Args: item (:obj:`Menu...
[ "def", "append_item", "(", "self", ",", "item", ")", ":", "if", "isinstance", "(", "item", ",", "SubmenuItem", ")", ":", "raise", "TypeError", "(", "\"SubmenuItems cannot be added to a MultiSelectMenu\"", ")", "super", "(", "MultiSelectMenu", ",", "self", ")", "...
Add an item to the end of the menu before the exit item. Note that Multi-Select Menus will not allow a SubmenuItem to be added, as multi-select menus are expected to be used only for executing multiple actions. Args: item (:obj:`MenuItem`): The item to be added Raises: ...
[ "Add", "an", "item", "to", "the", "end", "of", "the", "menu", "before", "the", "exit", "item", "." ]
train
https://github.com/aegirhall/console-menu/blob/1a28959d6f1dd6ac79c87b11efd8529d05532422/consolemenu/multiselect_menu.py#L26-L41
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", ")", "# Subtract 1 from each number for its actual index number", ...
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", "." ]
train
https://github.com/aegirhall/console-menu/blob/1a28959d6f1dd6ac79c87b11efd8529d05532422/consolemenu/multiselect_menu.py#L43-L67
aegirhall/console-menu
consolemenu/console_menu.py
ConsoleMenu.selected_item
def selected_item(self): """ :obj:`consolemenu.items.MenuItem`: The item in :attr:`items` that the user most recently selected, or None. """ if self.items and self.selected_option != -1: return self.items[self.current_option] else: return None
python
def selected_item(self): """ :obj:`consolemenu.items.MenuItem`: The item in :attr:`items` that the user most recently selected, or None. """ if self.items and self.selected_option != -1: return self.items[self.current_option] else: return None
[ "def", "selected_item", "(", "self", ")", ":", "if", "self", ".", "items", "and", "self", ".", "selected_option", "!=", "-", "1", ":", "return", "self", ".", "items", "[", "self", ".", "current_option", "]", "else", ":", "return", "None" ]
:obj:`consolemenu.items.MenuItem`: The item in :attr:`items` that the user most recently selected, or None.
[ ":", "obj", ":", "consolemenu", ".", "items", ".", "MenuItem", ":", "The", "item", "in", ":", "attr", ":", "items", "that", "the", "user", "most", "recently", "selected", "or", "None", "." ]
train
https://github.com/aegirhall/console-menu/blob/1a28959d6f1dd6ac79c87b11efd8529d05532422/consolemenu/console_menu.py#L93-L100
aegirhall/console-menu
consolemenu/console_menu.py
ConsoleMenu.append_item
def append_item(self, item): """ Add an item to the end of the menu before the exit item. Args: item (MenuItem): The item to be added. """ did_remove = self.remove_exit() item.menu = self self.items.append(item) if did_remove: sel...
python
def append_item(self, item): """ Add an item to the end of the menu before the exit item. Args: item (MenuItem): The item to be added. """ did_remove = self.remove_exit() item.menu = self self.items.append(item) if did_remove: sel...
[ "def", "append_item", "(", "self", ",", "item", ")", ":", "did_remove", "=", "self", ".", "remove_exit", "(", ")", "item", ".", "menu", "=", "self", "self", ".", "items", ".", "append", "(", "item", ")", "if", "did_remove", ":", "self", ".", "add_exi...
Add an item to the end of the menu before the exit item. Args: item (MenuItem): The item to be added.
[ "Add", "an", "item", "to", "the", "end", "of", "the", "menu", "before", "the", "exit", "item", "." ]
train
https://github.com/aegirhall/console-menu/blob/1a28959d6f1dd6ac79c87b11efd8529d05532422/consolemenu/console_menu.py#L102-L114
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", "." ]
train
https://github.com/aegirhall/console-menu/blob/1a28959d6f1dd6ac79c87b11efd8529d05532422/consolemenu/console_menu.py#L116-L130
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", "." ]
train
https://github.com/aegirhall/console-menu/blob/1a28959d6f1dd6ac79c87b11efd8529d05532422/consolemenu/console_menu.py#L144-L155
aegirhall/console-menu
consolemenu/console_menu.py
ConsoleMenu.start
def start(self, show_exit_option=None): """ Start the menu in a new thread and allow the user to interact with it. The thread is a daemon, so :meth:`join()<consolemenu.ConsoleMenu.join>` should be called if there's a possibility that the main thread will exit before the menu is done ...
python
def start(self, show_exit_option=None): """ Start the menu in a new thread and allow the user to interact with it. The thread is a daemon, so :meth:`join()<consolemenu.ConsoleMenu.join>` should be called if there's a possibility that the main thread will exit before the menu is done ...
[ "def", "start", "(", "self", ",", "show_exit_option", "=", "None", ")", ":", "self", ".", "previous_active_menu", "=", "ConsoleMenu", ".", "currently_active_menu", "ConsoleMenu", ".", "currently_active_menu", "=", "None", "self", ".", "should_exit", "=", "False", ...
Start the menu in a new thread and allow the user to interact with it. The thread is a daemon, so :meth:`join()<consolemenu.ConsoleMenu.join>` should be called if there's a possibility that the main thread will exit before the menu is done Args: show_exit_option (bool): Specify whet...
[ "Start", "the", "menu", "in", "a", "new", "thread", "and", "allow", "the", "user", "to", "interact", "with", "it", ".", "The", "thread", "is", "a", "daemon", "so", ":", "meth", ":", "join", "()", "<consolemenu", ".", "ConsoleMenu", ".", "join", ">", ...
train
https://github.com/aegirhall/console-menu/blob/1a28959d6f1dd6ac79c87b11efd8529d05532422/consolemenu/console_menu.py#L172-L202
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", "." ]
train
https://github.com/aegirhall/console-menu/blob/1a28959d6f1dd6ac79c87b11efd8529d05532422/consolemenu/console_menu.py#L226-L231
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" ]
train
https://github.com/aegirhall/console-menu/blob/1a28959d6f1dd6ac79c87b11efd8529d05532422/consolemenu/console_menu.py#L297-L311
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" ]
train
https://github.com/aegirhall/console-menu/blob/1a28959d6f1dd6ac79c87b11efd8529d05532422/consolemenu/console_menu.py#L323-L331
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" ]
train
https://github.com/aegirhall/console-menu/blob/1a28959d6f1dd6ac79c87b11efd8529d05532422/consolemenu/console_menu.py#L333-L341
aegirhall/console-menu
consolemenu/console_menu.py
ExitItem.show
def show(self, index): """ This class overrides this method """ if self.menu and self.menu.parent: self.text = "Return to %s" % self.menu.parent.title # Check if menu title ends with menu. (Some menus will include Menu in the name). if not self.text.st...
python
def show(self, index): """ This class overrides this method """ if self.menu and self.menu.parent: self.text = "Return to %s" % self.menu.parent.title # Check if menu title ends with menu. (Some menus will include Menu in the name). if not self.text.st...
[ "def", "show", "(", "self", ",", "index", ")", ":", "if", "self", ".", "menu", "and", "self", ".", "menu", ".", "parent", ":", "self", ".", "text", "=", "\"Return to %s\"", "%", "self", ".", "menu", ".", "parent", ".", "title", "# Check if menu title e...
This class overrides this method
[ "This", "class", "overrides", "this", "method" ]
train
https://github.com/aegirhall/console-menu/blob/1a28959d6f1dd6ac79c87b11efd8529d05532422/consolemenu/console_menu.py#L446-L457
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", "." ]
train
https://github.com/aegirhall/console-menu/blob/1a28959d6f1dd6ac79c87b11efd8529d05532422/consolemenu/selection_menu.py#L29-L50
timothyb0912/pylogit
pylogit/choice_tools.py
get_dataframe_from_data
def get_dataframe_from_data(data): """ Parameters ---------- data : string or pandas dataframe. If string, data should be an absolute or relative path to a CSV file containing the long format data for this choice model. Note long format has one row per available alternative for e...
python
def get_dataframe_from_data(data): """ Parameters ---------- data : string or pandas dataframe. If string, data should be an absolute or relative path to a CSV file containing the long format data for this choice model. Note long format has one row per available alternative for e...
[ "def", "get_dataframe_from_data", "(", "data", ")", ":", "if", "isinstance", "(", "data", ",", "str", ")", ":", "if", "data", ".", "endswith", "(", "\".csv\"", ")", ":", "dataframe", "=", "pd", ".", "read_csv", "(", "data", ")", "else", ":", "msg_1", ...
Parameters ---------- data : string or pandas dataframe. If string, data should be an absolute or relative path to a CSV file containing the long format data for this choice model. Note long format has one row per available alternative for each observation. If pandas dataframe, t...
[ "Parameters", "----------", "data", ":", "string", "or", "pandas", "dataframe", ".", "If", "string", "data", "should", "be", "an", "absolute", "or", "relative", "path", "to", "a", "CSV", "file", "containing", "the", "long", "format", "data", "for", "this", ...
train
https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/choice_tools.py#L23-L52
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", "." ]
train
https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/choice_tools.py#L73-L83
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", "." ]
train
https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/choice_tools.py#L86-L96
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", "." ]
train
https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/choice_tools.py#L99-L110
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'", ")", ":", "# Make sure columns is an iterable", "assert", "isinstance", "(", "columns", ",", "Iterable", ")", "# Make sure datafr...
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", "." ]
train
https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/choice_tools.py#L113-L156
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", "." ]
train
https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/choice_tools.py#L159-L194
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", "." ]
train
https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/choice_tools.py#L197-L217
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", ")", ":", "# Make sure specification is an OrderedDict", "try", ":", "assert", "isinstance", "(", "specification", ",", "OrderedDict", ")", "except", "AssertionError", ":", "raise",...
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", "." ]
train
https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/choice_tools.py#L220-L264
timothyb0912/pylogit
pylogit/choice_tools.py
check_type_and_values_of_specification_dict
def check_type_and_values_of_specification_dict(specification_dict, unique_alternatives): """ Verifies that the values of specification_dict have the correct type, have the correct structure, and have valid values (i.e. are actually in the set of possible ...
python
def check_type_and_values_of_specification_dict(specification_dict, unique_alternatives): """ Verifies that the values of specification_dict have the correct type, have the correct structure, and have valid values (i.e. are actually in the set of possible ...
[ "def", "check_type_and_values_of_specification_dict", "(", "specification_dict", ",", "unique_alternatives", ")", ":", "for", "key", "in", "specification_dict", ":", "specification", "=", "specification_dict", "[", "key", "]", "if", "isinstance", "(", "specification", "...
Verifies that the values of specification_dict have the correct type, have the correct structure, and have valid values (i.e. are actually in the set of possible alternatives). Will raise various errors if / when appropriate. Parameters ---------- specification_dict : OrderedDict. Keys are ...
[ "Verifies", "that", "the", "values", "of", "specification_dict", "have", "the", "correct", "type", "have", "the", "correct", "structure", "and", "have", "valid", "values", "(", "i", ".", "e", ".", "are", "actually", "in", "the", "set", "of", "possible", "a...
train
https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/choice_tools.py#L267-L337
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", "." ]
train
https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/choice_tools.py#L340-L417
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", "." ]
train
https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/choice_tools.py#L420-L463
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",...
train
https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/choice_tools.py#L466-L491
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", "." ]
train
https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/choice_tools.py#L494-L526
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", "." ]
train
https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/choice_tools.py#L529-L560
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", "." ]
train
https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/choice_tools.py#L563-L582
timothyb0912/pylogit
pylogit/choice_tools.py
create_design_matrix
def create_design_matrix(long_form, specification_dict, alt_id_col, names=None): """ Parameters ---------- long_form : pandas dataframe. Contains one row for each available alternative, for each observation. specifica...
python
def create_design_matrix(long_form, specification_dict, alt_id_col, names=None): """ Parameters ---------- long_form : pandas dataframe. Contains one row for each available alternative, for each observation. specifica...
[ "def", "create_design_matrix", "(", "long_form", ",", "specification_dict", ",", "alt_id_col", ",", "names", "=", "None", ")", ":", "##########", "# Check that the arguments meet this functions assumptions.", "# Fail gracefully if the arguments do not meet the function's requirements...
Parameters ---------- long_form : pandas dataframe. Contains one row for each available alternative, for each observation. specification_dict : OrderedDict. Keys are a proper subset of the columns in `long_form_df`. Values are either a list or a single string, `"all_diff"` or `"all_s...
[ "Parameters", "----------", "long_form", ":", "pandas", "dataframe", ".", "Contains", "one", "row", "for", "each", "available", "alternative", "for", "each", "observation", ".", "specification_dict", ":", "OrderedDict", ".", "Keys", "are", "a", "proper", "subset",...
train
https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/choice_tools.py#L585-L715
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", "# Get the indices of the unique IDs in their order of appearanc...
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", "." ]
train
https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/choice_tools.py#L718-L745