INSTRUCTION
stringlengths
1
8.43k
RESPONSE
stringlengths
75
104k
Return the Phonix code for a word.
def phonix(word, max_length=4, zero_pad=True): """Return the Phonix code for a word. This is a wrapper for :py:meth:`Phonix.encode`. Parameters ---------- word : str The word to transform max_length : int The length of the code returned (defaults to 4) zero_pad : bool ...
Return the Phonix code for a word.
def encode(self, word, max_length=4, zero_pad=True): """Return the Phonix code for a word. Parameters ---------- word : str The word to transform max_length : int The length of the code returned (defaults to 4) zero_pad : bool Pad the ...
Return the Editex distance between two strings.
def editex(src, tar, cost=(0, 1, 2), local=False): """Return the Editex distance between two strings. This is a wrapper for :py:meth:`Editex.dist_abs`. Parameters ---------- src : str Source string for comparison tar : str Target string for comparison cost : tuple A...
Return the normalized Editex distance between two strings.
def dist_editex(src, tar, cost=(0, 1, 2), local=False): """Return the normalized Editex distance between two strings. This is a wrapper for :py:meth:`Editex.dist`. Parameters ---------- src : str Source string for comparison tar : str Target string for comparison cost : tup...
Return the normalized Editex similarity of two strings.
def sim_editex(src, tar, cost=(0, 1, 2), local=False): """Return the normalized Editex similarity of two strings. This is a wrapper for :py:meth:`Editex.sim`. Parameters ---------- src : str Source string for comparison tar : str Target string for comparison cost : tuple ...
Return the Editex distance between two strings.
def dist_abs(self, src, tar, cost=(0, 1, 2), local=False): """Return the Editex distance between two strings. Parameters ---------- src : str Source string for comparison tar : str Target string for comparison cost : tuple A 3-tuple re...
Return the normalized Editex distance between two strings.
def dist(self, src, tar, cost=(0, 1, 2), local=False): """Return the normalized Editex distance between two strings. The Editex distance is normalized by dividing the Editex distance (calculated by any of the three supported methods) by the greater of the number of characters in src tim...
Return the position fingerprint.
def position_fingerprint( word, n_bits=16, most_common=MOST_COMMON_LETTERS_CG, bits_per_letter=3 ): """Return the position fingerprint. This is a wrapper for :py:meth:`Position.fingerprint`. Parameters ---------- word : str The word to fingerprint n_bits : int Number of bit...
Return the position fingerprint.
def fingerprint( self, word, n_bits=16, most_common=MOST_COMMON_LETTERS_CG, bits_per_letter=3, ): """Return the position fingerprint. Parameters ---------- word : str The word to fingerprint n_bits : int Number ...
Return Caumanns German stem.
def stem(self, word): """Return Caumanns German stem. Parameters ---------- word : str The word to stem Returns ------- str Word stem Examples -------- >>> stmr = Caumanns() >>> stmr.stem('lesen') ...
Return the NCD between two strings using arithmetic coding.
def dist(self, src, tar, probs=None): """Return the NCD between two strings using arithmetic coding. Parameters ---------- src : str Source string for comparison tar : str Target string for comparison probs : dict A dictionary trained ...
Read fn and return the contents.
def readfile(fn): """Read fn and return the contents. Parameters ---------- fn : str A filename Returns ------- str The content of the file """ with open(path.join(HERE, fn), 'r', encoding='utf-8') as f: return f.read()
Return the Spanish Metaphone of a word.
def spanish_metaphone(word, max_length=6, modified=False): """Return the Spanish Metaphone of a word. This is a wrapper for :py:meth:`SpanishMetaphone.encode`. Parameters ---------- word : str The word to transform max_length : int The length of the code returned (defaults to 6...
Return the Spanish Metaphone of a word.
def encode(self, word, max_length=6, modified=False): """Return the Spanish Metaphone of a word. Parameters ---------- word : str The word to transform max_length : int The length of the code returned (defaults to 6) modified : bool Se...
Return the FONEM code of a word.
def encode(self, word): """Return the FONEM code of a word. Parameters ---------- word : str The word to transform Returns ------- str The FONEM code Examples -------- >>> pe = FONEM() >>> pe.encode('March...
Return the Statistics Canada code for a word.
def encode(self, word, max_length=4): """Return the Statistics Canada code for a word. Parameters ---------- word : str The word to transform max_length : int The maximum length (default 4) of the code to return Returns ------- st...
Return the Synoname similarity type of two words.
def synoname( src, tar, word_approx_min=0.3, char_approx_min=0.73, tests=2 ** 12 - 1, ret_name=False, ): """Return the Synoname similarity type of two words. This is a wrapper for :py:meth:`Synoname.dist_abs`. Parameters ---------- src : str Source string for compar...
Return a word with punctuation stripped out.
def _synoname_strip_punct(self, word): """Return a word with punctuation stripped out. Parameters ---------- word : str A word to strip punctuation from Returns ------- str The word stripped of punctuation Examples ------...
Return the Synoname word approximation score for two names.
def _synoname_word_approximation( self, src_ln, tar_ln, src_fn='', tar_fn='', features=None ): """Return the Synoname word approximation score for two names. Parameters ---------- src_ln : str Last name of the source tar_ln : str Last name of ...
Return the Synoname similarity type of two words.
def dist_abs( self, src, tar, word_approx_min=0.3, char_approx_min=0.73, tests=2 ** 12 - 1, ret_name=False, ): """Return the Synoname similarity type of two words. Parameters ---------- src : str Source string for c...
Return the normalized Synoname distance between two words.
def dist( self, src, tar, word_approx_min=0.3, char_approx_min=0.73, tests=2 ** 12 - 1, ): """Return the normalized Synoname distance between two words. Parameters ---------- src : str Source string for comparison t...
r Return the Jaccard similarity of two strings.
def sim(self, src, tar, qval=2): r"""Return the Jaccard similarity of two strings. Parameters ---------- src : str Source string (or QGrams/Counter objects) for comparison tar : str Target string (or QGrams/Counter objects) for comparison qval : i...
Return the Tanimoto distance between two strings.
def tanimoto_coeff(self, src, tar, qval=2): """Return the Tanimoto distance between two strings. Tanimoto distance :cite:`Tanimoto:1958` is :math:`-log_{2} sim_{Tanimoto}(X, Y)`. Parameters ---------- src : str Source string (or QGrams/Counter objects) for c...
Return the common Sift4 distance between two terms.
def sift4_common(src, tar, max_offset=5, max_distance=0): """Return the "common" Sift4 distance between two terms. This is a wrapper for :py:meth:`Sift4.dist_abs`. Parameters ---------- src : str Source string for comparison tar : str Target string for comparison max_offset...
Return the normalized common Sift4 distance between two terms.
def dist_sift4(src, tar, max_offset=5, max_distance=0): """Return the normalized "common" Sift4 distance between two terms. This is a wrapper for :py:meth:`Sift4.dist`. Parameters ---------- src : str Source string for comparison tar : str Target string for comparison max_o...
Return the normalized common Sift4 similarity of two terms.
def sim_sift4(src, tar, max_offset=5, max_distance=0): """Return the normalized "common" Sift4 similarity of two terms. This is a wrapper for :py:meth:`Sift4.sim`. Parameters ---------- src : str Source string for comparison tar : str Target string for comparison max_offset...
Return the common Sift4 distance between two terms.
def dist_abs(self, src, tar, max_offset=5, max_distance=0): """Return the "common" Sift4 distance between two terms. Parameters ---------- src : str Source string for comparison tar : str Target string for comparison max_offset : int T...
Return the normalized common Sift4 distance between two terms.
def dist(self, src, tar, max_offset=5, max_distance=0): """Return the normalized "common" Sift4 distance between two terms. This is Sift4 distance, normalized to [0, 1]. Parameters ---------- src : str Source string for comparison tar : str Targe...
Return the NCD between two strings using bzip2 compression.
def dist(self, src, tar): """Return the NCD between two strings using bzip2 compression. Parameters ---------- src : str Source string for comparison tar : str Target string for comparison Returns ------- float Compres...
Return the MetaSoundex code for a word.
def encode(self, word, lang='en'): """Return the MetaSoundex code for a word. Parameters ---------- word : str The word to transform lang : str Either ``en`` for English or ``es`` for Spanish Returns ------- str The Me...
Return the S - stemmed form of a word.
def stem(self, word): """Return the S-stemmed form of a word. Parameters ---------- word : str The word to stem Returns ------- str Word stem Examples -------- >>> stmr = SStemmer() >>> stmr.stem('summarie...
Return the Ratcliff - Obershelp similarity of two strings.
def sim(self, src, tar): """Return the Ratcliff-Obershelp similarity of two strings. Parameters ---------- src : str Source string for comparison tar : str Target string for comparison Returns ------- float Ratcliff-Ob...
Return the Refined Soundex code for a word.
def refined_soundex(word, max_length=-1, zero_pad=False, retain_vowels=False): """Return the Refined Soundex code for a word. This is a wrapper for :py:meth:`RefinedSoundex.encode`. Parameters ---------- word : str The word to transform max_length : int The length of the code r...
Return the Refined Soundex code for a word.
def encode(self, word, max_length=-1, zero_pad=False, retain_vowels=False): """Return the Refined Soundex code for a word. Parameters ---------- word : str The word to transform max_length : int The length of the code returned (defaults to unlimited) ...
Return the MRA comparison rating of two strings.
def dist_abs(self, src, tar): """Return the MRA comparison rating of two strings. Parameters ---------- src : str Source string for comparison tar : str Target string for comparison Returns ------- int MRA comparison r...
Return the Parmar - Kumbharana encoding of a word.
def encode(self, word): """Return the Parmar-Kumbharana encoding of a word. Parameters ---------- word : str The word to transform Returns ------- str The Parmar-Kumbharana encoding Examples -------- >>> pe = Parm...
Calculate the Hamming distance between the Eudex hashes of two terms.
def eudex_hamming( src, tar, weights='exponential', max_length=8, normalized=False ): """Calculate the Hamming distance between the Eudex hashes of two terms. This is a wrapper for :py:meth:`Eudex.eudex_hamming`. Parameters ---------- src : str Source string for comparison tar : st...
Return normalized Hamming distance between Eudex hashes of two terms.
def dist_eudex(src, tar, weights='exponential', max_length=8): """Return normalized Hamming distance between Eudex hashes of two terms. This is a wrapper for :py:meth:`Eudex.dist`. Parameters ---------- src : str Source string for comparison tar : str Target string for comparis...
Return normalized Hamming similarity between Eudex hashes of two terms.
def sim_eudex(src, tar, weights='exponential', max_length=8): """Return normalized Hamming similarity between Eudex hashes of two terms. This is a wrapper for :py:meth:`Eudex.sim`. Parameters ---------- src : str Source string for comparison tar : str Target string for comparis...
Yield the next Fibonacci number.
def gen_fibonacci(): """Yield the next Fibonacci number. Based on https://www.python-course.eu/generators.php Starts at Fibonacci number 3 (the second 1) Yields ------ int The next Fibonacci number """ num_a, num_b = 1, 2 while True:...
Calculate the distance between the Eudex hashes of two terms.
def dist_abs( self, src, tar, weights='exponential', max_length=8, normalized=False ): """Calculate the distance between the Eudex hashes of two terms. Parameters ---------- src : str Source string for comparison tar : str Target string for co...
Return normalized distance between the Eudex hashes of two terms.
def dist(self, src, tar, weights='exponential', max_length=8): """Return normalized distance between the Eudex hashes of two terms. This is Eudex distance normalized to [0, 1]. Parameters ---------- src : str Source string for comparison tar : str ...
Return the Euclidean distance between two strings.
def euclidean(src, tar, qval=2, normalized=False, alphabet=None): """Return the Euclidean distance between two strings. This is a wrapper for :py:meth:`Euclidean.dist_abs`. Parameters ---------- src : str Source string (or QGrams/Counter objects) for comparison tar : str Target...
Return the normalized Euclidean distance between two strings.
def dist_euclidean(src, tar, qval=2, alphabet=None): """Return the normalized Euclidean distance between two strings. This is a wrapper for :py:meth:`Euclidean.dist`. Parameters ---------- src : str Source string (or QGrams/Counter objects) for comparison tar : str Target strin...
Return the normalized Euclidean similarity of two strings.
def sim_euclidean(src, tar, qval=2, alphabet=None): """Return the normalized Euclidean similarity of two strings. This is a wrapper for :py:meth:`Euclidean.sim`. Parameters ---------- src : str Source string (or QGrams/Counter objects) for comparison tar : str Target string (or...
Return Lovins condition K.
def _cond_k(self, word, suffix_len): """Return Lovins' condition K. Parameters ---------- word : str Word to check suffix_len : int Suffix length Returns ------- bool True if condition is met """ retur...
Return Lovins condition N.
def _cond_n(self, word, suffix_len): """Return Lovins' condition N. Parameters ---------- word : str Word to check suffix_len : int Suffix length Returns ------- bool True if condition is met """ if le...
Return Lovins condition S.
def _cond_s(self, word, suffix_len): """Return Lovins' condition S. Parameters ---------- word : str Word to check suffix_len : int Suffix length Returns ------- bool True if condition is met """ retur...
Return Lovins condition X.
def _cond_x(self, word, suffix_len): """Return Lovins' condition X. Parameters ---------- word : str Word to check suffix_len : int Suffix length Returns ------- bool True if condition is met """ retur...
Return Lovins condition BB.
def _cond_bb(self, word, suffix_len): """Return Lovins' condition BB. Parameters ---------- word : str Word to check suffix_len : int Suffix length Returns ------- bool True if condition is met """ ret...
Return Lovins stem.
def stem(self, word): """Return Lovins stem. Parameters ---------- word : str The word to stem Returns ------- str Word stem Examples -------- >>> stmr = Lovins() >>> stmr.stem('reading') 'read' ...
Return the Damerau - Levenshtein distance between two strings.
def dist_abs(self, src, tar, cost=(1, 1, 1, 1)): """Return the Damerau-Levenshtein distance between two strings. Parameters ---------- src : str Source string for comparison tar : str Target string for comparison cost : tuple A 4-tuple...
Return the NCD between two strings using zlib compression.
def dist(self, src, tar): """Return the NCD between two strings using zlib compression. Parameters ---------- src : str Source string for comparison tar : str Target string for comparison Returns ------- float Compress...
Return the Phonex code for a word.
def phonex(word, max_length=4, zero_pad=True): """Return the Phonex code for a word. This is a wrapper for :py:meth:`Phonex.encode`. Parameters ---------- word : str The word to transform max_length : int The length of the code returned (defaults to 4) zero_pad : bool ...
Return the Phonex code for a word.
def encode(self, word, max_length=4, zero_pad=True): """Return the Phonex code for a word. Parameters ---------- word : str The word to transform max_length : int The length of the code returned (defaults to 4) zero_pad : bool Pad the ...
Return Pylint badge color.
def pylint_color(score): """Return Pylint badge color. Parameters ---------- score : float A Pylint score Returns ------- str Badge color """ # These are the score cutoffs for each color above. # I.e. score==10 -> brightgreen, down to 7.5 > score >= 5 -> orange...
Return pydocstyle badge color.
def pydocstyle_color(score): """Return pydocstyle badge color. Parameters ---------- score : float A pydocstyle score Returns ------- str Badge color """ # These are the score cutoffs for each color above. # I.e. score==0 -> brightgreen, down to 100 < score <= ...
Return flake8 badge color.
def flake8_color(score): """Return flake8 badge color. Parameters ---------- score : float A flake8 score Returns ------- str Badge color """ # These are the score cutoffs for each color above. # I.e. score==0 -> brightgreen, down to 100 < score <= 200 -> orang...
Return the Gotoh score of two strings.
def gotoh(src, tar, gap_open=1, gap_ext=0.4, sim_func=sim_ident): """Return the Gotoh score of two strings. This is a wrapper for :py:meth:`Gotoh.dist_abs`. Parameters ---------- src : str Source string for comparison tar : str Target string for comparison gap_open : float ...
Return the Gotoh score of two strings.
def dist_abs(self, src, tar, gap_open=1, gap_ext=0.4, sim_func=sim_ident): """Return the Gotoh score of two strings. Parameters ---------- src : str Source string for comparison tar : str Target string for comparison gap_open : float T...
Return the bag distance between two strings.
def dist_abs(self, src, tar): """Return the bag distance between two strings. Parameters ---------- src : str Source string for comparison tar : str Target string for comparison Returns ------- int Bag distance ...
Return the normalized bag distance between two strings.
def dist(self, src, tar): """Return the normalized bag distance between two strings. Bag distance is normalized by dividing by :math:`max( |src|, |tar| )`. Parameters ---------- src : str Source string for comparison tar : str Target string for c...
Return CLEF German stemmer plus stem.
def stem(self, word): """Return 'CLEF German stemmer plus' stem. Parameters ---------- word : str The word to stem Returns ------- str Word stem Examples -------- >>> stmr = CLEFGermanPlus() >>> clef_germa...
Return the MLIPNS similarity of two strings.
def sim_mlipns(src, tar, threshold=0.25, max_mismatches=2): """Return the MLIPNS similarity of two strings. This is a wrapper for :py:meth:`MLIPNS.sim`. Parameters ---------- src : str Source string for comparison tar : str Target string for comparison threshold : float ...
Return the MLIPNS distance between two strings.
def dist_mlipns(src, tar, threshold=0.25, max_mismatches=2): """Return the MLIPNS distance between two strings. This is a wrapper for :py:meth:`MLIPNS.dist`. Parameters ---------- src : str Source string for comparison tar : str Target string for comparison threshold : floa...
Return the MLIPNS similarity of two strings.
def sim(self, src, tar, threshold=0.25, max_mismatches=2): """Return the MLIPNS similarity of two strings. Parameters ---------- src : str Source string for comparison tar : str Target string for comparison threshold : float A number [...
Return a similarity of two strings.
def sim(src, tar, method=sim_levenshtein): """Return a similarity of two strings. This is a generalized function for calling other similarity functions. Parameters ---------- src : str Source string for comparison tar : str Target string for comparison method : function ...
Return a distance between two strings.
def dist(src, tar, method=sim_levenshtein): """Return a distance between two strings. This is a generalized function for calling other distance functions. Parameters ---------- src : str Source string for comparison tar : str Target string for comparison method : function ...
Return the MRA personal numeric identifier ( PNI ) for a word.
def encode(self, word): """Return the MRA personal numeric identifier (PNI) for a word. Parameters ---------- word : str The word to transform Returns ------- str The MRA PNI Examples -------- >>> pe = MRA() ...
Return Porter helper function _m_degree value.
def _m_degree(self, term): """Return Porter helper function _m_degree value. m-degree is equal to the number of V to C transitions Parameters ---------- term : str The word for which to calculate the m-degree Returns ------- int ...
Return Porter helper function _has_vowel value.
def _has_vowel(self, term): """Return Porter helper function _has_vowel value. Parameters ---------- term : str The word to scan for vowels Returns ------- bool True iff a vowel exists in the term (as defined in the Porter ste...
Return Porter helper function _ends_in_doubled_cons value.
def _ends_in_doubled_cons(self, term): """Return Porter helper function _ends_in_doubled_cons value. Parameters ---------- term : str The word to check for a final doubled consonant Returns ------- bool True iff the stem ends in a doubled...
Return Porter helper function _ends_in_cvc value.
def _ends_in_cvc(self, term): """Return Porter helper function _ends_in_cvc value. Parameters ---------- term : str The word to scan for cvc Returns ------- bool True iff the stem ends in cvc (as defined in the Porter stemmer ...
Return Porter stem.
def stem(self, word, early_english=False): """Return Porter stem. Parameters ---------- word : str The word to stem early_english : bool Set to True in order to remove -eth & -est (2nd & 3rd person singular verbal agreement suffixes) ...
Return the SoundexBR encoding of a word.
def soundex_br(word, max_length=4, zero_pad=True): """Return the SoundexBR encoding of a word. This is a wrapper for :py:meth:`SoundexBR.encode`. Parameters ---------- word : str The word to transform max_length : int The length of the code returned (defaults to 4) zero_pad...
Return the SoundexBR encoding of a word.
def encode(self, word, max_length=4, zero_pad=True): """Return the SoundexBR encoding of a word. Parameters ---------- word : str The word to transform max_length : int The length of the code returned (defaults to 4) zero_pad : bool Pa...
Symmetrical logarithmic scale.
def filter_symlog(y, base=10.0): """Symmetrical logarithmic scale. Optional arguments: *base*: The base of the logarithm. """ log_base = np.log(base) sign = np.sign(y) logs = np.log(np.abs(y) / log_base) return sign * logs
Smooth ( and optionally differentiate ) with a Savitzky - Golay filter.
def filter_savitzky_golay(y, window_size=5, order=2, deriv=0, rate=1): """Smooth (and optionally differentiate) with a Savitzky-Golay filter.""" try: window_size = np.abs(np.int(window_size)) order = np.abs(np.int(order)) except ValueError: raise ValueError('window_size and order mus...
Show usage and available curve functions.
def usage_function(parser): """Show usage and available curve functions.""" parser.print_usage() print('') print('available functions:') for function in sorted(FUNCTION): doc = FUNCTION[function].__doc__.strip().splitlines()[0] print(' %-12s %s' % (function + ':', doc)) retur...
Show usage and available palettes.
def usage_palette(parser): """Show usage and available palettes.""" parser.print_usage() print('') print('available palettes:') for palette in sorted(PALETTE): print(' %-12s' % (palette,)) return 0
Main entrypoint if invoked via the command line.
def run(): """Main entrypoint if invoked via the command line.""" import argparse parser = argparse.ArgumentParser( description=( 'Text mode diagrams using UTF-8 characters and fancy colors.' ), epilog=""" (1): only works for the horizontal bar graph, the first argum...
Get the current terminal size.
def size(self): """Get the current terminal size.""" for fd in range(3): cr = self._ioctl_GWINSZ(fd) if cr: break if not cr: try: fd = os.open(os.ctermid(), os.O_RDONLY) cr = self._ioctl_GWINSZ(fd) ...
Get the escape sequence for indexed color index.
def color(self, index): """Get the escape sequence for indexed color ``index``. The ``index`` is a color index in the 256 color space. The color space consists of: * 0x00-0x0f: default EGA colors * 0x10-0xe7: 6x6x6 RGB cubes * 0xe8-0xff: gray scale ramp """ ...
Return the escape sequence for the selected Control Sequence.
def csi(self, capname, *args): """Return the escape sequence for the selected Control Sequence.""" value = curses.tigetstr(capname) if value is None: return b'' else: return curses.tparm(value, *args)
Return a value wrapped in the selected CSI and does a reset.
def csi_wrap(self, value, capname, *args): """Return a value wrapped in the selected CSI and does a reset.""" if isinstance(value, str): value = value.encode('utf-8') return b''.join([ self.csi(capname, *args), value, self.csi('sgr0'), ])
Read points from istream and output to ostream.
def consume(self, istream, ostream, batch=False): """Read points from istream and output to ostream.""" datapoints = [] # List of 2-tuples if batch: sleep = max(0.01, self.option.sleep) fd = istream.fileno() while True: try: ...
Consume data from a line.
def consume_line(self, line): """Consume data from a line.""" data = RE_VALUE_KEY.split(line.strip(), 1) if len(data) == 1: return float(data[0]), None else: return float(data[0]), data[1].strip()
Add a set of data points.
def update(self, points, values=None): """Add a set of data points.""" self.values = values or [None] * len(points) if np is None: if self.option.function: warnings.warn('numpy not available, function ignored') self.points = points self.minimu...
Generate a color ramp for the current screen height.
def color_ramp(self, size): """Generate a color ramp for the current screen height.""" color = PALETTE.get(self.option.palette, {}) color = color.get(self.term.colors, None) color_ramp = [] if color is not None: ratio = len(color) / float(size) for i in ra...
Convert the input size to human readable short form.
def human(self, size, base=1000, units=' kMGTZ'): """Convert the input ``size`` to human readable, short form.""" sign = '+' if size >= 0 else '-' size = abs(size) if size < 1000: return '%s%d' % (sign, size) for i, suffix in enumerate(units): unit = 1000 ...
Run the filter function on the provided points.
def apply_function(self, points): """Run the filter function on the provided points.""" if not self.option.function: return points if np is None: raise ImportError('numpy is not available') if ':' in self.option.function: function, arguments = self.o...
Resolve the points to make a line between two points.
def line(self, p1, p2, resolution=1): """Resolve the points to make a line between two points.""" xdiff = max(p1.x, p2.x) - min(p1.x, p2.x) ydiff = max(p1.y, p2.y) - min(p1.y, p2.y) xdir = [-1, 1][int(p1.x <= p2.x)] ydir = [-1, 1][int(p1.y <= p2.y)] r = int(round(max(xdif...
Set a text value in the screen canvas.
def set_text(self, point, text): """Set a text value in the screen canvas.""" if not self.option.legend: return if not isinstance(point, Point): point = Point(point) for offset, char in enumerate(str(text)): self.screen.canvas[point.y][point.x + offs...
Render graph to stream.
def render(self, stream): """Render graph to stream.""" encoding = self.option.encoding or self.term.encoding or "utf8" if self.option.color: ramp = self.color_ramp(self.size.y)[::-1] else: ramp = None if self.cycle >= 1 and self.lines: strea...
Normalised data points using numpy.
def _normalised_numpy(self): """Normalised data points using numpy.""" dx = (self.screen.width / float(len(self.points))) oy = (self.screen.height) points = np.array(self.points) - self.minimum points = points * 4.0 / self.extents * self.size.y for x, y in enumerate(point...
Normalised data points using pure Python.
def _normalised_python(self): """Normalised data points using pure Python.""" dx = (self.screen.width / float(len(self.points))) oy = (self.screen.height) for x, point in enumerate(self.points): y = (point - self.minimum) * 4.0 / self.extents * self.size.y yield P...
Zero crossing value.
def null(self): """Zero crossing value.""" if not self.option.axis: return -1 else: return self.screen.height - ( -self.minimum * 4.0 / self.extents * self.size.y )
Set pixel at ( x y ) point.
def set(self, point): """Set pixel at (x, y) point.""" if not isinstance(point, Point): point = Point(point) rx = self.round(point.x) ry = self.round(point.y) item = Point((rx >> 1, min(ry >> 2, self.size.y))) self.screen[item] |= self.pixels[ry & 3][rx & 1]
Unset pixel at ( x y ) point.
def unset(self, point): """Unset pixel at (x, y) point.""" if not isinstance(point, Point): point = Point(point) x, y = self.round(point.x) >> 1, self.round(point.y) >> 2 if (x, y) not in self.screen: return if isinstance(self.screen[y][x], int): ...
used when allocating memory ingame
def mem_size(self): '''used when allocating memory ingame''' data_len = self._data_mem_size node_count = len(list(self.xml_doc.iter(tag=etree.Element))) if self.compressed: size = 52 * node_count + data_len + 630 else: tags_len = 0 for e in s...