repo stringlengths 7 55 | path stringlengths 4 127 | func_name stringlengths 1 88 | original_string stringlengths 75 19.8k | language stringclasses 1
value | code stringlengths 75 19.8k | code_tokens list | docstring stringlengths 3 17.3k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 87 242 | partition stringclasses 1
value |
|---|---|---|---|---|---|---|---|---|---|---|---|
adamreeve/npTDMS | nptdms/tdms.py | fromfile | def fromfile(file, dtype, count, *args, **kwargs):
"""Wrapper around np.fromfile to support any file-like object"""
try:
return np.fromfile(file, dtype=dtype, count=count, *args, **kwargs)
except (TypeError, IOError, UnsupportedOperation):
return np.frombuffer(
file.read(count *... | python | def fromfile(file, dtype, count, *args, **kwargs):
"""Wrapper around np.fromfile to support any file-like object"""
try:
return np.fromfile(file, dtype=dtype, count=count, *args, **kwargs)
except (TypeError, IOError, UnsupportedOperation):
return np.frombuffer(
file.read(count *... | [
"def",
"fromfile",
"(",
"file",
",",
"dtype",
",",
"count",
",",
"*",
"args",
",",
"**",
"kwargs",
")",
":",
"try",
":",
"return",
"np",
".",
"fromfile",
"(",
"file",
",",
"dtype",
"=",
"dtype",
",",
"count",
"=",
"count",
",",
"*",
"args",
",",
... | Wrapper around np.fromfile to support any file-like object | [
"Wrapper",
"around",
"np",
".",
"fromfile",
"to",
"support",
"any",
"file",
"-",
"like",
"object"
] | d7d6632d4ebc2e78ed941477c2f1c56bd7493d74 | https://github.com/adamreeve/npTDMS/blob/d7d6632d4ebc2e78ed941477c2f1c56bd7493d74/nptdms/tdms.py#L43-L51 | train |
adamreeve/npTDMS | nptdms/tdms.py | read_property | def read_property(f, endianness="<"):
""" Read a property from a segment's metadata """
prop_name = types.String.read(f, endianness)
prop_data_type = types.tds_data_types[types.Uint32.read(f, endianness)]
value = prop_data_type.read(f, endianness)
log.debug("Property %s: %r", prop_name, value)
... | python | def read_property(f, endianness="<"):
""" Read a property from a segment's metadata """
prop_name = types.String.read(f, endianness)
prop_data_type = types.tds_data_types[types.Uint32.read(f, endianness)]
value = prop_data_type.read(f, endianness)
log.debug("Property %s: %r", prop_name, value)
... | [
"def",
"read_property",
"(",
"f",
",",
"endianness",
"=",
"\"<\"",
")",
":",
"prop_name",
"=",
"types",
".",
"String",
".",
"read",
"(",
"f",
",",
"endianness",
")",
"prop_data_type",
"=",
"types",
".",
"tds_data_types",
"[",
"types",
".",
"Uint32",
".",... | Read a property from a segment's metadata | [
"Read",
"a",
"property",
"from",
"a",
"segment",
"s",
"metadata"
] | d7d6632d4ebc2e78ed941477c2f1c56bd7493d74 | https://github.com/adamreeve/npTDMS/blob/d7d6632d4ebc2e78ed941477c2f1c56bd7493d74/nptdms/tdms.py#L54-L61 | train |
adamreeve/npTDMS | nptdms/tdms.py | read_string_data | def read_string_data(file, number_values, endianness):
""" Read string raw data
This is stored as an array of offsets
followed by the contiguous string data.
"""
offsets = [0]
for i in range(number_values):
offsets.append(types.Uint32.read(file, endianness))
strings = []
... | python | def read_string_data(file, number_values, endianness):
""" Read string raw data
This is stored as an array of offsets
followed by the contiguous string data.
"""
offsets = [0]
for i in range(number_values):
offsets.append(types.Uint32.read(file, endianness))
strings = []
... | [
"def",
"read_string_data",
"(",
"file",
",",
"number_values",
",",
"endianness",
")",
":",
"offsets",
"=",
"[",
"0",
"]",
"for",
"i",
"in",
"range",
"(",
"number_values",
")",
":",
"offsets",
".",
"append",
"(",
"types",
".",
"Uint32",
".",
"read",
"("... | Read string raw data
This is stored as an array of offsets
followed by the contiguous string data. | [
"Read",
"string",
"raw",
"data"
] | d7d6632d4ebc2e78ed941477c2f1c56bd7493d74 | https://github.com/adamreeve/npTDMS/blob/d7d6632d4ebc2e78ed941477c2f1c56bd7493d74/nptdms/tdms.py#L1049-L1062 | train |
adamreeve/npTDMS | nptdms/tdms.py | path_components | def path_components(path):
"""Convert a path into group and channel name components"""
def yield_components(path):
# Iterate over each character and the next character
chars = zip_longest(path, path[1:])
try:
# Iterate over components
while True:
... | python | def path_components(path):
"""Convert a path into group and channel name components"""
def yield_components(path):
# Iterate over each character and the next character
chars = zip_longest(path, path[1:])
try:
# Iterate over components
while True:
... | [
"def",
"path_components",
"(",
"path",
")",
":",
"def",
"yield_components",
"(",
"path",
")",
":",
"chars",
"=",
"zip_longest",
"(",
"path",
",",
"path",
"[",
"1",
":",
"]",
")",
"try",
":",
"while",
"True",
":",
"c",
",",
"n",
"=",
"next",
"(",
... | Convert a path into group and channel name components | [
"Convert",
"a",
"path",
"into",
"group",
"and",
"channel",
"name",
"components"
] | d7d6632d4ebc2e78ed941477c2f1c56bd7493d74 | https://github.com/adamreeve/npTDMS/blob/d7d6632d4ebc2e78ed941477c2f1c56bd7493d74/nptdms/tdms.py#L1065-L1098 | train |
adamreeve/npTDMS | nptdms/tdms.py | TdmsFile.object | def object(self, *path):
"""Get a TDMS object from the file
:param path: The object group and channel. Providing no channel
returns a group object, and providing no channel or group
will return the root object.
:rtype: :class:`TdmsObject`
For example, to get the... | python | def object(self, *path):
"""Get a TDMS object from the file
:param path: The object group and channel. Providing no channel
returns a group object, and providing no channel or group
will return the root object.
:rtype: :class:`TdmsObject`
For example, to get the... | [
"def",
"object",
"(",
"self",
",",
"*",
"path",
")",
":",
"object_path",
"=",
"self",
".",
"_path",
"(",
"*",
"path",
")",
"try",
":",
"return",
"self",
".",
"objects",
"[",
"object_path",
"]",
"except",
"KeyError",
":",
"raise",
"KeyError",
"(",
"\"... | Get a TDMS object from the file
:param path: The object group and channel. Providing no channel
returns a group object, and providing no channel or group
will return the root object.
:rtype: :class:`TdmsObject`
For example, to get the root object::
object()... | [
"Get",
"a",
"TDMS",
"object",
"from",
"the",
"file"
] | d7d6632d4ebc2e78ed941477c2f1c56bd7493d74 | https://github.com/adamreeve/npTDMS/blob/d7d6632d4ebc2e78ed941477c2f1c56bd7493d74/nptdms/tdms.py#L132-L157 | train |
adamreeve/npTDMS | nptdms/tdms.py | TdmsFile.groups | def groups(self):
"""Return the names of groups in the file
Note that there is not necessarily a TDMS object associated with
each group name.
:rtype: List of strings.
"""
# Split paths into components and take the first (group) component.
object_paths = (
... | python | def groups(self):
"""Return the names of groups in the file
Note that there is not necessarily a TDMS object associated with
each group name.
:rtype: List of strings.
"""
# Split paths into components and take the first (group) component.
object_paths = (
... | [
"def",
"groups",
"(",
"self",
")",
":",
"object_paths",
"=",
"(",
"path_components",
"(",
"path",
")",
"for",
"path",
"in",
"self",
".",
"objects",
")",
"group_names",
"=",
"(",
"path",
"[",
"0",
"]",
"for",
"path",
"in",
"object_paths",
"if",
"len",
... | Return the names of groups in the file
Note that there is not necessarily a TDMS object associated with
each group name.
:rtype: List of strings. | [
"Return",
"the",
"names",
"of",
"groups",
"in",
"the",
"file"
] | d7d6632d4ebc2e78ed941477c2f1c56bd7493d74 | https://github.com/adamreeve/npTDMS/blob/d7d6632d4ebc2e78ed941477c2f1c56bd7493d74/nptdms/tdms.py#L159-L180 | train |
adamreeve/npTDMS | nptdms/tdms.py | TdmsFile.group_channels | def group_channels(self, group):
"""Returns a list of channel objects for the given group
:param group: Name of the group to get channels for.
:rtype: List of :class:`TdmsObject` objects.
"""
path = self._path(group)
return [
self.objects[p]
for... | python | def group_channels(self, group):
"""Returns a list of channel objects for the given group
:param group: Name of the group to get channels for.
:rtype: List of :class:`TdmsObject` objects.
"""
path = self._path(group)
return [
self.objects[p]
for... | [
"def",
"group_channels",
"(",
"self",
",",
"group",
")",
":",
"path",
"=",
"self",
".",
"_path",
"(",
"group",
")",
"return",
"[",
"self",
".",
"objects",
"[",
"p",
"]",
"for",
"p",
"in",
"self",
".",
"objects",
"if",
"p",
".",
"startswith",
"(",
... | Returns a list of channel objects for the given group
:param group: Name of the group to get channels for.
:rtype: List of :class:`TdmsObject` objects. | [
"Returns",
"a",
"list",
"of",
"channel",
"objects",
"for",
"the",
"given",
"group"
] | d7d6632d4ebc2e78ed941477c2f1c56bd7493d74 | https://github.com/adamreeve/npTDMS/blob/d7d6632d4ebc2e78ed941477c2f1c56bd7493d74/nptdms/tdms.py#L182-L194 | train |
adamreeve/npTDMS | nptdms/tdms.py | TdmsFile.as_dataframe | def as_dataframe(self, time_index=False, absolute_time=False):
"""
Converts the TDMS file to a DataFrame
:param time_index: Whether to include a time index for the dataframe.
:param absolute_time: If time_index is true, whether the time index
values are absolute times or rel... | python | def as_dataframe(self, time_index=False, absolute_time=False):
"""
Converts the TDMS file to a DataFrame
:param time_index: Whether to include a time index for the dataframe.
:param absolute_time: If time_index is true, whether the time index
values are absolute times or rel... | [
"def",
"as_dataframe",
"(",
"self",
",",
"time_index",
"=",
"False",
",",
"absolute_time",
"=",
"False",
")",
":",
"import",
"pandas",
"as",
"pd",
"dataframe_dict",
"=",
"OrderedDict",
"(",
")",
"for",
"key",
",",
"value",
"in",
"self",
".",
"objects",
"... | Converts the TDMS file to a DataFrame
:param time_index: Whether to include a time index for the dataframe.
:param absolute_time: If time_index is true, whether the time index
values are absolute times or relative to the start time.
:return: The full TDMS file data.
:rtype: ... | [
"Converts",
"the",
"TDMS",
"file",
"to",
"a",
"DataFrame"
] | d7d6632d4ebc2e78ed941477c2f1c56bd7493d74 | https://github.com/adamreeve/npTDMS/blob/d7d6632d4ebc2e78ed941477c2f1c56bd7493d74/nptdms/tdms.py#L208-L226 | train |
adamreeve/npTDMS | nptdms/tdms.py | TdmsFile.as_hdf | def as_hdf(self, filepath, mode='w', group='/'):
"""
Converts the TDMS file into an HDF5 file
:param filepath: The path of the HDF5 file you want to write to.
:param mode: The write mode of the HDF5 file. This can be w, a ...
:param group: A group in the HDF5 file that will cont... | python | def as_hdf(self, filepath, mode='w', group='/'):
"""
Converts the TDMS file into an HDF5 file
:param filepath: The path of the HDF5 file you want to write to.
:param mode: The write mode of the HDF5 file. This can be w, a ...
:param group: A group in the HDF5 file that will cont... | [
"def",
"as_hdf",
"(",
"self",
",",
"filepath",
",",
"mode",
"=",
"'w'",
",",
"group",
"=",
"'/'",
")",
":",
"import",
"h5py",
"h5file",
"=",
"h5py",
".",
"File",
"(",
"filepath",
",",
"mode",
")",
"container_group",
"=",
"None",
"if",
"group",
"in",
... | Converts the TDMS file into an HDF5 file
:param filepath: The path of the HDF5 file you want to write to.
:param mode: The write mode of the HDF5 file. This can be w, a ...
:param group: A group in the HDF5 file that will contain the TDMS data. | [
"Converts",
"the",
"TDMS",
"file",
"into",
"an",
"HDF5",
"file"
] | d7d6632d4ebc2e78ed941477c2f1c56bd7493d74 | https://github.com/adamreeve/npTDMS/blob/d7d6632d4ebc2e78ed941477c2f1c56bd7493d74/nptdms/tdms.py#L228-L284 | train |
adamreeve/npTDMS | nptdms/tdms.py | _TdmsSegment.read_metadata | def read_metadata(self, f, objects, previous_segment=None):
"""Read segment metadata section and update object information"""
if not self.toc["kTocMetaData"]:
try:
self.ordered_objects = previous_segment.ordered_objects
except AttributeError:
rais... | python | def read_metadata(self, f, objects, previous_segment=None):
"""Read segment metadata section and update object information"""
if not self.toc["kTocMetaData"]:
try:
self.ordered_objects = previous_segment.ordered_objects
except AttributeError:
rais... | [
"def",
"read_metadata",
"(",
"self",
",",
"f",
",",
"objects",
",",
"previous_segment",
"=",
"None",
")",
":",
"if",
"not",
"self",
".",
"toc",
"[",
"\"kTocMetaData\"",
"]",
":",
"try",
":",
"self",
".",
"ordered_objects",
"=",
"previous_segment",
".",
"... | Read segment metadata section and update object information | [
"Read",
"segment",
"metadata",
"section",
"and",
"update",
"object",
"information"
] | d7d6632d4ebc2e78ed941477c2f1c56bd7493d74 | https://github.com/adamreeve/npTDMS/blob/d7d6632d4ebc2e78ed941477c2f1c56bd7493d74/nptdms/tdms.py#L359-L423 | train |
adamreeve/npTDMS | nptdms/tdms.py | _TdmsSegment.calculate_chunks | def calculate_chunks(self):
"""
Work out the number of chunks the data is in, for cases
where the meta data doesn't change at all so there is no
lead in.
Also increments the number of values for objects in this
segment, based on the number of chunks.
"""
... | python | def calculate_chunks(self):
"""
Work out the number of chunks the data is in, for cases
where the meta data doesn't change at all so there is no
lead in.
Also increments the number of values for objects in this
segment, based on the number of chunks.
"""
... | [
"def",
"calculate_chunks",
"(",
"self",
")",
":",
"if",
"self",
".",
"toc",
"[",
"'kTocDAQmxRawData'",
"]",
":",
"try",
":",
"data_size",
"=",
"next",
"(",
"o",
".",
"number_values",
"*",
"o",
".",
"raw_data_width",
"for",
"o",
"in",
"self",
".",
"orde... | Work out the number of chunks the data is in, for cases
where the meta data doesn't change at all so there is no
lead in.
Also increments the number of values for objects in this
segment, based on the number of chunks. | [
"Work",
"out",
"the",
"number",
"of",
"chunks",
"the",
"data",
"is",
"in",
"for",
"cases",
"where",
"the",
"meta",
"data",
"doesn",
"t",
"change",
"at",
"all",
"so",
"there",
"is",
"no",
"lead",
"in",
"."
] | d7d6632d4ebc2e78ed941477c2f1c56bd7493d74 | https://github.com/adamreeve/npTDMS/blob/d7d6632d4ebc2e78ed941477c2f1c56bd7493d74/nptdms/tdms.py#L425-L485 | train |
adamreeve/npTDMS | nptdms/tdms.py | _TdmsSegment.read_raw_data | def read_raw_data(self, f):
"""Read signal data from file"""
if not self.toc["kTocRawData"]:
return
f.seek(self.data_position)
total_data_size = self.next_segment_offset - self.raw_data_offset
log.debug(
"Reading %d bytes of data at %d in %d chunks" %
... | python | def read_raw_data(self, f):
"""Read signal data from file"""
if not self.toc["kTocRawData"]:
return
f.seek(self.data_position)
total_data_size = self.next_segment_offset - self.raw_data_offset
log.debug(
"Reading %d bytes of data at %d in %d chunks" %
... | [
"def",
"read_raw_data",
"(",
"self",
",",
"f",
")",
":",
"if",
"not",
"self",
".",
"toc",
"[",
"\"kTocRawData\"",
"]",
":",
"return",
"f",
".",
"seek",
"(",
"self",
".",
"data_position",
")",
"total_data_size",
"=",
"self",
".",
"next_segment_offset",
"-... | Read signal data from file | [
"Read",
"signal",
"data",
"from",
"file"
] | d7d6632d4ebc2e78ed941477c2f1c56bd7493d74 | https://github.com/adamreeve/npTDMS/blob/d7d6632d4ebc2e78ed941477c2f1c56bd7493d74/nptdms/tdms.py#L487-L532 | train |
adamreeve/npTDMS | nptdms/tdms.py | _TdmsSegment._read_interleaved_numpy | def _read_interleaved_numpy(self, f, data_objects):
"""Read interleaved data where all channels have a numpy type"""
log.debug("Reading interleaved data all at once")
# Read all data into 1 byte unsigned ints first
all_channel_bytes = data_objects[0].raw_data_width
if all_channe... | python | def _read_interleaved_numpy(self, f, data_objects):
"""Read interleaved data where all channels have a numpy type"""
log.debug("Reading interleaved data all at once")
# Read all data into 1 byte unsigned ints first
all_channel_bytes = data_objects[0].raw_data_width
if all_channe... | [
"def",
"_read_interleaved_numpy",
"(",
"self",
",",
"f",
",",
"data_objects",
")",
":",
"log",
".",
"debug",
"(",
"\"Reading interleaved data all at once\"",
")",
"all_channel_bytes",
"=",
"data_objects",
"[",
"0",
"]",
".",
"raw_data_width",
"if",
"all_channel_byte... | Read interleaved data where all channels have a numpy type | [
"Read",
"interleaved",
"data",
"where",
"all",
"channels",
"have",
"a",
"numpy",
"type"
] | d7d6632d4ebc2e78ed941477c2f1c56bd7493d74 | https://github.com/adamreeve/npTDMS/blob/d7d6632d4ebc2e78ed941477c2f1c56bd7493d74/nptdms/tdms.py#L534-L562 | train |
adamreeve/npTDMS | nptdms/tdms.py | _TdmsSegment._read_interleaved | def _read_interleaved(self, f, data_objects):
"""Read interleaved data that doesn't have a numpy type"""
log.debug("Reading interleaved data point by point")
object_data = {}
points_added = {}
for obj in data_objects:
object_data[obj.path] = obj._new_segment_data()
... | python | def _read_interleaved(self, f, data_objects):
"""Read interleaved data that doesn't have a numpy type"""
log.debug("Reading interleaved data point by point")
object_data = {}
points_added = {}
for obj in data_objects:
object_data[obj.path] = obj._new_segment_data()
... | [
"def",
"_read_interleaved",
"(",
"self",
",",
"f",
",",
"data_objects",
")",
":",
"log",
".",
"debug",
"(",
"\"Reading interleaved data point by point\"",
")",
"object_data",
"=",
"{",
"}",
"points_added",
"=",
"{",
"}",
"for",
"obj",
"in",
"data_objects",
":"... | Read interleaved data that doesn't have a numpy type | [
"Read",
"interleaved",
"data",
"that",
"doesn",
"t",
"have",
"a",
"numpy",
"type"
] | d7d6632d4ebc2e78ed941477c2f1c56bd7493d74 | https://github.com/adamreeve/npTDMS/blob/d7d6632d4ebc2e78ed941477c2f1c56bd7493d74/nptdms/tdms.py#L564-L581 | train |
adamreeve/npTDMS | nptdms/tdms.py | TdmsObject.time_track | def time_track(self, absolute_time=False, accuracy='ns'):
"""Return an array of time or the independent variable for this channel
This depends on the object having the wf_increment
and wf_start_offset properties defined.
Note that wf_start_offset is usually zero for time-series data.
... | python | def time_track(self, absolute_time=False, accuracy='ns'):
"""Return an array of time or the independent variable for this channel
This depends on the object having the wf_increment
and wf_start_offset properties defined.
Note that wf_start_offset is usually zero for time-series data.
... | [
"def",
"time_track",
"(",
"self",
",",
"absolute_time",
"=",
"False",
",",
"accuracy",
"=",
"'ns'",
")",
":",
"try",
":",
"increment",
"=",
"self",
".",
"property",
"(",
"'wf_increment'",
")",
"offset",
"=",
"self",
".",
"property",
"(",
"'wf_start_offset'... | Return an array of time or the independent variable for this channel
This depends on the object having the wf_increment
and wf_start_offset properties defined.
Note that wf_start_offset is usually zero for time-series data.
If you have time-series data channels with different start time... | [
"Return",
"an",
"array",
"of",
"time",
"or",
"the",
"independent",
"variable",
"for",
"this",
"channel"
] | d7d6632d4ebc2e78ed941477c2f1c56bd7493d74 | https://github.com/adamreeve/npTDMS/blob/d7d6632d4ebc2e78ed941477c2f1c56bd7493d74/nptdms/tdms.py#L645-L706 | train |
adamreeve/npTDMS | nptdms/tdms.py | TdmsObject._initialise_data | def _initialise_data(self, memmap_dir=None):
"""Initialise data array to zeros"""
if self.number_values == 0:
pass
elif self.data_type.nptype is None:
self._data = []
else:
if memmap_dir:
memmap_file = tempfile.NamedTemporaryFile(
... | python | def _initialise_data(self, memmap_dir=None):
"""Initialise data array to zeros"""
if self.number_values == 0:
pass
elif self.data_type.nptype is None:
self._data = []
else:
if memmap_dir:
memmap_file = tempfile.NamedTemporaryFile(
... | [
"def",
"_initialise_data",
"(",
"self",
",",
"memmap_dir",
"=",
"None",
")",
":",
"if",
"self",
".",
"number_values",
"==",
"0",
":",
"pass",
"elif",
"self",
".",
"data_type",
".",
"nptype",
"is",
"None",
":",
"self",
".",
"_data",
"=",
"[",
"]",
"el... | Initialise data array to zeros | [
"Initialise",
"data",
"array",
"to",
"zeros"
] | d7d6632d4ebc2e78ed941477c2f1c56bd7493d74 | https://github.com/adamreeve/npTDMS/blob/d7d6632d4ebc2e78ed941477c2f1c56bd7493d74/nptdms/tdms.py#L708-L732 | train |
adamreeve/npTDMS | nptdms/tdms.py | TdmsObject._update_data | def _update_data(self, new_data):
"""Update the object data with a new array of data"""
log.debug("Adding %d data points to data for %s" %
(len(new_data), self.path))
if self._data is None:
self._data = new_data
else:
if self.data_type.nptype is... | python | def _update_data(self, new_data):
"""Update the object data with a new array of data"""
log.debug("Adding %d data points to data for %s" %
(len(new_data), self.path))
if self._data is None:
self._data = new_data
else:
if self.data_type.nptype is... | [
"def",
"_update_data",
"(",
"self",
",",
"new_data",
")",
":",
"log",
".",
"debug",
"(",
"\"Adding %d data points to data for %s\"",
"%",
"(",
"len",
"(",
"new_data",
")",
",",
"self",
".",
"path",
")",
")",
"if",
"self",
".",
"_data",
"is",
"None",
":",... | Update the object data with a new array of data | [
"Update",
"the",
"object",
"data",
"with",
"a",
"new",
"array",
"of",
"data"
] | d7d6632d4ebc2e78ed941477c2f1c56bd7493d74 | https://github.com/adamreeve/npTDMS/blob/d7d6632d4ebc2e78ed941477c2f1c56bd7493d74/nptdms/tdms.py#L734-L749 | train |
adamreeve/npTDMS | nptdms/tdms.py | TdmsObject.as_dataframe | def as_dataframe(self, absolute_time=False):
"""
Converts the TDMS object to a DataFrame
:param absolute_time: Whether times should be absolute rather than
relative to the start time.
:return: The TDMS object data.
:rtype: pandas.DataFrame
"""
import... | python | def as_dataframe(self, absolute_time=False):
"""
Converts the TDMS object to a DataFrame
:param absolute_time: Whether times should be absolute rather than
relative to the start time.
:return: The TDMS object data.
:rtype: pandas.DataFrame
"""
import... | [
"def",
"as_dataframe",
"(",
"self",
",",
"absolute_time",
"=",
"False",
")",
":",
"import",
"pandas",
"as",
"pd",
"try",
":",
"time",
"=",
"self",
".",
"time_track",
"(",
"absolute_time",
")",
"except",
"KeyError",
":",
"time",
"=",
"None",
"if",
"self",... | Converts the TDMS object to a DataFrame
:param absolute_time: Whether times should be absolute rather than
relative to the start time.
:return: The TDMS object data.
:rtype: pandas.DataFrame | [
"Converts",
"the",
"TDMS",
"object",
"to",
"a",
"DataFrame"
] | d7d6632d4ebc2e78ed941477c2f1c56bd7493d74 | https://github.com/adamreeve/npTDMS/blob/d7d6632d4ebc2e78ed941477c2f1c56bd7493d74/nptdms/tdms.py#L751-L774 | train |
adamreeve/npTDMS | nptdms/tdms.py | TdmsObject.data | def data(self):
"""
NumPy array containing data if there is data for this object,
otherwise None.
"""
if self._data is None:
# self._data is None if data segment is empty
return np.empty((0, 1))
if self._data_scaled is None:
scale = sca... | python | def data(self):
"""
NumPy array containing data if there is data for this object,
otherwise None.
"""
if self._data is None:
# self._data is None if data segment is empty
return np.empty((0, 1))
if self._data_scaled is None:
scale = sca... | [
"def",
"data",
"(",
"self",
")",
":",
"if",
"self",
".",
"_data",
"is",
"None",
":",
"return",
"np",
".",
"empty",
"(",
"(",
"0",
",",
"1",
")",
")",
"if",
"self",
".",
"_data_scaled",
"is",
"None",
":",
"scale",
"=",
"scaling",
".",
"get_scaling... | NumPy array containing data if there is data for this object,
otherwise None. | [
"NumPy",
"array",
"containing",
"data",
"if",
"there",
"is",
"data",
"for",
"this",
"object",
"otherwise",
"None",
"."
] | d7d6632d4ebc2e78ed941477c2f1c56bd7493d74 | https://github.com/adamreeve/npTDMS/blob/d7d6632d4ebc2e78ed941477c2f1c56bd7493d74/nptdms/tdms.py#L777-L792 | train |
adamreeve/npTDMS | nptdms/tdms.py | _TdmsmxDAQMetadata._read_metadata | def _read_metadata(self, f, endianness):
"""
Read the metadata for a DAQmx raw segment. This is the raw
DAQmx-specific portion of the raw data index.
"""
self.data_type = types.tds_data_types[0xFFFFFFFF]
self.dimension = types.Uint32.read(f, endianness)
# In TDMS... | python | def _read_metadata(self, f, endianness):
"""
Read the metadata for a DAQmx raw segment. This is the raw
DAQmx-specific portion of the raw data index.
"""
self.data_type = types.tds_data_types[0xFFFFFFFF]
self.dimension = types.Uint32.read(f, endianness)
# In TDMS... | [
"def",
"_read_metadata",
"(",
"self",
",",
"f",
",",
"endianness",
")",
":",
"self",
".",
"data_type",
"=",
"types",
".",
"tds_data_types",
"[",
"0xFFFFFFFF",
"]",
"self",
".",
"dimension",
"=",
"types",
".",
"Uint32",
".",
"read",
"(",
"f",
",",
"endi... | Read the metadata for a DAQmx raw segment. This is the raw
DAQmx-specific portion of the raw data index. | [
"Read",
"the",
"metadata",
"for",
"a",
"DAQmx",
"raw",
"segment",
".",
"This",
"is",
"the",
"raw",
"DAQmx",
"-",
"specific",
"portion",
"of",
"the",
"raw",
"data",
"index",
"."
] | d7d6632d4ebc2e78ed941477c2f1c56bd7493d74 | https://github.com/adamreeve/npTDMS/blob/d7d6632d4ebc2e78ed941477c2f1c56bd7493d74/nptdms/tdms.py#L832-L869 | train |
adamreeve/npTDMS | nptdms/tdms.py | _TdmsSegmentObject._read_metadata | def _read_metadata(self, f):
"""Read object metadata and update object information"""
raw_data_index = types.Uint32.read(f, self.endianness)
log.debug("Reading metadata for object %s", self.tdms_object.path)
# Object has no data in this segment
if raw_data_index == 0xFFFFFFFF:... | python | def _read_metadata(self, f):
"""Read object metadata and update object information"""
raw_data_index = types.Uint32.read(f, self.endianness)
log.debug("Reading metadata for object %s", self.tdms_object.path)
# Object has no data in this segment
if raw_data_index == 0xFFFFFFFF:... | [
"def",
"_read_metadata",
"(",
"self",
",",
"f",
")",
":",
"raw_data_index",
"=",
"types",
".",
"Uint32",
".",
"read",
"(",
"f",
",",
"self",
".",
"endianness",
")",
"log",
".",
"debug",
"(",
"\"Reading metadata for object %s\"",
",",
"self",
".",
"tdms_obj... | Read object metadata and update object information | [
"Read",
"object",
"metadata",
"and",
"update",
"object",
"information"
] | d7d6632d4ebc2e78ed941477c2f1c56bd7493d74 | https://github.com/adamreeve/npTDMS/blob/d7d6632d4ebc2e78ed941477c2f1c56bd7493d74/nptdms/tdms.py#L919-L1011 | train |
adamreeve/npTDMS | nptdms/tdms.py | _TdmsSegmentObject._read_value | def _read_value(self, file):
"""Read a single value from the given file"""
if self.data_type.nptype is not None:
dtype = (np.dtype(self.data_type.nptype).newbyteorder(
self.endianness))
return fromfile(file, dtype=dtype, count=1)
return self.data_type.rea... | python | def _read_value(self, file):
"""Read a single value from the given file"""
if self.data_type.nptype is not None:
dtype = (np.dtype(self.data_type.nptype).newbyteorder(
self.endianness))
return fromfile(file, dtype=dtype, count=1)
return self.data_type.rea... | [
"def",
"_read_value",
"(",
"self",
",",
"file",
")",
":",
"if",
"self",
".",
"data_type",
".",
"nptype",
"is",
"not",
"None",
":",
"dtype",
"=",
"(",
"np",
".",
"dtype",
"(",
"self",
".",
"data_type",
".",
"nptype",
")",
".",
"newbyteorder",
"(",
"... | Read a single value from the given file | [
"Read",
"a",
"single",
"value",
"from",
"the",
"given",
"file"
] | d7d6632d4ebc2e78ed941477c2f1c56bd7493d74 | https://github.com/adamreeve/npTDMS/blob/d7d6632d4ebc2e78ed941477c2f1c56bd7493d74/nptdms/tdms.py#L1017-L1024 | train |
adamreeve/npTDMS | nptdms/tdms.py | _TdmsSegmentObject._read_values | def _read_values(self, file, number_values):
"""Read all values for this object from a contiguous segment"""
if self.data_type.nptype is not None:
dtype = (np.dtype(self.data_type.nptype).newbyteorder(
self.endianness))
return fromfile(file, dtype=dtype, count=nu... | python | def _read_values(self, file, number_values):
"""Read all values for this object from a contiguous segment"""
if self.data_type.nptype is not None:
dtype = (np.dtype(self.data_type.nptype).newbyteorder(
self.endianness))
return fromfile(file, dtype=dtype, count=nu... | [
"def",
"_read_values",
"(",
"self",
",",
"file",
",",
"number_values",
")",
":",
"if",
"self",
".",
"data_type",
".",
"nptype",
"is",
"not",
"None",
":",
"dtype",
"=",
"(",
"np",
".",
"dtype",
"(",
"self",
".",
"data_type",
".",
"nptype",
")",
".",
... | Read all values for this object from a contiguous segment | [
"Read",
"all",
"values",
"for",
"this",
"object",
"from",
"a",
"contiguous",
"segment"
] | d7d6632d4ebc2e78ed941477c2f1c56bd7493d74 | https://github.com/adamreeve/npTDMS/blob/d7d6632d4ebc2e78ed941477c2f1c56bd7493d74/nptdms/tdms.py#L1026-L1038 | train |
adamreeve/npTDMS | nptdms/tdms.py | _TdmsSegmentObject._new_segment_data | def _new_segment_data(self):
"""Return a new array to read the data of the current section into"""
if self.data_type.nptype is not None:
return np.zeros(self.number_values, dtype=self.data_type.nptype)
else:
return [None] * self.number_values | python | def _new_segment_data(self):
"""Return a new array to read the data of the current section into"""
if self.data_type.nptype is not None:
return np.zeros(self.number_values, dtype=self.data_type.nptype)
else:
return [None] * self.number_values | [
"def",
"_new_segment_data",
"(",
"self",
")",
":",
"if",
"self",
".",
"data_type",
".",
"nptype",
"is",
"not",
"None",
":",
"return",
"np",
".",
"zeros",
"(",
"self",
".",
"number_values",
",",
"dtype",
"=",
"self",
".",
"data_type",
".",
"nptype",
")"... | Return a new array to read the data of the current section into | [
"Return",
"a",
"new",
"array",
"to",
"read",
"the",
"data",
"of",
"the",
"current",
"section",
"into"
] | d7d6632d4ebc2e78ed941477c2f1c56bd7493d74 | https://github.com/adamreeve/npTDMS/blob/d7d6632d4ebc2e78ed941477c2f1c56bd7493d74/nptdms/tdms.py#L1040-L1046 | train |
apriha/lineage | src/lineage/snps.py | detect_build | def detect_build(snps):
""" Detect build of SNPs.
Use the coordinates of common SNPs to identify the build / assembly of a genotype file
that is being loaded.
Notes
-----
rs3094315 : plus strand in 36, 37, and 38
rs11928389 : plus strand in 36, minus strand in 37 and 38
rs2500347 : plu... | python | def detect_build(snps):
""" Detect build of SNPs.
Use the coordinates of common SNPs to identify the build / assembly of a genotype file
that is being loaded.
Notes
-----
rs3094315 : plus strand in 36, 37, and 38
rs11928389 : plus strand in 36, minus strand in 37 and 38
rs2500347 : plu... | [
"def",
"detect_build",
"(",
"snps",
")",
":",
"def",
"lookup_build_with_snp_pos",
"(",
"pos",
",",
"s",
")",
":",
"try",
":",
"return",
"s",
".",
"loc",
"[",
"s",
"==",
"pos",
"]",
".",
"index",
"[",
"0",
"]",
"except",
":",
"return",
"None",
"buil... | Detect build of SNPs.
Use the coordinates of common SNPs to identify the build / assembly of a genotype file
that is being loaded.
Notes
-----
rs3094315 : plus strand in 36, 37, and 38
rs11928389 : plus strand in 36, minus strand in 37 and 38
rs2500347 : plus strand in 36 and 37, minus str... | [
"Detect",
"build",
"of",
"SNPs",
"."
] | 13106a62a959a80ac26c68d1566422de08aa877b | https://github.com/apriha/lineage/blob/13106a62a959a80ac26c68d1566422de08aa877b/src/lineage/snps.py#L491-L553 | train |
apriha/lineage | src/lineage/snps.py | get_chromosomes | def get_chromosomes(snps):
""" Get the chromosomes of SNPs.
Parameters
----------
snps : pandas.DataFrame
Returns
-------
list
list of str chromosomes (e.g., ['1', '2', '3', 'MT'], empty list if no chromosomes
"""
if isinstance(snps, pd.DataFrame):
return list(pd.u... | python | def get_chromosomes(snps):
""" Get the chromosomes of SNPs.
Parameters
----------
snps : pandas.DataFrame
Returns
-------
list
list of str chromosomes (e.g., ['1', '2', '3', 'MT'], empty list if no chromosomes
"""
if isinstance(snps, pd.DataFrame):
return list(pd.u... | [
"def",
"get_chromosomes",
"(",
"snps",
")",
":",
"if",
"isinstance",
"(",
"snps",
",",
"pd",
".",
"DataFrame",
")",
":",
"return",
"list",
"(",
"pd",
".",
"unique",
"(",
"snps",
"[",
"\"chrom\"",
"]",
")",
")",
"else",
":",
"return",
"[",
"]"
] | Get the chromosomes of SNPs.
Parameters
----------
snps : pandas.DataFrame
Returns
-------
list
list of str chromosomes (e.g., ['1', '2', '3', 'MT'], empty list if no chromosomes | [
"Get",
"the",
"chromosomes",
"of",
"SNPs",
"."
] | 13106a62a959a80ac26c68d1566422de08aa877b | https://github.com/apriha/lineage/blob/13106a62a959a80ac26c68d1566422de08aa877b/src/lineage/snps.py#L597-L613 | train |
apriha/lineage | src/lineage/snps.py | get_chromosomes_summary | def get_chromosomes_summary(snps):
""" Summary of the chromosomes of SNPs.
Parameters
----------
snps : pandas.DataFrame
Returns
-------
str
human-readable listing of chromosomes (e.g., '1-3, MT'), empty str if no chromosomes
"""
if isinstance(snps, pd.DataFrame):
... | python | def get_chromosomes_summary(snps):
""" Summary of the chromosomes of SNPs.
Parameters
----------
snps : pandas.DataFrame
Returns
-------
str
human-readable listing of chromosomes (e.g., '1-3, MT'), empty str if no chromosomes
"""
if isinstance(snps, pd.DataFrame):
... | [
"def",
"get_chromosomes_summary",
"(",
"snps",
")",
":",
"if",
"isinstance",
"(",
"snps",
",",
"pd",
".",
"DataFrame",
")",
":",
"chroms",
"=",
"list",
"(",
"pd",
".",
"unique",
"(",
"snps",
"[",
"\"chrom\"",
"]",
")",
")",
"int_chroms",
"=",
"[",
"i... | Summary of the chromosomes of SNPs.
Parameters
----------
snps : pandas.DataFrame
Returns
-------
str
human-readable listing of chromosomes (e.g., '1-3, MT'), empty str if no chromosomes | [
"Summary",
"of",
"the",
"chromosomes",
"of",
"SNPs",
"."
] | 13106a62a959a80ac26c68d1566422de08aa877b | https://github.com/apriha/lineage/blob/13106a62a959a80ac26c68d1566422de08aa877b/src/lineage/snps.py#L616-L655 | train |
apriha/lineage | src/lineage/snps.py | determine_sex | def determine_sex(
snps, y_snps_not_null_threshold=0.1, heterozygous_x_snps_threshold=0.01
):
""" Determine sex from SNPs using thresholds.
Parameters
----------
snps : pandas.DataFrame
y_snps_not_null_threshold : float
percentage Y SNPs that are not null; above this threshold, Male is ... | python | def determine_sex(
snps, y_snps_not_null_threshold=0.1, heterozygous_x_snps_threshold=0.01
):
""" Determine sex from SNPs using thresholds.
Parameters
----------
snps : pandas.DataFrame
y_snps_not_null_threshold : float
percentage Y SNPs that are not null; above this threshold, Male is ... | [
"def",
"determine_sex",
"(",
"snps",
",",
"y_snps_not_null_threshold",
"=",
"0.1",
",",
"heterozygous_x_snps_threshold",
"=",
"0.01",
")",
":",
"if",
"isinstance",
"(",
"snps",
",",
"pd",
".",
"DataFrame",
")",
":",
"y_snps",
"=",
"len",
"(",
"snps",
".",
... | Determine sex from SNPs using thresholds.
Parameters
----------
snps : pandas.DataFrame
y_snps_not_null_threshold : float
percentage Y SNPs that are not null; above this threshold, Male is determined
heterozygous_x_snps_threshold : float
percentage heterozygous X SNPs; above this th... | [
"Determine",
"sex",
"from",
"SNPs",
"using",
"thresholds",
"."
] | 13106a62a959a80ac26c68d1566422de08aa877b | https://github.com/apriha/lineage/blob/13106a62a959a80ac26c68d1566422de08aa877b/src/lineage/snps.py#L658-L708 | train |
apriha/lineage | src/lineage/snps.py | sort_snps | def sort_snps(snps):
""" Sort SNPs based on ordered chromosome list and position. """
sorted_list = sorted(snps["chrom"].unique(), key=_natural_sort_key)
# move PAR and MT to the end of the dataframe
if "PAR" in sorted_list:
sorted_list.remove("PAR")
sorted_list.append("PAR")
if "... | python | def sort_snps(snps):
""" Sort SNPs based on ordered chromosome list and position. """
sorted_list = sorted(snps["chrom"].unique(), key=_natural_sort_key)
# move PAR and MT to the end of the dataframe
if "PAR" in sorted_list:
sorted_list.remove("PAR")
sorted_list.append("PAR")
if "... | [
"def",
"sort_snps",
"(",
"snps",
")",
":",
"sorted_list",
"=",
"sorted",
"(",
"snps",
"[",
"\"chrom\"",
"]",
".",
"unique",
"(",
")",
",",
"key",
"=",
"_natural_sort_key",
")",
"if",
"\"PAR\"",
"in",
"sorted_list",
":",
"sorted_list",
".",
"remove",
"(",... | Sort SNPs based on ordered chromosome list and position. | [
"Sort",
"SNPs",
"based",
"on",
"ordered",
"chromosome",
"list",
"and",
"position",
"."
] | 13106a62a959a80ac26c68d1566422de08aa877b | https://github.com/apriha/lineage/blob/13106a62a959a80ac26c68d1566422de08aa877b/src/lineage/snps.py#L711-L737 | train |
apriha/lineage | src/lineage/snps.py | SNPs.get_summary | def get_summary(self):
""" Get summary of ``SNPs``.
Returns
-------
dict
summary info, else None if ``SNPs`` is not valid
"""
if not self.is_valid():
return None
else:
return {
"source": self.source,
... | python | def get_summary(self):
""" Get summary of ``SNPs``.
Returns
-------
dict
summary info, else None if ``SNPs`` is not valid
"""
if not self.is_valid():
return None
else:
return {
"source": self.source,
... | [
"def",
"get_summary",
"(",
"self",
")",
":",
"if",
"not",
"self",
".",
"is_valid",
"(",
")",
":",
"return",
"None",
"else",
":",
"return",
"{",
"\"source\"",
":",
"self",
".",
"source",
",",
"\"assembly\"",
":",
"self",
".",
"assembly",
",",
"\"build\"... | Get summary of ``SNPs``.
Returns
-------
dict
summary info, else None if ``SNPs`` is not valid | [
"Get",
"summary",
"of",
"SNPs",
"."
] | 13106a62a959a80ac26c68d1566422de08aa877b | https://github.com/apriha/lineage/blob/13106a62a959a80ac26c68d1566422de08aa877b/src/lineage/snps.py#L113-L132 | train |
apriha/lineage | src/lineage/snps.py | SNPs._read_23andme | def _read_23andme(file):
""" Read and parse 23andMe file.
https://www.23andme.com
Parameters
----------
file : str
path to file
Returns
-------
pandas.DataFrame
individual's genetic data normalized for use with `lineage`
... | python | def _read_23andme(file):
""" Read and parse 23andMe file.
https://www.23andme.com
Parameters
----------
file : str
path to file
Returns
-------
pandas.DataFrame
individual's genetic data normalized for use with `lineage`
... | [
"def",
"_read_23andme",
"(",
"file",
")",
":",
"df",
"=",
"pd",
".",
"read_csv",
"(",
"file",
",",
"comment",
"=",
"\"#\"",
",",
"sep",
"=",
"\"\\t\"",
",",
"na_values",
"=",
"\"--\"",
",",
"names",
"=",
"[",
"\"rsid\"",
",",
"\"chrom\"",
",",
"\"pos... | Read and parse 23andMe file.
https://www.23andme.com
Parameters
----------
file : str
path to file
Returns
-------
pandas.DataFrame
individual's genetic data normalized for use with `lineage`
str
name of data source | [
"Read",
"and",
"parse",
"23andMe",
"file",
"."
] | 13106a62a959a80ac26c68d1566422de08aa877b | https://github.com/apriha/lineage/blob/13106a62a959a80ac26c68d1566422de08aa877b/src/lineage/snps.py#L204-L231 | train |
apriha/lineage | src/lineage/snps.py | SNPs._read_lineage_csv | def _read_lineage_csv(file, comments):
""" Read and parse CSV file generated by lineage.
Parameters
----------
file : str
path to file
comments : str
comments at beginning of file
Returns
-------
pandas.DataFrame
indiv... | python | def _read_lineage_csv(file, comments):
""" Read and parse CSV file generated by lineage.
Parameters
----------
file : str
path to file
comments : str
comments at beginning of file
Returns
-------
pandas.DataFrame
indiv... | [
"def",
"_read_lineage_csv",
"(",
"file",
",",
"comments",
")",
":",
"source",
"=",
"\"\"",
"for",
"comment",
"in",
"comments",
".",
"split",
"(",
"\"\\n\"",
")",
":",
"if",
"\"Source(s):\"",
"in",
"comment",
":",
"source",
"=",
"comment",
".",
"split",
"... | Read and parse CSV file generated by lineage.
Parameters
----------
file : str
path to file
comments : str
comments at beginning of file
Returns
-------
pandas.DataFrame
individual's genetic data normalized for use with `linea... | [
"Read",
"and",
"parse",
"CSV",
"file",
"generated",
"by",
"lineage",
"."
] | 13106a62a959a80ac26c68d1566422de08aa877b | https://github.com/apriha/lineage/blob/13106a62a959a80ac26c68d1566422de08aa877b/src/lineage/snps.py#L354-L387 | train |
apriha/lineage | src/lineage/snps.py | SNPs._read_generic_csv | def _read_generic_csv(file):
""" Read and parse generic CSV file.
Notes
-----
Assumes columns are 'rsid', 'chrom' / 'chromosome', 'pos' / 'position', and 'genotype';
values are comma separated; unreported genotypes are indicated by '--'; and one header row
precedes data.... | python | def _read_generic_csv(file):
""" Read and parse generic CSV file.
Notes
-----
Assumes columns are 'rsid', 'chrom' / 'chromosome', 'pos' / 'position', and 'genotype';
values are comma separated; unreported genotypes are indicated by '--'; and one header row
precedes data.... | [
"def",
"_read_generic_csv",
"(",
"file",
")",
":",
"df",
"=",
"pd",
".",
"read_csv",
"(",
"file",
",",
"skiprows",
"=",
"1",
",",
"na_values",
"=",
"\"--\"",
",",
"names",
"=",
"[",
"\"rsid\"",
",",
"\"chrom\"",
",",
"\"pos\"",
",",
"\"genotype\"",
"]"... | Read and parse generic CSV file.
Notes
-----
Assumes columns are 'rsid', 'chrom' / 'chromosome', 'pos' / 'position', and 'genotype';
values are comma separated; unreported genotypes are indicated by '--'; and one header row
precedes data. For example:
rsid,chromosom... | [
"Read",
"and",
"parse",
"generic",
"CSV",
"file",
"."
] | 13106a62a959a80ac26c68d1566422de08aa877b | https://github.com/apriha/lineage/blob/13106a62a959a80ac26c68d1566422de08aa877b/src/lineage/snps.py#L390-L425 | train |
apriha/lineage | src/lineage/snps.py | SNPs._assign_par_snps | def _assign_par_snps(self):
""" Assign PAR SNPs to the X or Y chromosome using SNP position.
References
-----
..[1] National Center for Biotechnology Information, Variation Services, RefSNP,
https://api.ncbi.nlm.nih.gov/variation/v0/
..[2] Yates et. al. (doi:10.1093/bi... | python | def _assign_par_snps(self):
""" Assign PAR SNPs to the X or Y chromosome using SNP position.
References
-----
..[1] National Center for Biotechnology Information, Variation Services, RefSNP,
https://api.ncbi.nlm.nih.gov/variation/v0/
..[2] Yates et. al. (doi:10.1093/bi... | [
"def",
"_assign_par_snps",
"(",
"self",
")",
":",
"rest_client",
"=",
"EnsemblRestClient",
"(",
"server",
"=",
"\"https://api.ncbi.nlm.nih.gov\"",
")",
"for",
"rsid",
"in",
"self",
".",
"snps",
".",
"loc",
"[",
"self",
".",
"snps",
"[",
"\"chrom\"",
"]",
"==... | Assign PAR SNPs to the X or Y chromosome using SNP position.
References
-----
..[1] National Center for Biotechnology Information, Variation Services, RefSNP,
https://api.ncbi.nlm.nih.gov/variation/v0/
..[2] Yates et. al. (doi:10.1093/bioinformatics/btu613),
http://e... | [
"Assign",
"PAR",
"SNPs",
"to",
"the",
"X",
"or",
"Y",
"chromosome",
"using",
"SNP",
"position",
"."
] | 13106a62a959a80ac26c68d1566422de08aa877b | https://github.com/apriha/lineage/blob/13106a62a959a80ac26c68d1566422de08aa877b/src/lineage/snps.py#L427-L472 | train |
apriha/lineage | src/lineage/visualization.py | plot_chromosomes | def plot_chromosomes(one_chrom_match, two_chrom_match, cytobands, path, title, build):
""" Plots chromosomes with designated markers.
Parameters
----------
one_chrom_match : list of dicts
segments to highlight on the chromosomes representing one shared chromosome
two_chrom_match : list of d... | python | def plot_chromosomes(one_chrom_match, two_chrom_match, cytobands, path, title, build):
""" Plots chromosomes with designated markers.
Parameters
----------
one_chrom_match : list of dicts
segments to highlight on the chromosomes representing one shared chromosome
two_chrom_match : list of d... | [
"def",
"plot_chromosomes",
"(",
"one_chrom_match",
",",
"two_chrom_match",
",",
"cytobands",
",",
"path",
",",
"title",
",",
"build",
")",
":",
"chrom_height",
"=",
"1.25",
"chrom_spacing",
"=",
"1",
"chromosome_list",
"=",
"[",
"\"chr%s\"",
"%",
"i",
"for",
... | Plots chromosomes with designated markers.
Parameters
----------
one_chrom_match : list of dicts
segments to highlight on the chromosomes representing one shared chromosome
two_chrom_match : list of dicts
segments to highlight on the chromosomes representing two shared chromosomes
c... | [
"Plots",
"chromosomes",
"with",
"designated",
"markers",
"."
] | 13106a62a959a80ac26c68d1566422de08aa877b | https://github.com/apriha/lineage/blob/13106a62a959a80ac26c68d1566422de08aa877b/src/lineage/visualization.py#L69-L169 | train |
apriha/lineage | src/lineage/__init__.py | create_dir | def create_dir(path):
""" Create directory specified by `path` if it doesn't already exist.
Parameters
----------
path : str
path to directory
Returns
-------
bool
True if `path` exists
"""
# https://stackoverflow.com/a/5032238
try:
os.makedirs(path, exi... | python | def create_dir(path):
""" Create directory specified by `path` if it doesn't already exist.
Parameters
----------
path : str
path to directory
Returns
-------
bool
True if `path` exists
"""
# https://stackoverflow.com/a/5032238
try:
os.makedirs(path, exi... | [
"def",
"create_dir",
"(",
"path",
")",
":",
"try",
":",
"os",
".",
"makedirs",
"(",
"path",
",",
"exist_ok",
"=",
"True",
")",
"except",
"Exception",
"as",
"err",
":",
"print",
"(",
"err",
")",
"return",
"False",
"if",
"os",
".",
"path",
".",
"exis... | Create directory specified by `path` if it doesn't already exist.
Parameters
----------
path : str
path to directory
Returns
-------
bool
True if `path` exists | [
"Create",
"directory",
"specified",
"by",
"path",
"if",
"it",
"doesn",
"t",
"already",
"exist",
"."
] | 13106a62a959a80ac26c68d1566422de08aa877b | https://github.com/apriha/lineage/blob/13106a62a959a80ac26c68d1566422de08aa877b/src/lineage/__init__.py#L859-L882 | train |
apriha/lineage | src/lineage/__init__.py | save_df_as_csv | def save_df_as_csv(df, path, filename, comment=None, **kwargs):
""" Save dataframe to a CSV file.
Parameters
----------
df : pandas.DataFrame
dataframe to save
path : str
path to directory where to save CSV file
filename : str
filename of CSV file
comment : str
... | python | def save_df_as_csv(df, path, filename, comment=None, **kwargs):
""" Save dataframe to a CSV file.
Parameters
----------
df : pandas.DataFrame
dataframe to save
path : str
path to directory where to save CSV file
filename : str
filename of CSV file
comment : str
... | [
"def",
"save_df_as_csv",
"(",
"df",
",",
"path",
",",
"filename",
",",
"comment",
"=",
"None",
",",
"**",
"kwargs",
")",
":",
"if",
"isinstance",
"(",
"df",
",",
"pd",
".",
"DataFrame",
")",
"and",
"len",
"(",
"df",
")",
">",
"0",
":",
"try",
":"... | Save dataframe to a CSV file.
Parameters
----------
df : pandas.DataFrame
dataframe to save
path : str
path to directory where to save CSV file
filename : str
filename of CSV file
comment : str
header comment(s); one or more lines starting with '#'
**kwargs
... | [
"Save",
"dataframe",
"to",
"a",
"CSV",
"file",
"."
] | 13106a62a959a80ac26c68d1566422de08aa877b | https://github.com/apriha/lineage/blob/13106a62a959a80ac26c68d1566422de08aa877b/src/lineage/__init__.py#L885-L940 | train |
apriha/lineage | src/lineage/resources.py | Resources.get_genetic_map_HapMapII_GRCh37 | def get_genetic_map_HapMapII_GRCh37(self):
""" Get International HapMap Consortium HapMap Phase II genetic map for Build 37.
Returns
-------
dict
dict of pandas.DataFrame HapMapII genetic maps if loading was successful, else None
"""
if self._genetic_map_HapM... | python | def get_genetic_map_HapMapII_GRCh37(self):
""" Get International HapMap Consortium HapMap Phase II genetic map for Build 37.
Returns
-------
dict
dict of pandas.DataFrame HapMapII genetic maps if loading was successful, else None
"""
if self._genetic_map_HapM... | [
"def",
"get_genetic_map_HapMapII_GRCh37",
"(",
"self",
")",
":",
"if",
"self",
".",
"_genetic_map_HapMapII_GRCh37",
"is",
"None",
":",
"self",
".",
"_genetic_map_HapMapII_GRCh37",
"=",
"self",
".",
"_load_genetic_map",
"(",
"self",
".",
"_get_path_genetic_map_HapMapII_G... | Get International HapMap Consortium HapMap Phase II genetic map for Build 37.
Returns
-------
dict
dict of pandas.DataFrame HapMapII genetic maps if loading was successful, else None | [
"Get",
"International",
"HapMap",
"Consortium",
"HapMap",
"Phase",
"II",
"genetic",
"map",
"for",
"Build",
"37",
"."
] | 13106a62a959a80ac26c68d1566422de08aa877b | https://github.com/apriha/lineage/blob/13106a62a959a80ac26c68d1566422de08aa877b/src/lineage/resources.py#L83-L96 | train |
apriha/lineage | src/lineage/resources.py | Resources.get_cytoBand_hg19 | def get_cytoBand_hg19(self):
""" Get UCSC cytoBand table for Build 37.
Returns
-------
pandas.DataFrame
cytoBand table if loading was successful, else None
"""
if self._cytoBand_hg19 is None:
self._cytoBand_hg19 = self._load_cytoBand(self._get_pat... | python | def get_cytoBand_hg19(self):
""" Get UCSC cytoBand table for Build 37.
Returns
-------
pandas.DataFrame
cytoBand table if loading was successful, else None
"""
if self._cytoBand_hg19 is None:
self._cytoBand_hg19 = self._load_cytoBand(self._get_pat... | [
"def",
"get_cytoBand_hg19",
"(",
"self",
")",
":",
"if",
"self",
".",
"_cytoBand_hg19",
"is",
"None",
":",
"self",
".",
"_cytoBand_hg19",
"=",
"self",
".",
"_load_cytoBand",
"(",
"self",
".",
"_get_path_cytoBand_hg19",
"(",
")",
")",
"return",
"self",
".",
... | Get UCSC cytoBand table for Build 37.
Returns
-------
pandas.DataFrame
cytoBand table if loading was successful, else None | [
"Get",
"UCSC",
"cytoBand",
"table",
"for",
"Build",
"37",
"."
] | 13106a62a959a80ac26c68d1566422de08aa877b | https://github.com/apriha/lineage/blob/13106a62a959a80ac26c68d1566422de08aa877b/src/lineage/resources.py#L98-L109 | train |
apriha/lineage | src/lineage/resources.py | Resources.get_knownGene_hg19 | def get_knownGene_hg19(self):
""" Get UCSC knownGene table for Build 37.
Returns
-------
pandas.DataFrame
knownGene table if loading was successful, else None
"""
if self._knownGene_hg19 is None:
self._knownGene_hg19 = self._load_knownGene(self._g... | python | def get_knownGene_hg19(self):
""" Get UCSC knownGene table for Build 37.
Returns
-------
pandas.DataFrame
knownGene table if loading was successful, else None
"""
if self._knownGene_hg19 is None:
self._knownGene_hg19 = self._load_knownGene(self._g... | [
"def",
"get_knownGene_hg19",
"(",
"self",
")",
":",
"if",
"self",
".",
"_knownGene_hg19",
"is",
"None",
":",
"self",
".",
"_knownGene_hg19",
"=",
"self",
".",
"_load_knownGene",
"(",
"self",
".",
"_get_path_knownGene_hg19",
"(",
")",
")",
"return",
"self",
"... | Get UCSC knownGene table for Build 37.
Returns
-------
pandas.DataFrame
knownGene table if loading was successful, else None | [
"Get",
"UCSC",
"knownGene",
"table",
"for",
"Build",
"37",
"."
] | 13106a62a959a80ac26c68d1566422de08aa877b | https://github.com/apriha/lineage/blob/13106a62a959a80ac26c68d1566422de08aa877b/src/lineage/resources.py#L111-L122 | train |
apriha/lineage | src/lineage/resources.py | Resources.get_kgXref_hg19 | def get_kgXref_hg19(self):
""" Get UCSC kgXref table for Build 37.
Returns
-------
pandas.DataFrame
kgXref table if loading was successful, else None
"""
if self._kgXref_hg19 is None:
self._kgXref_hg19 = self._load_kgXref(self._get_path_kgXref_hg1... | python | def get_kgXref_hg19(self):
""" Get UCSC kgXref table for Build 37.
Returns
-------
pandas.DataFrame
kgXref table if loading was successful, else None
"""
if self._kgXref_hg19 is None:
self._kgXref_hg19 = self._load_kgXref(self._get_path_kgXref_hg1... | [
"def",
"get_kgXref_hg19",
"(",
"self",
")",
":",
"if",
"self",
".",
"_kgXref_hg19",
"is",
"None",
":",
"self",
".",
"_kgXref_hg19",
"=",
"self",
".",
"_load_kgXref",
"(",
"self",
".",
"_get_path_kgXref_hg19",
"(",
")",
")",
"return",
"self",
".",
"_kgXref_... | Get UCSC kgXref table for Build 37.
Returns
-------
pandas.DataFrame
kgXref table if loading was successful, else None | [
"Get",
"UCSC",
"kgXref",
"table",
"for",
"Build",
"37",
"."
] | 13106a62a959a80ac26c68d1566422de08aa877b | https://github.com/apriha/lineage/blob/13106a62a959a80ac26c68d1566422de08aa877b/src/lineage/resources.py#L124-L135 | train |
apriha/lineage | src/lineage/resources.py | Resources.get_assembly_mapping_data | def get_assembly_mapping_data(self, source_assembly, target_assembly):
""" Get assembly mapping data.
Parameters
----------
source_assembly : {'NCBI36', 'GRCh37', 'GRCh38'}
assembly to remap from
target_assembly : {'NCBI36', 'GRCh37', 'GRCh38'}
assembly t... | python | def get_assembly_mapping_data(self, source_assembly, target_assembly):
""" Get assembly mapping data.
Parameters
----------
source_assembly : {'NCBI36', 'GRCh37', 'GRCh38'}
assembly to remap from
target_assembly : {'NCBI36', 'GRCh37', 'GRCh38'}
assembly t... | [
"def",
"get_assembly_mapping_data",
"(",
"self",
",",
"source_assembly",
",",
"target_assembly",
")",
":",
"return",
"self",
".",
"_load_assembly_mapping_data",
"(",
"self",
".",
"_get_path_assembly_mapping_data",
"(",
"source_assembly",
",",
"target_assembly",
")",
")"... | Get assembly mapping data.
Parameters
----------
source_assembly : {'NCBI36', 'GRCh37', 'GRCh38'}
assembly to remap from
target_assembly : {'NCBI36', 'GRCh37', 'GRCh38'}
assembly to remap to
Returns
-------
dict
dict of json a... | [
"Get",
"assembly",
"mapping",
"data",
"."
] | 13106a62a959a80ac26c68d1566422de08aa877b | https://github.com/apriha/lineage/blob/13106a62a959a80ac26c68d1566422de08aa877b/src/lineage/resources.py#L137-L154 | train |
apriha/lineage | src/lineage/resources.py | Resources._load_assembly_mapping_data | def _load_assembly_mapping_data(filename):
""" Load assembly mapping data.
Parameters
----------
filename : str
path to compressed archive with assembly mapping data
Returns
-------
assembly_mapping_data : dict
dict of assembly maps if lo... | python | def _load_assembly_mapping_data(filename):
""" Load assembly mapping data.
Parameters
----------
filename : str
path to compressed archive with assembly mapping data
Returns
-------
assembly_mapping_data : dict
dict of assembly maps if lo... | [
"def",
"_load_assembly_mapping_data",
"(",
"filename",
")",
":",
"try",
":",
"assembly_mapping_data",
"=",
"{",
"}",
"with",
"tarfile",
".",
"open",
"(",
"filename",
",",
"\"r\"",
")",
"as",
"tar",
":",
"for",
"member",
"in",
"tar",
".",
"getmembers",
"(",... | Load assembly mapping data.
Parameters
----------
filename : str
path to compressed archive with assembly mapping data
Returns
-------
assembly_mapping_data : dict
dict of assembly maps if loading was successful, else None
Notes
... | [
"Load",
"assembly",
"mapping",
"data",
"."
] | 13106a62a959a80ac26c68d1566422de08aa877b | https://github.com/apriha/lineage/blob/13106a62a959a80ac26c68d1566422de08aa877b/src/lineage/resources.py#L312-L346 | train |
apriha/lineage | src/lineage/resources.py | Resources._load_cytoBand | def _load_cytoBand(filename):
""" Load UCSC cytoBand table.
Parameters
----------
filename : str
path to cytoBand file
Returns
-------
df : pandas.DataFrame
cytoBand table if loading was successful, else None
References
-... | python | def _load_cytoBand(filename):
""" Load UCSC cytoBand table.
Parameters
----------
filename : str
path to cytoBand file
Returns
-------
df : pandas.DataFrame
cytoBand table if loading was successful, else None
References
-... | [
"def",
"_load_cytoBand",
"(",
"filename",
")",
":",
"try",
":",
"df",
"=",
"pd",
".",
"read_table",
"(",
"filename",
",",
"names",
"=",
"[",
"\"chrom\"",
",",
"\"start\"",
",",
"\"end\"",
",",
"\"name\"",
",",
"\"gie_stain\"",
"]",
")",
"df",
"[",
"\"c... | Load UCSC cytoBand table.
Parameters
----------
filename : str
path to cytoBand file
Returns
-------
df : pandas.DataFrame
cytoBand table if loading was successful, else None
References
----------
..[1] Ryan Dale, GitHub ... | [
"Load",
"UCSC",
"cytoBand",
"table",
"."
] | 13106a62a959a80ac26c68d1566422de08aa877b | https://github.com/apriha/lineage/blob/13106a62a959a80ac26c68d1566422de08aa877b/src/lineage/resources.py#L349-L376 | train |
apriha/lineage | src/lineage/resources.py | Resources._load_knownGene | def _load_knownGene(filename):
""" Load UCSC knownGene table.
Parameters
----------
filename : str
path to knownGene file
Returns
-------
df : pandas.DataFrame
knownGene table if loading was successful, else None
"""
try:
... | python | def _load_knownGene(filename):
""" Load UCSC knownGene table.
Parameters
----------
filename : str
path to knownGene file
Returns
-------
df : pandas.DataFrame
knownGene table if loading was successful, else None
"""
try:
... | [
"def",
"_load_knownGene",
"(",
"filename",
")",
":",
"try",
":",
"df",
"=",
"pd",
".",
"read_table",
"(",
"filename",
",",
"names",
"=",
"[",
"\"name\"",
",",
"\"chrom\"",
",",
"\"strand\"",
",",
"\"txStart\"",
",",
"\"txEnd\"",
",",
"\"cdsStart\"",
",",
... | Load UCSC knownGene table.
Parameters
----------
filename : str
path to knownGene file
Returns
-------
df : pandas.DataFrame
knownGene table if loading was successful, else None | [
"Load",
"UCSC",
"knownGene",
"table",
"."
] | 13106a62a959a80ac26c68d1566422de08aa877b | https://github.com/apriha/lineage/blob/13106a62a959a80ac26c68d1566422de08aa877b/src/lineage/resources.py#L379-L415 | train |
apriha/lineage | src/lineage/resources.py | Resources._load_kgXref | def _load_kgXref(filename):
""" Load UCSC kgXref table.
Parameters
----------
filename : str
path to kgXref file
Returns
-------
df : pandas.DataFrame
kgXref table if loading was successful, else None
"""
try:
... | python | def _load_kgXref(filename):
""" Load UCSC kgXref table.
Parameters
----------
filename : str
path to kgXref file
Returns
-------
df : pandas.DataFrame
kgXref table if loading was successful, else None
"""
try:
... | [
"def",
"_load_kgXref",
"(",
"filename",
")",
":",
"try",
":",
"df",
"=",
"pd",
".",
"read_table",
"(",
"filename",
",",
"names",
"=",
"[",
"\"kgID\"",
",",
"\"mRNA\"",
",",
"\"spID\"",
",",
"\"spDisplayID\"",
",",
"\"geneSymbol\"",
",",
"\"refseq\"",
",",
... | Load UCSC kgXref table.
Parameters
----------
filename : str
path to kgXref file
Returns
-------
df : pandas.DataFrame
kgXref table if loading was successful, else None | [
"Load",
"UCSC",
"kgXref",
"table",
"."
] | 13106a62a959a80ac26c68d1566422de08aa877b | https://github.com/apriha/lineage/blob/13106a62a959a80ac26c68d1566422de08aa877b/src/lineage/resources.py#L418-L452 | train |
apriha/lineage | src/lineage/resources.py | Resources._get_path_assembly_mapping_data | def _get_path_assembly_mapping_data(
self, source_assembly, target_assembly, retries=10
):
""" Get local path to assembly mapping data, downloading if necessary.
Parameters
----------
source_assembly : {'NCBI36', 'GRCh37', 'GRCh38'}
assembly to remap from
... | python | def _get_path_assembly_mapping_data(
self, source_assembly, target_assembly, retries=10
):
""" Get local path to assembly mapping data, downloading if necessary.
Parameters
----------
source_assembly : {'NCBI36', 'GRCh37', 'GRCh38'}
assembly to remap from
... | [
"def",
"_get_path_assembly_mapping_data",
"(",
"self",
",",
"source_assembly",
",",
"target_assembly",
",",
"retries",
"=",
"10",
")",
":",
"if",
"not",
"lineage",
".",
"create_dir",
"(",
"self",
".",
"_resources_dir",
")",
":",
"return",
"None",
"chroms",
"="... | Get local path to assembly mapping data, downloading if necessary.
Parameters
----------
source_assembly : {'NCBI36', 'GRCh37', 'GRCh38'}
assembly to remap from
target_assembly : {'NCBI36', 'GRCh37', 'GRCh38'}
assembly to remap to
retries : int
... | [
"Get",
"local",
"path",
"to",
"assembly",
"mapping",
"data",
"downloading",
"if",
"necessary",
"."
] | 13106a62a959a80ac26c68d1566422de08aa877b | https://github.com/apriha/lineage/blob/13106a62a959a80ac26c68d1566422de08aa877b/src/lineage/resources.py#L517-L626 | train |
apriha/lineage | src/lineage/resources.py | Resources._download_file | def _download_file(self, url, filename, compress=False, timeout=30):
""" Download a file to the resources folder.
Download data from `url`, save as `filename`, and optionally compress with gzip.
Parameters
----------
url : str
URL to download data from
filen... | python | def _download_file(self, url, filename, compress=False, timeout=30):
""" Download a file to the resources folder.
Download data from `url`, save as `filename`, and optionally compress with gzip.
Parameters
----------
url : str
URL to download data from
filen... | [
"def",
"_download_file",
"(",
"self",
",",
"url",
",",
"filename",
",",
"compress",
"=",
"False",
",",
"timeout",
"=",
"30",
")",
":",
"if",
"not",
"lineage",
".",
"create_dir",
"(",
"self",
".",
"_resources_dir",
")",
":",
"return",
"None",
"if",
"com... | Download a file to the resources folder.
Download data from `url`, save as `filename`, and optionally compress with gzip.
Parameters
----------
url : str
URL to download data from
filename : str
name of file to save; if compress, ensure '.gz' is appended... | [
"Download",
"a",
"file",
"to",
"the",
"resources",
"folder",
"."
] | 13106a62a959a80ac26c68d1566422de08aa877b | https://github.com/apriha/lineage/blob/13106a62a959a80ac26c68d1566422de08aa877b/src/lineage/resources.py#L642-L701 | train |
apriha/lineage | src/lineage/individual.py | Individual.load_snps | def load_snps(
self,
raw_data,
discrepant_snp_positions_threshold=100,
discrepant_genotypes_threshold=500,
save_output=False,
):
""" Load raw genotype data.
Parameters
----------
raw_data : list or str
path(s) to file(s) with raw g... | python | def load_snps(
self,
raw_data,
discrepant_snp_positions_threshold=100,
discrepant_genotypes_threshold=500,
save_output=False,
):
""" Load raw genotype data.
Parameters
----------
raw_data : list or str
path(s) to file(s) with raw g... | [
"def",
"load_snps",
"(",
"self",
",",
"raw_data",
",",
"discrepant_snp_positions_threshold",
"=",
"100",
",",
"discrepant_genotypes_threshold",
"=",
"500",
",",
"save_output",
"=",
"False",
",",
")",
":",
"if",
"type",
"(",
"raw_data",
")",
"is",
"list",
":",
... | Load raw genotype data.
Parameters
----------
raw_data : list or str
path(s) to file(s) with raw genotype data
discrepant_snp_positions_threshold : int
threshold for discrepant SNP positions between existing data and data to be loaded,
a large value c... | [
"Load",
"raw",
"genotype",
"data",
"."
] | 13106a62a959a80ac26c68d1566422de08aa877b | https://github.com/apriha/lineage/blob/13106a62a959a80ac26c68d1566422de08aa877b/src/lineage/individual.py#L205-L243 | train |
apriha/lineage | src/lineage/individual.py | Individual.save_snps | def save_snps(self, filename=None):
""" Save SNPs to file.
Parameters
----------
filename : str
filename for file to save
Returns
-------
str
path to file in output directory if SNPs were saved, else empty str
"""
comment ... | python | def save_snps(self, filename=None):
""" Save SNPs to file.
Parameters
----------
filename : str
filename for file to save
Returns
-------
str
path to file in output directory if SNPs were saved, else empty str
"""
comment ... | [
"def",
"save_snps",
"(",
"self",
",",
"filename",
"=",
"None",
")",
":",
"comment",
"=",
"(",
"\"# Source(s): {}\\n\"",
"\"# Assembly: {}\\n\"",
"\"# SNPs: {}\\n\"",
"\"# Chromosomes: {}\\n\"",
".",
"format",
"(",
"self",
".",
"source",
",",
"self",
".",
"assembly... | Save SNPs to file.
Parameters
----------
filename : str
filename for file to save
Returns
-------
str
path to file in output directory if SNPs were saved, else empty str | [
"Save",
"SNPs",
"to",
"file",
"."
] | 13106a62a959a80ac26c68d1566422de08aa877b | https://github.com/apriha/lineage/blob/13106a62a959a80ac26c68d1566422de08aa877b/src/lineage/individual.py#L267-L298 | train |
apriha/lineage | src/lineage/individual.py | Individual.remap_snps | def remap_snps(self, target_assembly, complement_bases=True):
""" Remap the SNP coordinates of this ``Individual`` from one assembly to another.
This method is a wrapper for `remap_snps` in the ``Lineage`` class.
This method uses the assembly map endpoint of the Ensembl REST API service to con... | python | def remap_snps(self, target_assembly, complement_bases=True):
""" Remap the SNP coordinates of this ``Individual`` from one assembly to another.
This method is a wrapper for `remap_snps` in the ``Lineage`` class.
This method uses the assembly map endpoint of the Ensembl REST API service to con... | [
"def",
"remap_snps",
"(",
"self",
",",
"target_assembly",
",",
"complement_bases",
"=",
"True",
")",
":",
"from",
"lineage",
"import",
"Lineage",
"l",
"=",
"Lineage",
"(",
")",
"return",
"l",
".",
"remap_snps",
"(",
"self",
",",
"target_assembly",
",",
"co... | Remap the SNP coordinates of this ``Individual`` from one assembly to another.
This method is a wrapper for `remap_snps` in the ``Lineage`` class.
This method uses the assembly map endpoint of the Ensembl REST API service to convert SNP
coordinates / positions from one assembly to another. Aft... | [
"Remap",
"the",
"SNP",
"coordinates",
"of",
"this",
"Individual",
"from",
"one",
"assembly",
"to",
"another",
"."
] | 13106a62a959a80ac26c68d1566422de08aa877b | https://github.com/apriha/lineage/blob/13106a62a959a80ac26c68d1566422de08aa877b/src/lineage/individual.py#L382-L427 | train |
apriha/lineage | src/lineage/individual.py | Individual._set_snps | def _set_snps(self, snps, build=37):
""" Set `_snps` and `_build` properties of this ``Individual``.
Notes
-----
Intended to be used internally to `lineage`.
Parameters
----------
snps : pandas.DataFrame
individual's genetic data normalized for use w... | python | def _set_snps(self, snps, build=37):
""" Set `_snps` and `_build` properties of this ``Individual``.
Notes
-----
Intended to be used internally to `lineage`.
Parameters
----------
snps : pandas.DataFrame
individual's genetic data normalized for use w... | [
"def",
"_set_snps",
"(",
"self",
",",
"snps",
",",
"build",
"=",
"37",
")",
":",
"self",
".",
"_snps",
"=",
"snps",
"self",
".",
"_build",
"=",
"build"
] | Set `_snps` and `_build` properties of this ``Individual``.
Notes
-----
Intended to be used internally to `lineage`.
Parameters
----------
snps : pandas.DataFrame
individual's genetic data normalized for use with `lineage`
build : int
bui... | [
"Set",
"_snps",
"and",
"_build",
"properties",
"of",
"this",
"Individual",
"."
] | 13106a62a959a80ac26c68d1566422de08aa877b | https://github.com/apriha/lineage/blob/13106a62a959a80ac26c68d1566422de08aa877b/src/lineage/individual.py#L429-L444 | train |
apriha/lineage | src/lineage/individual.py | Individual._double_single_alleles | def _double_single_alleles(df, chrom):
""" Double any single alleles in the specified chromosome.
Parameters
----------
df : pandas.DataFrame
SNPs
chrom : str
chromosome of alleles to double
Returns
-------
df : pandas.DataFrame
... | python | def _double_single_alleles(df, chrom):
""" Double any single alleles in the specified chromosome.
Parameters
----------
df : pandas.DataFrame
SNPs
chrom : str
chromosome of alleles to double
Returns
-------
df : pandas.DataFrame
... | [
"def",
"_double_single_alleles",
"(",
"df",
",",
"chrom",
")",
":",
"single_alleles",
"=",
"np",
".",
"where",
"(",
"(",
"df",
"[",
"\"chrom\"",
"]",
"==",
"chrom",
")",
"&",
"(",
"df",
"[",
"\"genotype\"",
"]",
".",
"str",
".",
"len",
"(",
")",
"=... | Double any single alleles in the specified chromosome.
Parameters
----------
df : pandas.DataFrame
SNPs
chrom : str
chromosome of alleles to double
Returns
-------
df : pandas.DataFrame
SNPs with specified chromosome's single ... | [
"Double",
"any",
"single",
"alleles",
"in",
"the",
"specified",
"chromosome",
"."
] | 13106a62a959a80ac26c68d1566422de08aa877b | https://github.com/apriha/lineage/blob/13106a62a959a80ac26c68d1566422de08aa877b/src/lineage/individual.py#L605-L628 | train |
tBuLi/symfit | symfit/core/support.py | seperate_symbols | def seperate_symbols(func):
"""
Seperate the symbols in symbolic function func. Return them in alphabetical
order.
:param func: scipy symbolic function.
:return: (vars, params), a tuple of all variables and parameters, each
sorted in alphabetical order.
:raises TypeError: only symfit V... | python | def seperate_symbols(func):
"""
Seperate the symbols in symbolic function func. Return them in alphabetical
order.
:param func: scipy symbolic function.
:return: (vars, params), a tuple of all variables and parameters, each
sorted in alphabetical order.
:raises TypeError: only symfit V... | [
"def",
"seperate_symbols",
"(",
"func",
")",
":",
"params",
"=",
"[",
"]",
"vars",
"=",
"[",
"]",
"for",
"symbol",
"in",
"func",
".",
"free_symbols",
":",
"if",
"not",
"isidentifier",
"(",
"str",
"(",
"symbol",
")",
")",
":",
"continue",
"if",
"isins... | Seperate the symbols in symbolic function func. Return them in alphabetical
order.
:param func: scipy symbolic function.
:return: (vars, params), a tuple of all variables and parameters, each
sorted in alphabetical order.
:raises TypeError: only symfit Variable and Parameter are allowed, not s... | [
"Seperate",
"the",
"symbols",
"in",
"symbolic",
"function",
"func",
".",
"Return",
"them",
"in",
"alphabetical",
"order",
"."
] | 759dd3d1d4270510d651f40b23dd26b1b10eee83 | https://github.com/tBuLi/symfit/blob/759dd3d1d4270510d651f40b23dd26b1b10eee83/symfit/core/support.py#L69-L106 | train |
tBuLi/symfit | symfit/core/support.py | sympy_to_py | def sympy_to_py(func, args):
"""
Turn a symbolic expression into a Python lambda function,
which has the names of the variables and parameters as it's argument names.
:param func: sympy expression
:param args: variables and parameters in this model
:return: lambda function to be used for numeri... | python | def sympy_to_py(func, args):
"""
Turn a symbolic expression into a Python lambda function,
which has the names of the variables and parameters as it's argument names.
:param func: sympy expression
:param args: variables and parameters in this model
:return: lambda function to be used for numeri... | [
"def",
"sympy_to_py",
"(",
"func",
",",
"args",
")",
":",
"derivatives",
"=",
"{",
"var",
":",
"Variable",
"(",
"var",
".",
"name",
")",
"for",
"var",
"in",
"args",
"if",
"isinstance",
"(",
"var",
",",
"sympy",
".",
"Derivative",
")",
"}",
"func",
... | Turn a symbolic expression into a Python lambda function,
which has the names of the variables and parameters as it's argument names.
:param func: sympy expression
:param args: variables and parameters in this model
:return: lambda function to be used for numerical evaluation of the model. | [
"Turn",
"a",
"symbolic",
"expression",
"into",
"a",
"Python",
"lambda",
"function",
"which",
"has",
"the",
"names",
"of",
"the",
"variables",
"and",
"parameters",
"as",
"it",
"s",
"argument",
"names",
"."
] | 759dd3d1d4270510d651f40b23dd26b1b10eee83 | https://github.com/tBuLi/symfit/blob/759dd3d1d4270510d651f40b23dd26b1b10eee83/symfit/core/support.py#L108-L160 | train |
tBuLi/symfit | symfit/core/support.py | sympy_to_scipy | def sympy_to_scipy(func, vars, params):
"""
Convert a symbolic expression to one scipy digs. Not used by ``symfit`` any more.
:param func: sympy expression
:param vars: variables
:param params: parameters
:return: Scipy-style function to be used for numerical evaluation of the model.
"""
... | python | def sympy_to_scipy(func, vars, params):
"""
Convert a symbolic expression to one scipy digs. Not used by ``symfit`` any more.
:param func: sympy expression
:param vars: variables
:param params: parameters
:return: Scipy-style function to be used for numerical evaluation of the model.
"""
... | [
"def",
"sympy_to_scipy",
"(",
"func",
",",
"vars",
",",
"params",
")",
":",
"lambda_func",
"=",
"sympy_to_py",
"(",
"func",
",",
"vars",
",",
"params",
")",
"def",
"f",
"(",
"x",
",",
"p",
")",
":",
"x",
"=",
"np",
".",
"atleast_2d",
"(",
"x",
")... | Convert a symbolic expression to one scipy digs. Not used by ``symfit`` any more.
:param func: sympy expression
:param vars: variables
:param params: parameters
:return: Scipy-style function to be used for numerical evaluation of the model. | [
"Convert",
"a",
"symbolic",
"expression",
"to",
"one",
"scipy",
"digs",
".",
"Not",
"used",
"by",
"symfit",
"any",
"more",
"."
] | 759dd3d1d4270510d651f40b23dd26b1b10eee83 | https://github.com/tBuLi/symfit/blob/759dd3d1d4270510d651f40b23dd26b1b10eee83/symfit/core/support.py#L162-L188 | train |
tBuLi/symfit | symfit/core/support.py | jacobian | def jacobian(expr, symbols):
"""
Derive a symbolic expr w.r.t. each symbol in symbols. This returns a symbolic jacobian vector.
:param expr: A sympy Expr.
:param symbols: The symbols w.r.t. which to derive.
"""
jac = []
for symbol in symbols:
# Differentiate to every param
f... | python | def jacobian(expr, symbols):
"""
Derive a symbolic expr w.r.t. each symbol in symbols. This returns a symbolic jacobian vector.
:param expr: A sympy Expr.
:param symbols: The symbols w.r.t. which to derive.
"""
jac = []
for symbol in symbols:
# Differentiate to every param
f... | [
"def",
"jacobian",
"(",
"expr",
",",
"symbols",
")",
":",
"jac",
"=",
"[",
"]",
"for",
"symbol",
"in",
"symbols",
":",
"f",
"=",
"sympy",
".",
"diff",
"(",
"expr",
",",
"symbol",
")",
"jac",
".",
"append",
"(",
"f",
")",
"return",
"jac"
] | Derive a symbolic expr w.r.t. each symbol in symbols. This returns a symbolic jacobian vector.
:param expr: A sympy Expr.
:param symbols: The symbols w.r.t. which to derive. | [
"Derive",
"a",
"symbolic",
"expr",
"w",
".",
"r",
".",
"t",
".",
"each",
"symbol",
"in",
"symbols",
".",
"This",
"returns",
"a",
"symbolic",
"jacobian",
"vector",
"."
] | 759dd3d1d4270510d651f40b23dd26b1b10eee83 | https://github.com/tBuLi/symfit/blob/759dd3d1d4270510d651f40b23dd26b1b10eee83/symfit/core/support.py#L300-L312 | train |
tBuLi/symfit | symfit/core/support.py | name | def name(self):
"""
Save name which can be used for alphabetic sorting and can be turned
into a kwarg.
"""
base_str = 'd{}{}_'.format(self.derivative_count if
self.derivative_count > 1 else '', self.expr)
for var, count in self.variable_count:
base_str += '... | python | def name(self):
"""
Save name which can be used for alphabetic sorting and can be turned
into a kwarg.
"""
base_str = 'd{}{}_'.format(self.derivative_count if
self.derivative_count > 1 else '', self.expr)
for var, count in self.variable_count:
base_str += '... | [
"def",
"name",
"(",
"self",
")",
":",
"base_str",
"=",
"'d{}{}_'",
".",
"format",
"(",
"self",
".",
"derivative_count",
"if",
"self",
".",
"derivative_count",
">",
"1",
"else",
"''",
",",
"self",
".",
"expr",
")",
"for",
"var",
",",
"count",
"in",
"s... | Save name which can be used for alphabetic sorting and can be turned
into a kwarg. | [
"Save",
"name",
"which",
"can",
"be",
"used",
"for",
"alphabetic",
"sorting",
"and",
"can",
"be",
"turned",
"into",
"a",
"kwarg",
"."
] | 759dd3d1d4270510d651f40b23dd26b1b10eee83 | https://github.com/tBuLi/symfit/blob/759dd3d1d4270510d651f40b23dd26b1b10eee83/symfit/core/support.py#L433-L442 | train |
tBuLi/symfit | symfit/core/minimizers.py | BaseMinimizer._baseobjective_from_callable | def _baseobjective_from_callable(self, func, objective_type=MinimizeModel):
"""
symfit works with BaseObjective subclasses internally. If a custom
objective is provided, we wrap it into a BaseObjective, MinimizeModel by
default.
:param func: Callable. If already an instance of B... | python | def _baseobjective_from_callable(self, func, objective_type=MinimizeModel):
"""
symfit works with BaseObjective subclasses internally. If a custom
objective is provided, we wrap it into a BaseObjective, MinimizeModel by
default.
:param func: Callable. If already an instance of B... | [
"def",
"_baseobjective_from_callable",
"(",
"self",
",",
"func",
",",
"objective_type",
"=",
"MinimizeModel",
")",
":",
"if",
"isinstance",
"(",
"func",
",",
"BaseObjective",
")",
"or",
"(",
"hasattr",
"(",
"func",
",",
"'__self__'",
")",
"and",
"isinstance",
... | symfit works with BaseObjective subclasses internally. If a custom
objective is provided, we wrap it into a BaseObjective, MinimizeModel by
default.
:param func: Callable. If already an instance of BaseObjective, it is
returned immediately. If not, it is turned into a BaseObjective ... | [
"symfit",
"works",
"with",
"BaseObjective",
"subclasses",
"internally",
".",
"If",
"a",
"custom",
"objective",
"is",
"provided",
"we",
"wrap",
"it",
"into",
"a",
"BaseObjective",
"MinimizeModel",
"by",
"default",
"."
] | 759dd3d1d4270510d651f40b23dd26b1b10eee83 | https://github.com/tBuLi/symfit/blob/759dd3d1d4270510d651f40b23dd26b1b10eee83/symfit/core/minimizers.py#L44-L74 | train |
tBuLi/symfit | symfit/core/minimizers.py | GradientMinimizer.resize_jac | def resize_jac(self, func):
"""
Removes values with identical indices to fixed parameters from the
output of func. func has to return the jacobian of a scalar function.
:param func: Jacobian function to be wrapped. Is assumed to be the
jacobian of a scalar function.
... | python | def resize_jac(self, func):
"""
Removes values with identical indices to fixed parameters from the
output of func. func has to return the jacobian of a scalar function.
:param func: Jacobian function to be wrapped. Is assumed to be the
jacobian of a scalar function.
... | [
"def",
"resize_jac",
"(",
"self",
",",
"func",
")",
":",
"if",
"func",
"is",
"None",
":",
"return",
"None",
"@",
"wraps",
"(",
"func",
")",
"def",
"resized",
"(",
"*",
"args",
",",
"**",
"kwargs",
")",
":",
"out",
"=",
"func",
"(",
"*",
"args",
... | Removes values with identical indices to fixed parameters from the
output of func. func has to return the jacobian of a scalar function.
:param func: Jacobian function to be wrapped. Is assumed to be the
jacobian of a scalar function.
:return: Jacobian corresponding to non-fixed par... | [
"Removes",
"values",
"with",
"identical",
"indices",
"to",
"fixed",
"parameters",
"from",
"the",
"output",
"of",
"func",
".",
"func",
"has",
"to",
"return",
"the",
"jacobian",
"of",
"a",
"scalar",
"function",
"."
] | 759dd3d1d4270510d651f40b23dd26b1b10eee83 | https://github.com/tBuLi/symfit/blob/759dd3d1d4270510d651f40b23dd26b1b10eee83/symfit/core/minimizers.py#L143-L161 | train |
tBuLi/symfit | symfit/core/minimizers.py | HessianMinimizer.resize_hess | def resize_hess(self, func):
"""
Removes values with identical indices to fixed parameters from the
output of func. func has to return the Hessian of a scalar function.
:param func: Hessian function to be wrapped. Is assumed to be the
Hessian of a scalar function.
:r... | python | def resize_hess(self, func):
"""
Removes values with identical indices to fixed parameters from the
output of func. func has to return the Hessian of a scalar function.
:param func: Hessian function to be wrapped. Is assumed to be the
Hessian of a scalar function.
:r... | [
"def",
"resize_hess",
"(",
"self",
",",
"func",
")",
":",
"if",
"func",
"is",
"None",
":",
"return",
"None",
"@",
"wraps",
"(",
"func",
")",
"def",
"resized",
"(",
"*",
"args",
",",
"**",
"kwargs",
")",
":",
"out",
"=",
"func",
"(",
"*",
"args",
... | Removes values with identical indices to fixed parameters from the
output of func. func has to return the Hessian of a scalar function.
:param func: Hessian function to be wrapped. Is assumed to be the
Hessian of a scalar function.
:return: Hessian corresponding to free parameters o... | [
"Removes",
"values",
"with",
"identical",
"indices",
"to",
"fixed",
"parameters",
"from",
"the",
"output",
"of",
"func",
".",
"func",
"has",
"to",
"return",
"the",
"Hessian",
"of",
"a",
"scalar",
"function",
"."
] | 759dd3d1d4270510d651f40b23dd26b1b10eee83 | https://github.com/tBuLi/symfit/blob/759dd3d1d4270510d651f40b23dd26b1b10eee83/symfit/core/minimizers.py#L179-L197 | train |
tBuLi/symfit | symfit/core/minimizers.py | ScipyMinimize.execute | def execute(self, bounds=None, jacobian=None, hessian=None, constraints=None, **minimize_options):
"""
Calls the wrapped algorithm.
:param bounds: The bounds for the parameters. Usually filled by
:class:`~symfit.core.minimizers.BoundedMinimizer`.
:param jacobian: The Jacobia... | python | def execute(self, bounds=None, jacobian=None, hessian=None, constraints=None, **minimize_options):
"""
Calls the wrapped algorithm.
:param bounds: The bounds for the parameters. Usually filled by
:class:`~symfit.core.minimizers.BoundedMinimizer`.
:param jacobian: The Jacobia... | [
"def",
"execute",
"(",
"self",
",",
"bounds",
"=",
"None",
",",
"jacobian",
"=",
"None",
",",
"hessian",
"=",
"None",
",",
"constraints",
"=",
"None",
",",
"**",
"minimize_options",
")",
":",
"ans",
"=",
"minimize",
"(",
"self",
".",
"objective",
",",
... | Calls the wrapped algorithm.
:param bounds: The bounds for the parameters. Usually filled by
:class:`~symfit.core.minimizers.BoundedMinimizer`.
:param jacobian: The Jacobian. Usually filled by
:class:`~symfit.core.minimizers.ScipyGradientMinimize`.
:param \*\*minimize_op... | [
"Calls",
"the",
"wrapped",
"algorithm",
"."
] | 759dd3d1d4270510d651f40b23dd26b1b10eee83 | https://github.com/tBuLi/symfit/blob/759dd3d1d4270510d651f40b23dd26b1b10eee83/symfit/core/minimizers.py#L331-L353 | train |
tBuLi/symfit | symfit/core/minimizers.py | ScipyConstrainedMinimize.scipy_constraints | def scipy_constraints(self, constraints):
"""
Returns all constraints in a scipy compatible format.
:param constraints: List of either MinimizeModel instances (this is what
is provided by :class:`~symfit.core.fit.Fit`),
:class:`~symfit.core.fit.BaseModel`, or
:clas... | python | def scipy_constraints(self, constraints):
"""
Returns all constraints in a scipy compatible format.
:param constraints: List of either MinimizeModel instances (this is what
is provided by :class:`~symfit.core.fit.Fit`),
:class:`~symfit.core.fit.BaseModel`, or
:clas... | [
"def",
"scipy_constraints",
"(",
"self",
",",
"constraints",
")",
":",
"cons",
"=",
"[",
"]",
"types",
"=",
"{",
"sympy",
".",
"Eq",
":",
"'eq'",
",",
"sympy",
".",
"Ge",
":",
"'ineq'",
",",
"}",
"for",
"constraint",
"in",
"constraints",
":",
"if",
... | Returns all constraints in a scipy compatible format.
:param constraints: List of either MinimizeModel instances (this is what
is provided by :class:`~symfit.core.fit.Fit`),
:class:`~symfit.core.fit.BaseModel`, or
:class:`sympy.core.relational.Relational`.
:return: dict of... | [
"Returns",
"all",
"constraints",
"in",
"a",
"scipy",
"compatible",
"format",
"."
] | 759dd3d1d4270510d651f40b23dd26b1b10eee83 | https://github.com/tBuLi/symfit/blob/759dd3d1d4270510d651f40b23dd26b1b10eee83/symfit/core/minimizers.py#L477-L517 | train |
tBuLi/symfit | symfit/core/minimizers.py | TrustConstr._get_jacobian_hessian_strategy | def _get_jacobian_hessian_strategy(self):
"""
Figure out how to calculate the jacobian and hessian. Will return a
tuple describing how best to calculate the jacobian and hessian,
repectively. If None, it should be calculated using the available
analytical method.
:return... | python | def _get_jacobian_hessian_strategy(self):
"""
Figure out how to calculate the jacobian and hessian. Will return a
tuple describing how best to calculate the jacobian and hessian,
repectively. If None, it should be calculated using the available
analytical method.
:return... | [
"def",
"_get_jacobian_hessian_strategy",
"(",
"self",
")",
":",
"if",
"self",
".",
"jacobian",
"is",
"not",
"None",
"and",
"self",
".",
"hessian",
"is",
"None",
":",
"jacobian",
"=",
"None",
"hessian",
"=",
"'cs'",
"elif",
"self",
".",
"jacobian",
"is",
... | Figure out how to calculate the jacobian and hessian. Will return a
tuple describing how best to calculate the jacobian and hessian,
repectively. If None, it should be calculated using the available
analytical method.
:return: tuple of jacobian_method, hessian_method | [
"Figure",
"out",
"how",
"to",
"calculate",
"the",
"jacobian",
"and",
"hessian",
".",
"Will",
"return",
"a",
"tuple",
"describing",
"how",
"best",
"to",
"calculate",
"the",
"jacobian",
"and",
"hessian",
"repectively",
".",
"If",
"None",
"it",
"should",
"be",
... | 759dd3d1d4270510d651f40b23dd26b1b10eee83 | https://github.com/tBuLi/symfit/blob/759dd3d1d4270510d651f40b23dd26b1b10eee83/symfit/core/minimizers.py#L566-L584 | train |
tBuLi/symfit | symfit/core/minimizers.py | BasinHopping.execute | def execute(self, **minimize_options):
"""
Execute the basin-hopping minimization.
:param minimize_options: options to be passed on to
:func:`scipy.optimize.basinhopping`.
:return: :class:`symfit.core.fit_results.FitResults`
"""
if 'minimizer_kwargs' not in m... | python | def execute(self, **minimize_options):
"""
Execute the basin-hopping minimization.
:param minimize_options: options to be passed on to
:func:`scipy.optimize.basinhopping`.
:return: :class:`symfit.core.fit_results.FitResults`
"""
if 'minimizer_kwargs' not in m... | [
"def",
"execute",
"(",
"self",
",",
"**",
"minimize_options",
")",
":",
"if",
"'minimizer_kwargs'",
"not",
"in",
"minimize_options",
":",
"minimize_options",
"[",
"'minimizer_kwargs'",
"]",
"=",
"{",
"}",
"if",
"'method'",
"not",
"in",
"minimize_options",
"[",
... | Execute the basin-hopping minimization.
:param minimize_options: options to be passed on to
:func:`scipy.optimize.basinhopping`.
:return: :class:`symfit.core.fit_results.FitResults` | [
"Execute",
"the",
"basin",
"-",
"hopping",
"minimization",
"."
] | 759dd3d1d4270510d651f40b23dd26b1b10eee83 | https://github.com/tBuLi/symfit/blob/759dd3d1d4270510d651f40b23dd26b1b10eee83/symfit/core/minimizers.py#L719-L748 | train |
tBuLi/symfit | symfit/core/printing.py | SymfitNumPyPrinter._print_MatMul | def _print_MatMul(self, expr):
"""
Matrix multiplication printer. The sympy one turns everything into a
dot product without type-checking.
"""
from sympy import MatrixExpr
links = []
for i, j in zip(expr.args[1:], expr.args[:-1]):
if isinstance(i, Matr... | python | def _print_MatMul(self, expr):
"""
Matrix multiplication printer. The sympy one turns everything into a
dot product without type-checking.
"""
from sympy import MatrixExpr
links = []
for i, j in zip(expr.args[1:], expr.args[:-1]):
if isinstance(i, Matr... | [
"def",
"_print_MatMul",
"(",
"self",
",",
"expr",
")",
":",
"from",
"sympy",
"import",
"MatrixExpr",
"links",
"=",
"[",
"]",
"for",
"i",
",",
"j",
"in",
"zip",
"(",
"expr",
".",
"args",
"[",
"1",
":",
"]",
",",
"expr",
".",
"args",
"[",
":",
"-... | Matrix multiplication printer. The sympy one turns everything into a
dot product without type-checking. | [
"Matrix",
"multiplication",
"printer",
".",
"The",
"sympy",
"one",
"turns",
"everything",
"into",
"a",
"dot",
"product",
"without",
"type",
"-",
"checking",
"."
] | 759dd3d1d4270510d651f40b23dd26b1b10eee83 | https://github.com/tBuLi/symfit/blob/759dd3d1d4270510d651f40b23dd26b1b10eee83/symfit/core/printing.py#L34-L50 | train |
tBuLi/symfit | symfit/contrib/interactive_guess/interactive_guess.py | InteractiveGuess.execute | def execute(self, **kwargs):
"""
Execute the interactive guessing procedure.
:param show: Whether or not to show the figure. Useful for testing.
:type show: bool
:param block: Blocking call to matplotlib
:type show: bool
Any additional keyword arguments are pass... | python | def execute(self, **kwargs):
"""
Execute the interactive guessing procedure.
:param show: Whether or not to show the figure. Useful for testing.
:type show: bool
:param block: Blocking call to matplotlib
:type show: bool
Any additional keyword arguments are pass... | [
"def",
"execute",
"(",
"self",
",",
"**",
"kwargs",
")",
":",
"show",
"=",
"kwargs",
".",
"pop",
"(",
"'show'",
")",
"if",
"show",
":",
"plt",
".",
"show",
"(",
"**",
"kwargs",
")"
] | Execute the interactive guessing procedure.
:param show: Whether or not to show the figure. Useful for testing.
:type show: bool
:param block: Blocking call to matplotlib
:type show: bool
Any additional keyword arguments are passed to
matplotlib.pyplot.show(). | [
"Execute",
"the",
"interactive",
"guessing",
"procedure",
"."
] | 759dd3d1d4270510d651f40b23dd26b1b10eee83 | https://github.com/tBuLi/symfit/blob/759dd3d1d4270510d651f40b23dd26b1b10eee83/symfit/contrib/interactive_guess/interactive_guess.py#L99-L115 | train |
tBuLi/symfit | symfit/contrib/interactive_guess/interactive_guess.py | InteractiveGuess._set_up_sliders | def _set_up_sliders(self):
"""
Creates an slider for every parameter.
"""
i = 0.05
self._sliders = {}
for param in self.model.params:
if not param.fixed:
axbg = 'lightgoldenrodyellow'
else:
axbg = 'red'
#... | python | def _set_up_sliders(self):
"""
Creates an slider for every parameter.
"""
i = 0.05
self._sliders = {}
for param in self.model.params:
if not param.fixed:
axbg = 'lightgoldenrodyellow'
else:
axbg = 'red'
#... | [
"def",
"_set_up_sliders",
"(",
"self",
")",
":",
"i",
"=",
"0.05",
"self",
".",
"_sliders",
"=",
"{",
"}",
"for",
"param",
"in",
"self",
".",
"model",
".",
"params",
":",
"if",
"not",
"param",
".",
"fixed",
":",
"axbg",
"=",
"'lightgoldenrodyellow'",
... | Creates an slider for every parameter. | [
"Creates",
"an",
"slider",
"for",
"every",
"parameter",
"."
] | 759dd3d1d4270510d651f40b23dd26b1b10eee83 | https://github.com/tBuLi/symfit/blob/759dd3d1d4270510d651f40b23dd26b1b10eee83/symfit/contrib/interactive_guess/interactive_guess.py#L158-L186 | train |
tBuLi/symfit | symfit/contrib/interactive_guess/interactive_guess.py | InteractiveGuess._update_plot | def _update_plot(self, _):
"""Callback to redraw the plot to reflect the new parameter values."""
# Since all sliders call this same callback without saying who they are
# I need to update the values for all parameters. This can be
# circumvented by creating a seperate callback function ... | python | def _update_plot(self, _):
"""Callback to redraw the plot to reflect the new parameter values."""
# Since all sliders call this same callback without saying who they are
# I need to update the values for all parameters. This can be
# circumvented by creating a seperate callback function ... | [
"def",
"_update_plot",
"(",
"self",
",",
"_",
")",
":",
"for",
"param",
"in",
"self",
".",
"model",
".",
"params",
":",
"param",
".",
"value",
"=",
"self",
".",
"_sliders",
"[",
"param",
"]",
".",
"val",
"for",
"indep_var",
",",
"dep_var",
"in",
"s... | Callback to redraw the plot to reflect the new parameter values. | [
"Callback",
"to",
"redraw",
"the",
"plot",
"to",
"reflect",
"the",
"new",
"parameter",
"values",
"."
] | 759dd3d1d4270510d651f40b23dd26b1b10eee83 | https://github.com/tBuLi/symfit/blob/759dd3d1d4270510d651f40b23dd26b1b10eee83/symfit/contrib/interactive_guess/interactive_guess.py#L200-L209 | train |
tBuLi/symfit | symfit/contrib/interactive_guess/interactive_guess.py | InteractiveGuess._eval_model | def _eval_model(self):
"""
Convenience method for evaluating the model with the current parameters
:return: named tuple with results
"""
arguments = self._x_grid.copy()
arguments.update({param: param.value for param in self.model.params})
return self.model(**key2... | python | def _eval_model(self):
"""
Convenience method for evaluating the model with the current parameters
:return: named tuple with results
"""
arguments = self._x_grid.copy()
arguments.update({param: param.value for param in self.model.params})
return self.model(**key2... | [
"def",
"_eval_model",
"(",
"self",
")",
":",
"arguments",
"=",
"self",
".",
"_x_grid",
".",
"copy",
"(",
")",
"arguments",
".",
"update",
"(",
"{",
"param",
":",
"param",
".",
"value",
"for",
"param",
"in",
"self",
".",
"model",
".",
"params",
"}",
... | Convenience method for evaluating the model with the current parameters
:return: named tuple with results | [
"Convenience",
"method",
"for",
"evaluating",
"the",
"model",
"with",
"the",
"current",
"parameters"
] | 759dd3d1d4270510d651f40b23dd26b1b10eee83 | https://github.com/tBuLi/symfit/blob/759dd3d1d4270510d651f40b23dd26b1b10eee83/symfit/contrib/interactive_guess/interactive_guess.py#L211-L219 | train |
tBuLi/symfit | symfit/contrib/interactive_guess/interactive_guess.py | Strategy2D.plot_data | def plot_data(self, proj, ax):
"""
Creates and plots a scatter plot of the original data.
"""
x, y = proj
ax.scatter(self.ig.independent_data[x],
self.ig.dependent_data[y], c='b') | python | def plot_data(self, proj, ax):
"""
Creates and plots a scatter plot of the original data.
"""
x, y = proj
ax.scatter(self.ig.independent_data[x],
self.ig.dependent_data[y], c='b') | [
"def",
"plot_data",
"(",
"self",
",",
"proj",
",",
"ax",
")",
":",
"x",
",",
"y",
"=",
"proj",
"ax",
".",
"scatter",
"(",
"self",
".",
"ig",
".",
"independent_data",
"[",
"x",
"]",
",",
"self",
".",
"ig",
".",
"dependent_data",
"[",
"y",
"]",
"... | Creates and plots a scatter plot of the original data. | [
"Creates",
"and",
"plots",
"a",
"scatter",
"plot",
"of",
"the",
"original",
"data",
"."
] | 759dd3d1d4270510d651f40b23dd26b1b10eee83 | https://github.com/tBuLi/symfit/blob/759dd3d1d4270510d651f40b23dd26b1b10eee83/symfit/contrib/interactive_guess/interactive_guess.py#L241-L247 | train |
tBuLi/symfit | symfit/contrib/interactive_guess/interactive_guess.py | StrategynD.plot_data | def plot_data(self, proj, ax):
"""
Creates and plots the contourplot of the original data. This is done
by evaluating the density of projected datapoints on a grid.
"""
x, y = proj
x_data = self.ig.independent_data[x]
y_data = self.ig.dependent_data[y]
pro... | python | def plot_data(self, proj, ax):
"""
Creates and plots the contourplot of the original data. This is done
by evaluating the density of projected datapoints on a grid.
"""
x, y = proj
x_data = self.ig.independent_data[x]
y_data = self.ig.dependent_data[y]
pro... | [
"def",
"plot_data",
"(",
"self",
",",
"proj",
",",
"ax",
")",
":",
"x",
",",
"y",
"=",
"proj",
"x_data",
"=",
"self",
".",
"ig",
".",
"independent_data",
"[",
"x",
"]",
"y_data",
"=",
"self",
".",
"ig",
".",
"dependent_data",
"[",
"y",
"]",
"proj... | Creates and plots the contourplot of the original data. This is done
by evaluating the density of projected datapoints on a grid. | [
"Creates",
"and",
"plots",
"the",
"contourplot",
"of",
"the",
"original",
"data",
".",
"This",
"is",
"done",
"by",
"evaluating",
"the",
"density",
"of",
"projected",
"datapoints",
"on",
"a",
"grid",
"."
] | 759dd3d1d4270510d651f40b23dd26b1b10eee83 | https://github.com/tBuLi/symfit/blob/759dd3d1d4270510d651f40b23dd26b1b10eee83/symfit/contrib/interactive_guess/interactive_guess.py#L278-L302 | train |
tBuLi/symfit | symfit/distributions.py | BivariateGaussian | def BivariateGaussian(x, y, mu_x, mu_y, sig_x, sig_y, rho):
"""
Bivariate Gaussian pdf.
:param x: :class:`symfit.core.argument.Variable`
:param y: :class:`symfit.core.argument.Variable`
:param mu_x: :class:`symfit.core.argument.Parameter` for the mean of `x`
:param mu_y: :class:`symfit.core.arg... | python | def BivariateGaussian(x, y, mu_x, mu_y, sig_x, sig_y, rho):
"""
Bivariate Gaussian pdf.
:param x: :class:`symfit.core.argument.Variable`
:param y: :class:`symfit.core.argument.Variable`
:param mu_x: :class:`symfit.core.argument.Parameter` for the mean of `x`
:param mu_y: :class:`symfit.core.arg... | [
"def",
"BivariateGaussian",
"(",
"x",
",",
"y",
",",
"mu_x",
",",
"mu_y",
",",
"sig_x",
",",
"sig_y",
",",
"rho",
")",
":",
"exponent",
"=",
"-",
"1",
"/",
"(",
"2",
"*",
"(",
"1",
"-",
"rho",
"**",
"2",
")",
")",
"exponent",
"*=",
"(",
"x",
... | Bivariate Gaussian pdf.
:param x: :class:`symfit.core.argument.Variable`
:param y: :class:`symfit.core.argument.Variable`
:param mu_x: :class:`symfit.core.argument.Parameter` for the mean of `x`
:param mu_y: :class:`symfit.core.argument.Parameter` for the mean of `y`
:param sig_x: :class:`symfit.co... | [
"Bivariate",
"Gaussian",
"pdf",
"."
] | 759dd3d1d4270510d651f40b23dd26b1b10eee83 | https://github.com/tBuLi/symfit/blob/759dd3d1d4270510d651f40b23dd26b1b10eee83/symfit/distributions.py#L21-L40 | train |
tBuLi/symfit | symfit/core/fit.py | r_squared | def r_squared(model, fit_result, data):
"""
Calculates the coefficient of determination, R^2, for the fit.
(Is not defined properly for vector valued functions.)
:param model: Model instance
:param fit_result: FitResults instance
:param data: data with which the fit was performed.
"""
... | python | def r_squared(model, fit_result, data):
"""
Calculates the coefficient of determination, R^2, for the fit.
(Is not defined properly for vector valued functions.)
:param model: Model instance
:param fit_result: FitResults instance
:param data: data with which the fit was performed.
"""
... | [
"def",
"r_squared",
"(",
"model",
",",
"fit_result",
",",
"data",
")",
":",
"y_is",
"=",
"[",
"data",
"[",
"var",
"]",
"for",
"var",
"in",
"model",
"if",
"var",
"in",
"data",
"]",
"x_is",
"=",
"[",
"value",
"for",
"var",
",",
"value",
"in",
"data... | Calculates the coefficient of determination, R^2, for the fit.
(Is not defined properly for vector valued functions.)
:param model: Model instance
:param fit_result: FitResults instance
:param data: data with which the fit was performed. | [
"Calculates",
"the",
"coefficient",
"of",
"determination",
"R^2",
"for",
"the",
"fit",
"."
] | 759dd3d1d4270510d651f40b23dd26b1b10eee83 | https://github.com/tBuLi/symfit/blob/759dd3d1d4270510d651f40b23dd26b1b10eee83/symfit/core/fit.py#L1431-L1448 | train |
tBuLi/symfit | symfit/core/fit.py | _partial_subs | def _partial_subs(func, func2vars):
"""
Partial-bug proof substitution. Works by making the substitutions on
the expression inside the derivative first, and then rebuilding the
derivative safely without evaluating it using `_partial_diff`.
"""
if isinstance(func, sympy.Derivative):
new_f... | python | def _partial_subs(func, func2vars):
"""
Partial-bug proof substitution. Works by making the substitutions on
the expression inside the derivative first, and then rebuilding the
derivative safely without evaluating it using `_partial_diff`.
"""
if isinstance(func, sympy.Derivative):
new_f... | [
"def",
"_partial_subs",
"(",
"func",
",",
"func2vars",
")",
":",
"if",
"isinstance",
"(",
"func",
",",
"sympy",
".",
"Derivative",
")",
":",
"new_func",
"=",
"func",
".",
"expr",
".",
"xreplace",
"(",
"func2vars",
")",
"new_variables",
"=",
"tuple",
"(",... | Partial-bug proof substitution. Works by making the substitutions on
the expression inside the derivative first, and then rebuilding the
derivative safely without evaluating it using `_partial_diff`. | [
"Partial",
"-",
"bug",
"proof",
"substitution",
".",
"Works",
"by",
"making",
"the",
"substitutions",
"on",
"the",
"expression",
"inside",
"the",
"derivative",
"first",
"and",
"then",
"rebuilding",
"the",
"derivative",
"safely",
"without",
"evaluating",
"it",
"u... | 759dd3d1d4270510d651f40b23dd26b1b10eee83 | https://github.com/tBuLi/symfit/blob/759dd3d1d4270510d651f40b23dd26b1b10eee83/symfit/core/fit.py#L1693-L1705 | train |
tBuLi/symfit | symfit/core/fit.py | BaseModel._init_from_dict | def _init_from_dict(self, model_dict):
"""
Initiate self from a model_dict to make sure attributes such as vars, params are available.
Creates lists of alphabetically sorted independent vars, dependent vars, sigma vars, and parameters.
Finally it creates a signature for this model so it... | python | def _init_from_dict(self, model_dict):
"""
Initiate self from a model_dict to make sure attributes such as vars, params are available.
Creates lists of alphabetically sorted independent vars, dependent vars, sigma vars, and parameters.
Finally it creates a signature for this model so it... | [
"def",
"_init_from_dict",
"(",
"self",
",",
"model_dict",
")",
":",
"sort_func",
"=",
"lambda",
"symbol",
":",
"symbol",
".",
"name",
"self",
".",
"model_dict",
"=",
"OrderedDict",
"(",
"sorted",
"(",
"model_dict",
".",
"items",
"(",
")",
",",
"key",
"="... | Initiate self from a model_dict to make sure attributes such as vars, params are available.
Creates lists of alphabetically sorted independent vars, dependent vars, sigma vars, and parameters.
Finally it creates a signature for this model so it can be called nicely. This signature only contains
... | [
"Initiate",
"self",
"from",
"a",
"model_dict",
"to",
"make",
"sure",
"attributes",
"such",
"as",
"vars",
"params",
"are",
"available",
"."
] | 759dd3d1d4270510d651f40b23dd26b1b10eee83 | https://github.com/tBuLi/symfit/blob/759dd3d1d4270510d651f40b23dd26b1b10eee83/symfit/core/fit.py#L273-L310 | train |
tBuLi/symfit | symfit/core/fit.py | BaseModel.function_dict | def function_dict(self):
"""
Equivalent to ``self.model_dict``, but with all variables replaced by
functions if applicable. Sorted by the evaluation order according to
``self.ordered_symbols``, not alphabetical like ``self.model_dict``!
"""
func_dict = OrderedDict()
... | python | def function_dict(self):
"""
Equivalent to ``self.model_dict``, but with all variables replaced by
functions if applicable. Sorted by the evaluation order according to
``self.ordered_symbols``, not alphabetical like ``self.model_dict``!
"""
func_dict = OrderedDict()
... | [
"def",
"function_dict",
"(",
"self",
")",
":",
"func_dict",
"=",
"OrderedDict",
"(",
")",
"for",
"var",
",",
"func",
"in",
"self",
".",
"vars_as_functions",
".",
"items",
"(",
")",
":",
"expr",
"=",
"self",
".",
"model_dict",
"[",
"var",
"]",
".",
"x... | Equivalent to ``self.model_dict``, but with all variables replaced by
functions if applicable. Sorted by the evaluation order according to
``self.ordered_symbols``, not alphabetical like ``self.model_dict``! | [
"Equivalent",
"to",
"self",
".",
"model_dict",
"but",
"with",
"all",
"variables",
"replaced",
"by",
"functions",
"if",
"applicable",
".",
"Sorted",
"by",
"the",
"evaluation",
"order",
"according",
"to",
"self",
".",
"ordered_symbols",
"not",
"alphabetical",
"lik... | 759dd3d1d4270510d651f40b23dd26b1b10eee83 | https://github.com/tBuLi/symfit/blob/759dd3d1d4270510d651f40b23dd26b1b10eee83/symfit/core/fit.py#L340-L350 | train |
tBuLi/symfit | symfit/core/fit.py | TakesData._model_sanity | def _model_sanity(model):
"""
Perform some basic sanity checking on the model to warn users when they
might be trying something ill advised.
:param model: model instance.
"""
if not isinstance(model, ODEModel) and not isinstance(model, BaseNumericalModel):
# ... | python | def _model_sanity(model):
"""
Perform some basic sanity checking on the model to warn users when they
might be trying something ill advised.
:param model: model instance.
"""
if not isinstance(model, ODEModel) and not isinstance(model, BaseNumericalModel):
# ... | [
"def",
"_model_sanity",
"(",
"model",
")",
":",
"if",
"not",
"isinstance",
"(",
"model",
",",
"ODEModel",
")",
"and",
"not",
"isinstance",
"(",
"model",
",",
"BaseNumericalModel",
")",
":",
"for",
"var",
",",
"expr",
"in",
"model",
".",
"items",
"(",
"... | Perform some basic sanity checking on the model to warn users when they
might be trying something ill advised.
:param model: model instance. | [
"Perform",
"some",
"basic",
"sanity",
"checking",
"on",
"the",
"model",
"to",
"warn",
"users",
"when",
"they",
"might",
"be",
"trying",
"something",
"ill",
"advised",
"."
] | 759dd3d1d4270510d651f40b23dd26b1b10eee83 | https://github.com/tBuLi/symfit/blob/759dd3d1d4270510d651f40b23dd26b1b10eee83/symfit/core/fit.py#L1014-L1028 | train |
tBuLi/symfit | symfit/core/fit.py | TakesData.data_shapes | def data_shapes(self):
"""
Returns the shape of the data. In most cases this will be the same for
all variables of the same type, if not this raises an Exception.
Ignores variables which are set to None by design so we know that those
None variables can be assumed to have the sa... | python | def data_shapes(self):
"""
Returns the shape of the data. In most cases this will be the same for
all variables of the same type, if not this raises an Exception.
Ignores variables which are set to None by design so we know that those
None variables can be assumed to have the sa... | [
"def",
"data_shapes",
"(",
"self",
")",
":",
"independent_shapes",
"=",
"[",
"]",
"for",
"var",
",",
"data",
"in",
"self",
".",
"independent_data",
".",
"items",
"(",
")",
":",
"if",
"data",
"is",
"not",
"None",
":",
"independent_shapes",
".",
"append",
... | Returns the shape of the data. In most cases this will be the same for
all variables of the same type, if not this raises an Exception.
Ignores variables which are set to None by design so we know that those
None variables can be assumed to have the same shape as the other in
calculatio... | [
"Returns",
"the",
"shape",
"of",
"the",
"data",
".",
"In",
"most",
"cases",
"this",
"will",
"be",
"the",
"same",
"for",
"all",
"variables",
"of",
"the",
"same",
"type",
"if",
"not",
"this",
"raises",
"an",
"Exception",
"."
] | 759dd3d1d4270510d651f40b23dd26b1b10eee83 | https://github.com/tBuLi/symfit/blob/759dd3d1d4270510d651f40b23dd26b1b10eee83/symfit/core/fit.py#L1067-L1088 | train |
tBuLi/symfit | symfit/core/fit.py | Fit.execute | def execute(self, **minimize_options):
"""
Execute the fit.
:param minimize_options: keyword arguments to be passed to the specified
minimizer.
:return: FitResults instance
"""
minimizer_ans = self.minimizer.execute(**minimize_options)
try: # to build... | python | def execute(self, **minimize_options):
"""
Execute the fit.
:param minimize_options: keyword arguments to be passed to the specified
minimizer.
:return: FitResults instance
"""
minimizer_ans = self.minimizer.execute(**minimize_options)
try: # to build... | [
"def",
"execute",
"(",
"self",
",",
"**",
"minimize_options",
")",
":",
"minimizer_ans",
"=",
"self",
".",
"minimizer",
".",
"execute",
"(",
"**",
"minimize_options",
")",
"try",
":",
"cov_matrix",
"=",
"minimizer_ans",
".",
"covariance_matrix",
"except",
"Att... | Execute the fit.
:param minimize_options: keyword arguments to be passed to the specified
minimizer.
:return: FitResults instance | [
"Execute",
"the",
"fit",
"."
] | 759dd3d1d4270510d651f40b23dd26b1b10eee83 | https://github.com/tBuLi/symfit/blob/759dd3d1d4270510d651f40b23dd26b1b10eee83/symfit/core/fit.py#L1407-L1428 | train |
tBuLi/symfit | symfit/core/fit.py | ODEModel.eval_components | def eval_components(self, *args, **kwargs):
"""
Numerically integrate the system of ODEs.
:param args: Ordered arguments for the parameters and independent
variables
:param kwargs: Keyword arguments for the parameters and independent
variables
:return:
... | python | def eval_components(self, *args, **kwargs):
"""
Numerically integrate the system of ODEs.
:param args: Ordered arguments for the parameters and independent
variables
:param kwargs: Keyword arguments for the parameters and independent
variables
:return:
... | [
"def",
"eval_components",
"(",
"self",
",",
"*",
"args",
",",
"**",
"kwargs",
")",
":",
"bound_arguments",
"=",
"self",
".",
"__signature__",
".",
"bind",
"(",
"*",
"args",
",",
"**",
"kwargs",
")",
"t_like",
"=",
"bound_arguments",
".",
"arguments",
"["... | Numerically integrate the system of ODEs.
:param args: Ordered arguments for the parameters and independent
variables
:param kwargs: Keyword arguments for the parameters and independent
variables
:return: | [
"Numerically",
"integrate",
"the",
"system",
"of",
"ODEs",
"."
] | 759dd3d1d4270510d651f40b23dd26b1b10eee83 | https://github.com/tBuLi/symfit/blob/759dd3d1d4270510d651f40b23dd26b1b10eee83/symfit/core/fit.py#L1590-L1660 | train |
tBuLi/symfit | symfit/core/operators.py | call | def call(self, *values, **named_values):
"""
Call an expression to evaluate it at the given point.
Future improvements: I would like if func and signature could be buffered after the
first call so they don't have to be recalculated for every call. However, nothing
can be stored on self as sympy use... | python | def call(self, *values, **named_values):
"""
Call an expression to evaluate it at the given point.
Future improvements: I would like if func and signature could be buffered after the
first call so they don't have to be recalculated for every call. However, nothing
can be stored on self as sympy use... | [
"def",
"call",
"(",
"self",
",",
"*",
"values",
",",
"**",
"named_values",
")",
":",
"independent_vars",
",",
"params",
"=",
"seperate_symbols",
"(",
"self",
")",
"func",
"=",
"sympy_to_py",
"(",
"self",
",",
"independent_vars",
"+",
"params",
")",
"parame... | Call an expression to evaluate it at the given point.
Future improvements: I would like if func and signature could be buffered after the
first call so they don't have to be recalculated for every call. However, nothing
can be stored on self as sympy uses __slots__ for efficiency. This means there is no
... | [
"Call",
"an",
"expression",
"to",
"evaluate",
"it",
"at",
"the",
"given",
"point",
"."
] | 759dd3d1d4270510d651f40b23dd26b1b10eee83 | https://github.com/tBuLi/symfit/blob/759dd3d1d4270510d651f40b23dd26b1b10eee83/symfit/core/operators.py#L48-L92 | train |
tBuLi/symfit | symfit/core/fit_results.py | FitResults.variance | def variance(self, param):
"""
Return the variance in a given parameter as found by the fit.
:param param: ``Parameter`` Instance.
:return: Variance of ``param``.
"""
param_number = self.model.params.index(param)
try:
return self.covariance_matrix[par... | python | def variance(self, param):
"""
Return the variance in a given parameter as found by the fit.
:param param: ``Parameter`` Instance.
:return: Variance of ``param``.
"""
param_number = self.model.params.index(param)
try:
return self.covariance_matrix[par... | [
"def",
"variance",
"(",
"self",
",",
"param",
")",
":",
"param_number",
"=",
"self",
".",
"model",
".",
"params",
".",
"index",
"(",
"param",
")",
"try",
":",
"return",
"self",
".",
"covariance_matrix",
"[",
"param_number",
",",
"param_number",
"]",
"exc... | Return the variance in a given parameter as found by the fit.
:param param: ``Parameter`` Instance.
:return: Variance of ``param``. | [
"Return",
"the",
"variance",
"in",
"a",
"given",
"parameter",
"as",
"found",
"by",
"the",
"fit",
"."
] | 759dd3d1d4270510d651f40b23dd26b1b10eee83 | https://github.com/tBuLi/symfit/blob/759dd3d1d4270510d651f40b23dd26b1b10eee83/symfit/core/fit_results.py#L99-L111 | train |
tBuLi/symfit | symfit/core/fit_results.py | FitResults.covariance | def covariance(self, param_1, param_2):
"""
Return the covariance between param_1 and param_2.
:param param_1: ``Parameter`` Instance.
:param param_2: ``Parameter`` Instance.
:return: Covariance of the two params.
"""
param_1_number = self.model.params.index(para... | python | def covariance(self, param_1, param_2):
"""
Return the covariance between param_1 and param_2.
:param param_1: ``Parameter`` Instance.
:param param_2: ``Parameter`` Instance.
:return: Covariance of the two params.
"""
param_1_number = self.model.params.index(para... | [
"def",
"covariance",
"(",
"self",
",",
"param_1",
",",
"param_2",
")",
":",
"param_1_number",
"=",
"self",
".",
"model",
".",
"params",
".",
"index",
"(",
"param_1",
")",
"param_2_number",
"=",
"self",
".",
"model",
".",
"params",
".",
"index",
"(",
"p... | Return the covariance between param_1 and param_2.
:param param_1: ``Parameter`` Instance.
:param param_2: ``Parameter`` Instance.
:return: Covariance of the two params. | [
"Return",
"the",
"covariance",
"between",
"param_1",
"and",
"param_2",
"."
] | 759dd3d1d4270510d651f40b23dd26b1b10eee83 | https://github.com/tBuLi/symfit/blob/759dd3d1d4270510d651f40b23dd26b1b10eee83/symfit/core/fit_results.py#L113-L123 | train |
tBuLi/symfit | symfit/core/fit_results.py | FitResults._array_safe_dict_eq | def _array_safe_dict_eq(one_dict, other_dict):
"""
Dicts containing arrays are hard to compare. This function uses
numpy.allclose to compare arrays, and does normal comparison for all
other types.
:param one_dict:
:param other_dict:
:return: bool
"""
... | python | def _array_safe_dict_eq(one_dict, other_dict):
"""
Dicts containing arrays are hard to compare. This function uses
numpy.allclose to compare arrays, and does normal comparison for all
other types.
:param one_dict:
:param other_dict:
:return: bool
"""
... | [
"def",
"_array_safe_dict_eq",
"(",
"one_dict",
",",
"other_dict",
")",
":",
"for",
"key",
"in",
"one_dict",
":",
"try",
":",
"assert",
"one_dict",
"[",
"key",
"]",
"==",
"other_dict",
"[",
"key",
"]",
"except",
"ValueError",
"as",
"err",
":",
"if",
"isin... | Dicts containing arrays are hard to compare. This function uses
numpy.allclose to compare arrays, and does normal comparison for all
other types.
:param one_dict:
:param other_dict:
:return: bool | [
"Dicts",
"containing",
"arrays",
"are",
"hard",
"to",
"compare",
".",
"This",
"function",
"uses",
"numpy",
".",
"allclose",
"to",
"compare",
"arrays",
"and",
"does",
"normal",
"comparison",
"for",
"all",
"other",
"types",
"."
] | 759dd3d1d4270510d651f40b23dd26b1b10eee83 | https://github.com/tBuLi/symfit/blob/759dd3d1d4270510d651f40b23dd26b1b10eee83/symfit/core/fit_results.py#L126-L147 | train |
tBuLi/symfit | examples/callable_numerical_model.py | nonanalytical_func | def nonanalytical_func(x, a, b):
"""
This can be any pythonic function which should be fitted, typically one
which is not easily written or supported as an analytical expression.
"""
# Do your non-trivial magic here. In this case a Piecewise, although this
# could also be done symbolically.
... | python | def nonanalytical_func(x, a, b):
"""
This can be any pythonic function which should be fitted, typically one
which is not easily written or supported as an analytical expression.
"""
# Do your non-trivial magic here. In this case a Piecewise, although this
# could also be done symbolically.
... | [
"def",
"nonanalytical_func",
"(",
"x",
",",
"a",
",",
"b",
")",
":",
"y",
"=",
"np",
".",
"zeros_like",
"(",
"x",
")",
"y",
"[",
"x",
">",
"b",
"]",
"=",
"(",
"a",
"*",
"(",
"x",
"-",
"b",
")",
"+",
"b",
")",
"[",
"x",
">",
"b",
"]",
... | This can be any pythonic function which should be fitted, typically one
which is not easily written or supported as an analytical expression. | [
"This",
"can",
"be",
"any",
"pythonic",
"function",
"which",
"should",
"be",
"fitted",
"typically",
"one",
"which",
"is",
"not",
"easily",
"written",
"or",
"supported",
"as",
"an",
"analytical",
"expression",
"."
] | 759dd3d1d4270510d651f40b23dd26b1b10eee83 | https://github.com/tBuLi/symfit/blob/759dd3d1d4270510d651f40b23dd26b1b10eee83/examples/callable_numerical_model.py#L5-L15 | train |
mixcloud/django-experiments | experiments/admin.py | ExperimentAdmin.get_form | def get_form(self, request, obj=None, **kwargs):
"""
Add the default alternative dropdown with appropriate choices
"""
if obj:
if obj.alternatives:
choices = [(alternative, alternative) for alternative in obj.alternatives.keys()]
else:
... | python | def get_form(self, request, obj=None, **kwargs):
"""
Add the default alternative dropdown with appropriate choices
"""
if obj:
if obj.alternatives:
choices = [(alternative, alternative) for alternative in obj.alternatives.keys()]
else:
... | [
"def",
"get_form",
"(",
"self",
",",
"request",
",",
"obj",
"=",
"None",
",",
"**",
"kwargs",
")",
":",
"if",
"obj",
":",
"if",
"obj",
".",
"alternatives",
":",
"choices",
"=",
"[",
"(",
"alternative",
",",
"alternative",
")",
"for",
"alternative",
"... | Add the default alternative dropdown with appropriate choices | [
"Add",
"the",
"default",
"alternative",
"dropdown",
"with",
"appropriate",
"choices"
] | 1f45e9f8a108b51e44918daa647269b2b8d43f1d | https://github.com/mixcloud/django-experiments/blob/1f45e9f8a108b51e44918daa647269b2b8d43f1d/experiments/admin.py#L46-L61 | train |
mixcloud/django-experiments | experiments/admin.py | ExperimentAdmin.set_alternative_view | def set_alternative_view(self, request):
"""
Allows the admin user to change their assigned alternative
"""
if not request.user.has_perm('experiments.change_experiment'):
return HttpResponseForbidden()
experiment_name = request.POST.get("experiment")
alternat... | python | def set_alternative_view(self, request):
"""
Allows the admin user to change their assigned alternative
"""
if not request.user.has_perm('experiments.change_experiment'):
return HttpResponseForbidden()
experiment_name = request.POST.get("experiment")
alternat... | [
"def",
"set_alternative_view",
"(",
"self",
",",
"request",
")",
":",
"if",
"not",
"request",
".",
"user",
".",
"has_perm",
"(",
"'experiments.change_experiment'",
")",
":",
"return",
"HttpResponseForbidden",
"(",
")",
"experiment_name",
"=",
"request",
".",
"PO... | Allows the admin user to change their assigned alternative | [
"Allows",
"the",
"admin",
"user",
"to",
"change",
"their",
"assigned",
"alternative"
] | 1f45e9f8a108b51e44918daa647269b2b8d43f1d | https://github.com/mixcloud/django-experiments/blob/1f45e9f8a108b51e44918daa647269b2b8d43f1d/experiments/admin.py#L112-L128 | train |
mixcloud/django-experiments | experiments/admin.py | ExperimentAdmin.set_state_view | def set_state_view(self, request):
"""
Changes the experiment state
"""
if not request.user.has_perm('experiments.change_experiment'):
return HttpResponseForbidden()
try:
state = int(request.POST.get("state", ""))
except ValueError:
re... | python | def set_state_view(self, request):
"""
Changes the experiment state
"""
if not request.user.has_perm('experiments.change_experiment'):
return HttpResponseForbidden()
try:
state = int(request.POST.get("state", ""))
except ValueError:
re... | [
"def",
"set_state_view",
"(",
"self",
",",
"request",
")",
":",
"if",
"not",
"request",
".",
"user",
".",
"has_perm",
"(",
"'experiments.change_experiment'",
")",
":",
"return",
"HttpResponseForbidden",
"(",
")",
"try",
":",
"state",
"=",
"int",
"(",
"reques... | Changes the experiment state | [
"Changes",
"the",
"experiment",
"state"
] | 1f45e9f8a108b51e44918daa647269b2b8d43f1d | https://github.com/mixcloud/django-experiments/blob/1f45e9f8a108b51e44918daa647269b2b8d43f1d/experiments/admin.py#L130-L156 | train |
mixcloud/django-experiments | experiments/utils.py | WebUser.get_alternative | def get_alternative(self, experiment_name):
"""
Get the alternative this user is enrolled in.
"""
experiment = None
try:
# catching the KeyError instead of using .get so that the experiment is auto created if desired
experiment = experiment_manager[experim... | python | def get_alternative(self, experiment_name):
"""
Get the alternative this user is enrolled in.
"""
experiment = None
try:
# catching the KeyError instead of using .get so that the experiment is auto created if desired
experiment = experiment_manager[experim... | [
"def",
"get_alternative",
"(",
"self",
",",
"experiment_name",
")",
":",
"experiment",
"=",
"None",
"try",
":",
"experiment",
"=",
"experiment_manager",
"[",
"experiment_name",
"]",
"except",
"KeyError",
":",
"pass",
"if",
"experiment",
":",
"if",
"experiment",
... | Get the alternative this user is enrolled in. | [
"Get",
"the",
"alternative",
"this",
"user",
"is",
"enrolled",
"in",
"."
] | 1f45e9f8a108b51e44918daa647269b2b8d43f1d | https://github.com/mixcloud/django-experiments/blob/1f45e9f8a108b51e44918daa647269b2b8d43f1d/experiments/utils.py#L102-L119 | train |
mixcloud/django-experiments | experiments/utils.py | WebUser.set_alternative | def set_alternative(self, experiment_name, alternative):
"""Explicitly set the alternative the user is enrolled in for the specified experiment.
This allows you to change a user between alternatives. The user and goal counts for the new
alternative will be increment, but those for the old one w... | python | def set_alternative(self, experiment_name, alternative):
"""Explicitly set the alternative the user is enrolled in for the specified experiment.
This allows you to change a user between alternatives. The user and goal counts for the new
alternative will be increment, but those for the old one w... | [
"def",
"set_alternative",
"(",
"self",
",",
"experiment_name",
",",
"alternative",
")",
":",
"experiment",
"=",
"experiment_manager",
".",
"get_experiment",
"(",
"experiment_name",
")",
"if",
"experiment",
":",
"self",
".",
"_set_enrollment",
"(",
"experiment",
",... | Explicitly set the alternative the user is enrolled in for the specified experiment.
This allows you to change a user between alternatives. The user and goal counts for the new
alternative will be increment, but those for the old one will not be decremented. The user will
be enrolled in the exp... | [
"Explicitly",
"set",
"the",
"alternative",
"the",
"user",
"is",
"enrolled",
"in",
"for",
"the",
"specified",
"experiment",
"."
] | 1f45e9f8a108b51e44918daa647269b2b8d43f1d | https://github.com/mixcloud/django-experiments/blob/1f45e9f8a108b51e44918daa647269b2b8d43f1d/experiments/utils.py#L121-L129 | train |
mixcloud/django-experiments | experiments/utils.py | WebUser.goal | def goal(self, goal_name, count=1):
"""Record that this user has performed a particular goal
This will update the goal stats for all experiments the user is enrolled in."""
for enrollment in self._get_all_enrollments():
if enrollment.experiment.is_displaying_alternatives():
... | python | def goal(self, goal_name, count=1):
"""Record that this user has performed a particular goal
This will update the goal stats for all experiments the user is enrolled in."""
for enrollment in self._get_all_enrollments():
if enrollment.experiment.is_displaying_alternatives():
... | [
"def",
"goal",
"(",
"self",
",",
"goal_name",
",",
"count",
"=",
"1",
")",
":",
"for",
"enrollment",
"in",
"self",
".",
"_get_all_enrollments",
"(",
")",
":",
"if",
"enrollment",
".",
"experiment",
".",
"is_displaying_alternatives",
"(",
")",
":",
"self",
... | Record that this user has performed a particular goal
This will update the goal stats for all experiments the user is enrolled in. | [
"Record",
"that",
"this",
"user",
"has",
"performed",
"a",
"particular",
"goal"
] | 1f45e9f8a108b51e44918daa647269b2b8d43f1d | https://github.com/mixcloud/django-experiments/blob/1f45e9f8a108b51e44918daa647269b2b8d43f1d/experiments/utils.py#L131-L137 | train |
mixcloud/django-experiments | experiments/utils.py | WebUser.incorporate | def incorporate(self, other_user):
"""Incorporate all enrollments and goals performed by the other user
If this user is not enrolled in a given experiment, the results for the
other user are incorporated. For experiments this user is already
enrolled in the results of the other user are... | python | def incorporate(self, other_user):
"""Incorporate all enrollments and goals performed by the other user
If this user is not enrolled in a given experiment, the results for the
other user are incorporated. For experiments this user is already
enrolled in the results of the other user are... | [
"def",
"incorporate",
"(",
"self",
",",
"other_user",
")",
":",
"for",
"enrollment",
"in",
"other_user",
".",
"_get_all_enrollments",
"(",
")",
":",
"if",
"not",
"self",
".",
"_get_enrollment",
"(",
"enrollment",
".",
"experiment",
")",
":",
"self",
".",
"... | Incorporate all enrollments and goals performed by the other user
If this user is not enrolled in a given experiment, the results for the
other user are incorporated. For experiments this user is already
enrolled in the results of the other user are discarded.
This takes a relatively l... | [
"Incorporate",
"all",
"enrollments",
"and",
"goals",
"performed",
"by",
"the",
"other",
"user"
] | 1f45e9f8a108b51e44918daa647269b2b8d43f1d | https://github.com/mixcloud/django-experiments/blob/1f45e9f8a108b51e44918daa647269b2b8d43f1d/experiments/utils.py#L143-L158 | train |
mixcloud/django-experiments | experiments/utils.py | WebUser.visit | def visit(self):
"""Record that the user has visited the site for the purposes of retention tracking"""
for enrollment in self._get_all_enrollments():
if enrollment.experiment.is_displaying_alternatives():
# We have two different goals, VISIT_NOT_PRESENT_COUNT_GOAL and VISIT_... | python | def visit(self):
"""Record that the user has visited the site for the purposes of retention tracking"""
for enrollment in self._get_all_enrollments():
if enrollment.experiment.is_displaying_alternatives():
# We have two different goals, VISIT_NOT_PRESENT_COUNT_GOAL and VISIT_... | [
"def",
"visit",
"(",
"self",
")",
":",
"for",
"enrollment",
"in",
"self",
".",
"_get_all_enrollments",
"(",
")",
":",
"if",
"enrollment",
".",
"experiment",
".",
"is_displaying_alternatives",
"(",
")",
":",
"if",
"not",
"enrollment",
".",
"last_seen",
":",
... | Record that the user has visited the site for the purposes of retention tracking | [
"Record",
"that",
"the",
"user",
"has",
"visited",
"the",
"site",
"for",
"the",
"purposes",
"of",
"retention",
"tracking"
] | 1f45e9f8a108b51e44918daa647269b2b8d43f1d | https://github.com/mixcloud/django-experiments/blob/1f45e9f8a108b51e44918daa647269b2b8d43f1d/experiments/utils.py#L160-L177 | train |
jgrassler/mkdocs-pandoc | mkdocs_pandoc/pandoc_converter.py | PandocConverter.flatten_pages | def flatten_pages(self, pages, level=1):
"""Recursively flattens pages data structure into a one-dimensional data structure"""
flattened = []
for page in pages:
if type(page) is list:
flattened.append(
{
'f... | python | def flatten_pages(self, pages, level=1):
"""Recursively flattens pages data structure into a one-dimensional data structure"""
flattened = []
for page in pages:
if type(page) is list:
flattened.append(
{
'f... | [
"def",
"flatten_pages",
"(",
"self",
",",
"pages",
",",
"level",
"=",
"1",
")",
":",
"flattened",
"=",
"[",
"]",
"for",
"page",
"in",
"pages",
":",
"if",
"type",
"(",
"page",
")",
"is",
"list",
":",
"flattened",
".",
"append",
"(",
"{",
"'file'",
... | Recursively flattens pages data structure into a one-dimensional data structure | [
"Recursively",
"flattens",
"pages",
"data",
"structure",
"into",
"a",
"one",
"-",
"dimensional",
"data",
"structure"
] | 11edfb90830325dca85bd0369bb8e2da8d6815b3 | https://github.com/jgrassler/mkdocs-pandoc/blob/11edfb90830325dca85bd0369bb8e2da8d6815b3/mkdocs_pandoc/pandoc_converter.py#L68-L96 | train |
jgrassler/mkdocs-pandoc | mkdocs_pandoc/pandoc_converter.py | PandocConverter.convert | def convert(self):
"""User-facing conversion method. Returns pandoc document as a list of
lines."""
lines = []
pages = self.flatten_pages(self.config['pages'])
f_exclude = mkdocs_pandoc.filters.exclude.ExcludeFilter(
exclude=self.exclude)
f_include = mk... | python | def convert(self):
"""User-facing conversion method. Returns pandoc document as a list of
lines."""
lines = []
pages = self.flatten_pages(self.config['pages'])
f_exclude = mkdocs_pandoc.filters.exclude.ExcludeFilter(
exclude=self.exclude)
f_include = mk... | [
"def",
"convert",
"(",
"self",
")",
":",
"lines",
"=",
"[",
"]",
"pages",
"=",
"self",
".",
"flatten_pages",
"(",
"self",
".",
"config",
"[",
"'pages'",
"]",
")",
"f_exclude",
"=",
"mkdocs_pandoc",
".",
"filters",
".",
"exclude",
".",
"ExcludeFilter",
... | User-facing conversion method. Returns pandoc document as a list of
lines. | [
"User",
"-",
"facing",
"conversion",
"method",
".",
"Returns",
"pandoc",
"document",
"as",
"a",
"list",
"of",
"lines",
"."
] | 11edfb90830325dca85bd0369bb8e2da8d6815b3 | https://github.com/jgrassler/mkdocs-pandoc/blob/11edfb90830325dca85bd0369bb8e2da8d6815b3/mkdocs_pandoc/pandoc_converter.py#L98-L167 | train |
jgrassler/mkdocs-pandoc | mkdocs_pandoc/filters/tables.py | TableFilter.blocks | def blocks(self, lines):
"""Groups lines into markdown blocks"""
state = markdown.blockparser.State()
blocks = []
# We use three states: start, ``` and '\n'
state.set('start')
# index of current block
currblock = 0
for line in lines:
line +=... | python | def blocks(self, lines):
"""Groups lines into markdown blocks"""
state = markdown.blockparser.State()
blocks = []
# We use three states: start, ``` and '\n'
state.set('start')
# index of current block
currblock = 0
for line in lines:
line +=... | [
"def",
"blocks",
"(",
"self",
",",
"lines",
")",
":",
"state",
"=",
"markdown",
".",
"blockparser",
".",
"State",
"(",
")",
"blocks",
"=",
"[",
"]",
"state",
".",
"set",
"(",
"'start'",
")",
"currblock",
"=",
"0",
"for",
"line",
"in",
"lines",
":",... | Groups lines into markdown blocks | [
"Groups",
"lines",
"into",
"markdown",
"blocks"
] | 11edfb90830325dca85bd0369bb8e2da8d6815b3 | https://github.com/jgrassler/mkdocs-pandoc/blob/11edfb90830325dca85bd0369bb8e2da8d6815b3/mkdocs_pandoc/filters/tables.py#L31-L57 | train |
jgrassler/mkdocs-pandoc | mkdocs_pandoc/filters/tables.py | TableFilter.ruler_line | def ruler_line(self, widths, linetype='-'):
"""Generates a ruler line for separating rows from each other"""
cells = []
for w in widths:
cells.append(linetype * (w+2))
return '+' + '+'.join(cells) + '+' | python | def ruler_line(self, widths, linetype='-'):
"""Generates a ruler line for separating rows from each other"""
cells = []
for w in widths:
cells.append(linetype * (w+2))
return '+' + '+'.join(cells) + '+' | [
"def",
"ruler_line",
"(",
"self",
",",
"widths",
",",
"linetype",
"=",
"'-'",
")",
":",
"cells",
"=",
"[",
"]",
"for",
"w",
"in",
"widths",
":",
"cells",
".",
"append",
"(",
"linetype",
"*",
"(",
"w",
"+",
"2",
")",
")",
"return",
"'+'",
"+",
"... | Generates a ruler line for separating rows from each other | [
"Generates",
"a",
"ruler",
"line",
"for",
"separating",
"rows",
"from",
"each",
"other"
] | 11edfb90830325dca85bd0369bb8e2da8d6815b3 | https://github.com/jgrassler/mkdocs-pandoc/blob/11edfb90830325dca85bd0369bb8e2da8d6815b3/mkdocs_pandoc/filters/tables.py#L182-L187 | train |
jgrassler/mkdocs-pandoc | mkdocs_pandoc/filters/tables.py | TableFilter.wrap_row | def wrap_row(self, widths, row, width_default=None):
"""Wraps a single line table row into a fixed width, multi-line table."""
lines = []
longest = 0 # longest wrapped column in row
if not width_default:
width_default = self.width_default
# Wrap column contents
... | python | def wrap_row(self, widths, row, width_default=None):
"""Wraps a single line table row into a fixed width, multi-line table."""
lines = []
longest = 0 # longest wrapped column in row
if not width_default:
width_default = self.width_default
# Wrap column contents
... | [
"def",
"wrap_row",
"(",
"self",
",",
"widths",
",",
"row",
",",
"width_default",
"=",
"None",
")",
":",
"lines",
"=",
"[",
"]",
"longest",
"=",
"0",
"if",
"not",
"width_default",
":",
"width_default",
"=",
"self",
".",
"width_default",
"for",
"i",
"in"... | Wraps a single line table row into a fixed width, multi-line table. | [
"Wraps",
"a",
"single",
"line",
"table",
"row",
"into",
"a",
"fixed",
"width",
"multi",
"-",
"line",
"table",
"."
] | 11edfb90830325dca85bd0369bb8e2da8d6815b3 | https://github.com/jgrassler/mkdocs-pandoc/blob/11edfb90830325dca85bd0369bb8e2da8d6815b3/mkdocs_pandoc/filters/tables.py#L190-L234 | train |
mishbahr/djangocms-forms | djangocms_forms/admin.py | FormSubmissionAdmin.render_export_form | def render_export_form(self, request, context, form_url=''):
"""
Render the from submission export form.
"""
context.update({
'has_change_permission': self.has_change_permission(request),
'form_url': mark_safe(form_url),
'opts': self.opts,
... | python | def render_export_form(self, request, context, form_url=''):
"""
Render the from submission export form.
"""
context.update({
'has_change_permission': self.has_change_permission(request),
'form_url': mark_safe(form_url),
'opts': self.opts,
... | [
"def",
"render_export_form",
"(",
"self",
",",
"request",
",",
"context",
",",
"form_url",
"=",
"''",
")",
":",
"context",
".",
"update",
"(",
"{",
"'has_change_permission'",
":",
"self",
".",
"has_change_permission",
"(",
"request",
")",
",",
"'form_url'",
... | Render the from submission export form. | [
"Render",
"the",
"from",
"submission",
"export",
"form",
"."
] | 9d7a4ef9769fd5e1526921c084d6da7b8070a2c1 | https://github.com/mishbahr/djangocms-forms/blob/9d7a4ef9769fd5e1526921c084d6da7b8070a2c1/djangocms_forms/admin.py#L260-L272 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.