_id
stringlengths
2
7
title
stringlengths
1
88
partition
stringclasses
3 values
text
stringlengths
31
13.1k
language
stringclasses
1 value
meta_information
dict
q270900
SecurityLevel
test
def SecurityLevel(): """ Generates a filter chain for validating a security level. """ return ( f.Type(int) | f.Min(1) |
python
{ "resource": "" }
q270901
ProposedTransaction.increment_legacy_tag
test
def increment_legacy_tag(self): """ Increments the transaction's legacy tag, used to fix insecure bundle hashes when finalizing a bundle.
python
{ "resource": "" }
q270902
ProposedBundle.tag
test
def tag(self): # type: () -> Tag """ Determines the most relevant tag for the bundle. """ for
python
{ "resource": "" }
q270903
ProposedBundle.add_transaction
test
def add_transaction(self, transaction): # type: (ProposedTransaction) -> None """ Adds a transaction to the bundle. If the transaction message is too long, it will be split automatically into multiple transactions. """ if self.hash: raise RuntimeError('Bundle is already finalized.') if transaction.value < 0: raise ValueError('Use ``add_inputs`` to add inputs to the bundle.') self._transactions.append(ProposedTransaction(
python
{ "resource": "" }
q270904
ProposedBundle.finalize
test
def finalize(self): # type: () -> None """ Finalizes the bundle, preparing it to be attached to the Tangle. """ if self.hash: raise RuntimeError('Bundle is already finalized.') if not self: raise ValueError('Bundle has no transactions.') # Quick validation. balance = self.balance if balance < 0: if self.change_address: self.add_transaction(ProposedTransaction( address=self.change_address, value=-balance, tag=self.tag, )) else: raise ValueError( 'Bundle has unspent inputs (balance: {balance}); ' 'use ``send_unspent_inputs_to`` to create ' 'change transaction.'.format( balance=balance, ), ) elif balance > 0: raise ValueError(
python
{ "resource": "" }
q270905
ProposedBundle.sign_inputs
test
def sign_inputs(self, key_generator): # type: (KeyGenerator) -> None """ Sign inputs in a finalized bundle. """ if not self.hash: raise RuntimeError('Cannot sign inputs until bundle is finalized.') # Use a counter for the loop so that we can skip ahead as we go. i = 0 while i < len(self): txn = self[i] if txn.value < 0: # In order to sign the input, we need to know the index # of the private key used to generate it. if txn.address.key_index is None: raise with_context( exc=ValueError( 'Unable to sign input {input}; ' '``key_index`` is None ' '(``exc.context`` has more info).'.format( input=txn.address, ), ), context={ 'transaction': txn, }, ) if txn.address.security_level is None: raise with_context( exc=ValueError(
python
{ "resource": "" }
q270906
ProposedBundle.sign_input_at
test
def sign_input_at(self, start_index, private_key): # type: (int, PrivateKey) -> None """ Signs the input at the specified index. :param start_index: The index of the first input transaction. If necessary, the resulting signature will be split across multiple transactions automatically (i.e., if an input has ``security_level=2``, you still only need to call :py:meth:`sign_input_at` once). :param private_key: The private key that will be used to generate the signature.
python
{ "resource": "" }
q270907
ProposedBundle._create_input_transactions
test
def _create_input_transactions(self, addy): # type: (Address) -> None """ Creates transactions for the specified input address. """ self._transactions.append(ProposedTransaction( address=addy, tag=self.tag, # Spend the entire address balance; if necessary, we will # add a change transaction to the bundle. value=-addy.balance, )) # Signatures require additional transactions to store, due to # transaction length limit. # Subtract 1 to account for
python
{ "resource": "" }
q270908
convert_value_to_standard_unit
test
def convert_value_to_standard_unit(value, symbol='i'): # type: (Text, Text) -> float """ Converts between any two standard units of iota. :param value: Value (affixed) to convert. For example: '1.618 Mi'. :param symbol: Unit symbol of iota to convert to. For example: 'Gi'. :return: Float as units of given symbol to convert to. """ try: # Get input value value_tuple = value.split() amount = float(value_tuple[0]) except (ValueError, IndexError, AttributeError):
python
{ "resource": "" }
q270909
decompress_G1
test
def decompress_G1(z: G1Compressed) -> G1Uncompressed: """ Recovers x and y coordinates from the compressed point. """ # b_flag == 1 indicates the infinity point b_flag = (z % POW_2_383) // POW_2_382 if b_flag == 1: return Z1 x = z % POW_2_381 # Try solving y coordinate from the equation Y^2 = X^3 + b # using quadratic residue y = pow((x**3 + b.n) % q, (q + 1) // 4, q) if pow(y, 2, q) != (x**3 + b.n) % q: raise ValueError( "The
python
{ "resource": "" }
q270910
prime_field_inv
test
def prime_field_inv(a: int, n: int) -> int: """ Extended euclidean algorithm to find modular inverses for integers """ if a == 0: return 0 lm, hm = 1, 0 low, high = a % n, n while
python
{ "resource": "" }
q270911
Lexicon.from_json_file
test
def from_json_file(cls, filename): """ Load a lexicon from a JSON file. Args:
python
{ "resource": "" }
q270912
Lexicon.find_word_groups
test
def find_word_groups(self, text, category, proximity=2): """ Given a string and a category, finds and combines words into groups based on their proximity. Args: text (str): Some text. tokens (list): A list of regex strings. Returns: list. The combined strings it found. Example: COLOURS = [r"red(?:dish)?", r"grey(?:ish)?", r"green(?:ish)?"] s = 'GREYISH-GREEN limestone with RED or GREY sandstone.' find_word_groups(s, COLOURS) --> ['greyish green', 'red', 'grey'] """ f = re.IGNORECASE words = getattr(self, category) regex = re.compile(r'(\b' + r'\b|\b'.join(words) + r'\b)', flags=f) candidates = regex.finditer(text) starts, ends = [], [] groups = [] for item in candidates: starts.append(item.span()[0]) ends.append(item.span()[1]) groups.append(item.group().lower()) new_starts = [] # As a check only. new_groups = [] # This is what I want. skip = False
python
{ "resource": "" }
q270913
Lexicon.find_synonym
test
def find_synonym(self, word): """ Given a string and a dict of synonyms, returns the 'preferred' word. Case insensitive. Args: word (str): A word. Returns: str: The preferred word, or the input word if not found. Example: >>> syn = {'snake': ['python', 'adder']} >>> find_synonym('adder', syn) 'snake'
python
{ "resource": "" }
q270914
Lexicon.expand_abbreviations
test
def expand_abbreviations(self, text): """ Parse a piece of text and replace any abbreviations with their full word equivalents. Uses the lexicon.abbreviations dictionary to find abbreviations. Args: text (str): The text to parse. Returns: str: The text with abbreviations replaced. """ if not self.abbreviations: raise LexiconError("No abbreviations in lexicon.") def chunks(data, SIZE=25): """ Regex only supports
python
{ "resource": "" }
q270915
Lexicon.split_description
test
def split_description(self, text): """ Split a description into parts, each of which can be turned into a single component. """ # Protect some special sequences. t = re.sub(r'(\d) ?in\. ', r'\1 inch ', text) # Protect. t = re.sub(r'(\d) ?ft\. ', r'\1 feet ', t) # Protect. # Transform all part delimiters to first splitter. words = getattr(self, 'splitters') try: splitter = words[0].strip() except: splitter
python
{ "resource": "" }
q270916
Lexicon.categories
test
def categories(self): """ Lists the categories in the lexicon, except the optional categories. Returns: list: A list of strings of category names.
python
{ "resource": "" }
q270917
Decor.random
test
def random(cls, component): """ Returns a minimal Decor with a random colour. """ colour = random.sample([i for
python
{ "resource": "" }
q270918
Decor.plot
test
def plot(self, fmt=None, fig=None, ax=None): """ Make a simple plot of the Decor. Args: fmt (str): A Python format string for the component summaries. fig (Pyplot figure): A figure, optional. Use either fig or ax, not both. ax (Pyplot axis): An axis, optional. Use either fig or ax, not both. Returns: fig or ax or None. If you pass in an ax, you get it back. If you pass in a fig, you get it. If you pass nothing, the function creates a plot object as a side-effect. """ u = 4 # aspect ratio of decor plot v = 0.25 # ratio of decor
python
{ "resource": "" }
q270919
Legend.builtin
test
def builtin(cls, name): """ Generate a default legend. Args: name (str): The name of the legend you want. Not case sensitive. 'nsdoe': Nova Scotia Dept. of Energy 'canstrat': Canstrat 'nagmdm__6_2': USGS N. Am. Geol. Map Data Model 6.2 'nagmdm__6_1': USGS N. Am. Geol. Map Data Model 6.1 'nagmdm__4_3': USGS N. Am. Geol. Map Data Model 4.3 'sgmc': USGS State Geologic Map Compilation Default 'nagmdm__6_2'. Returns: Legend: The legend
python
{ "resource": "" }
q270920
Legend.builtin_timescale
test
def builtin_timescale(cls, name): """ Generate a default timescale legend. No arguments. Returns: Legend: The timescale stored in `defaults.py`. """ names = {
python
{ "resource": "" }
q270921
Legend.random
test
def random(cls, components, width=False, colour=None): """ Generate a random legend for a given list of components. Args: components (list or Striplog): A list of components. If you pass a Striplog, it will use the primary components. If you pass a component on its own, you will get a random Decor. width (bool): Also generate widths for the components, based on the order in which they are encountered. colour (str): If you want to give the Decors all the same colour, provide a hex string. Returns: Legend or Decor: A legend (or Decor) with random colours. TODO: It might be convenient to have a partial method to generate an 'empty' legend. Might be an easy way for someone to start with a template, since it'll have the components in it already. """ try: # Treating as a Striplog. list_of_Decors = [Decor.random(c)
python
{ "resource": "" }
q270922
Legend.from_image
test
def from_image(cls, filename, components, ignore=None, col_offset=0.1, row_offset=2): """ A slightly easier way to make legends from images. Args: filename (str) components (list) ignore (list): Colours to ignore, e.g. "#FFFFFF" to ignore white. col_offset (Number): If < 1, interpreted as proportion of way across the image. If > 1, interpreted as pixels from left. row_offset (int): Number of pixels to skip at the top of
python
{ "resource": "" }
q270923
Legend.from_csv
test
def from_csv(cls, filename=None, text=None): """ Read CSV text and generate a Legend. Args: string (str): The CSV string. In the first row, list the properties. Precede the properties of the component with 'comp ' or 'component '. For example: colour, width, comp lithology, comp colour #FFFFFF, 0, , #F7E9A6, 3, Sandstone, Grey #FF99CC, 2, Anhydrite, ... etc Note: To edit a legend, the easiest thing to do is probably this: - `legend.to_csv()` - Edit the legend, call it `new_legend`. - `legend = Legend.from_csv(text=new_legend)` """ if (filename is None) and (text is None): raise LegendError("You must provide a filename or CSV text.") if (filename is not None): with open(filename, 'r') as f: text = f.read() try: f = StringIO(text) # Python 3 except TypeError: f = StringIO(unicode(text)) # Python 2 r = csv.DictReader(f, skipinitialspace=True) list_of_Decors, components = [], [] kind = 'component' for row in r: d, component = {}, {} for (k, v) in row.items(): if (k in [None, '']): continue if (v in [None, '']): if k.lower() not in ['color', 'colour']: continue if k[:4].lower() == 'comp': prop = ' '.join(k.split()[1:]) if v.lower() == 'true': component[prop] = True elif v.lower() ==
python
{ "resource": "" }
q270924
Legend.to_csv
test
def to_csv(self): """ Renders a legend as a CSV string. No arguments. Returns: str: The legend as a CSV. """ # We can't delegate this to Decor because we need to know the superset # of all Decor properties. There may be lots of blanks. header = [] component_header = [] for row in self: for j in row.__dict__.keys(): if j == '_colour': j = 'colour' header.append(j) for k in row.component.__dict__.keys(): component_header.append(k) header = set(header) component_header = set(component_header) header.remove('component') header_row = '' if 'colour' in header: header_row += 'colour,' header.remove('colour') has_colour = True for item in header: header_row += item + ',' for item in component_header: header_row += 'component ' +
python
{ "resource": "" }
q270925
Legend.max_width
test
def max_width(self): """ The maximum width of all the Decors in the Legend. This is needed to scale a Legend or Striplog when plotting with widths turned on. """ try:
python
{ "resource": "" }
q270926
Legend.get_decor
test
def get_decor(self, c, match_only=None): """ Get the decor for a component. Args: c (component): The component to look up. match_only (list of str): The component attributes to include in the comparison. Default: All of them. Returns: Decor. The matching Decor from the Legend, or None if not found. """ if isinstance(c, Component): if c: if match_only: # Filter the component only those attributes c = Component({k: getattr(c, k, None) for k in match_only}) for decor in self.__list: try: if c == decor.component:
python
{ "resource": "" }
q270927
Legend.getattr
test
def getattr(self, c, attr, default=None, match_only=None): """ Get the attribute of a component. Args: c (component): The component to look up. attr (str): The attribute to get. default (str): What to return in the event of no match.
python
{ "resource": "" }
q270928
Legend.get_component
test
def get_component(self, colour, tolerance=0, default=None): """ Get the component corresponding to a display colour. This is for generating a Striplog object from a colour image of a striplog. Args: colour (str): The hex colour string to look up. tolerance (float): The colourspace distance within which to match. default (component or None): The component to return in the event of no match. Returns: component. The component best matching the provided colour. """ if not (0 <= tolerance <= np.sqrt(195075)): raise LegendError('Tolerance must be between 0 and 441.67') for decor in self.__list: if colour.lower() == decor.colour: return decor.component # If we're here, we didn't find one yet. r1, g1, b1 = utils.hex_to_rgb(colour) # Start with a best match of black. best_match = '#000000' best_match_dist = np.sqrt(r1**2. + g1**2. + b1**2.) # Now compare to each colour in the legend. for decor in self.__list: r2, g2, b2 = decor.rgb
python
{ "resource": "" }
q270929
Legend.plot
test
def plot(self, fmt=None): """ Make a simple plot of the legend. Simply calls Decor.plot() on all of its members. TODO: Build a more
python
{ "resource": "" }
q270930
Component.from_text
test
def from_text(cls, text, lexicon, required=None, first_only=True): """ Generate a Component from a text string, using a Lexicon. Args: text (str): The text string to parse. lexicon (Lexicon): The dictionary to use for the categories and lexemes. required (str): An attribute that we must have. If a required attribute is missing from the component, then None is returned. first_only (bool): Whether to only take the first match of a lexeme against the text
python
{ "resource": "" }
q270931
Component.summary
test
def summary(self, fmt=None, initial=True, default=''): """ Given a format string, return a summary description of a component. Args: component (dict): A component dictionary. fmt (str): Describes the format with a string. If no format is given, you will just get a list of attributes. If you give the empty string (''), you'll get `default` back. By default this gives you the empty string, effectively suppressing the summary. initial (bool): Whether to capitialize the first letter. Default is True. default (str): What to give if there's no component defined. Returns: str: A summary string. Example: r = Component({'colour': 'Red', 'grainsize': 'VF-F',
python
{ "resource": "" }
q270932
Rock
test
def Rock(*args, **kwargs): """ Graceful deprecation for old class name. """ with warnings.catch_warnings(): warnings.simplefilter("always") w = "The 'Rock' class was renamed 'Component'. "
python
{ "resource": "" }
q270933
_process_row
test
def _process_row(text, columns): """ Processes a single row from the file. """ if not text: return # Construct the column dictionary that maps each field to # its start, its length, and its read and write functions. coldict = {k: {'start': s, 'len': l, 'read': r, 'write': w} for
python
{ "resource": "" }
q270934
parse_canstrat
test
def parse_canstrat(text): """ Read all the rows and return a dict of the results. """ result = {} for row in text.split('\n'): if not row: continue if len(row) < 8: # Not a real record. continue # Read the metadata for this row/ row_header = _process_row(row, columns_) or
python
{ "resource": "" }
q270935
Striplog.__strict
test
def __strict(self): """ Private method. Checks if striplog is monotonically increasing in depth. Returns: Bool. """ def conc(a, b):
python
{ "resource": "" }
q270936
Striplog.unique
test
def unique(self): """ Property. Summarize a Striplog with some statistics. Returns: List. A list of (Component, total thickness thickness) tuples. """ all_rx = set([iv.primary for iv in self]) table = {r:
python
{ "resource": "" }
q270937
Striplog.__intervals_from_tops
test
def __intervals_from_tops(self, tops, values, basis, components, field=None, ignore_nan=True): """ Private method. Take a sequence of tops in an arbitrary dimension, and provide a list of intervals from which a striplog can be made. This is only intended to be used by ``from_image()``. Args: tops (iterable). A list of floats. values (iterable). A list of values to look up. basis (iterable). A list of components. components (iterable). A list of Components. Returns: List. A list of Intervals. """ # Scale tops to actual depths. length = float(basis.size) start, stop = basis[0], basis[-1] tops = [start + (p/(length-1)) * (stop-start) for p in tops] bases = tops[1:] + [stop] list_of_Intervals = [] for i,
python
{ "resource": "" }
q270938
Striplog._clean_longitudinal_data
test
def _clean_longitudinal_data(cls, data, null=None): """ Private function. Make sure we have what we need to make a striplog. """ # Rename 'depth' or 'MD' if ('top' not in data.keys()): data['top'] = data.pop('depth', data.pop('MD', None)) # Sort everything
python
{ "resource": "" }
q270939
Striplog.from_petrel
test
def from_petrel(cls, filename, stop=None, points=False, null=None, function=None, include=None, exclude=None, remap=None, ignore=None): """ Makes a striplog from a Petrel text file. Returns: striplog. """ result = utils.read_petrel(filename, function=function,
python
{ "resource": "" }
q270940
Striplog._build_list_of_Intervals
test
def _build_list_of_Intervals(cls, data_dict, stop=None, points=False, include=None, exclude=None, ignore=None, lexicon=None): """ Private function. Takes a data dictionary and reconstructs a list of Intervals from it. Args: data_dict (dict) stop (float): Where to end the last interval. points (bool) include (dict) exclude (dict) ignore (list) lexicon (Lexicon) Returns: list. """ include = include or {} exclude = exclude or {} ignore = ignore or [] # Reassemble as list of dicts all_data = [] for data in zip(*data_dict.values()): all_data.append({k: v for k, v in zip(data_dict.keys(), data)}) # Sort all_data = sorted(all_data, key=lambda x: x['top']) # Filter down: wanted_data = [] for dictionary in all_data: keep = True delete = [] for k, v in dictionary.items(): incl = include.get(k, utils.null_default(True)) excl = exclude.get(k, utils.null_default(False)) if k in ignore: delete.append(k)
python
{ "resource": "" }
q270941
Striplog.from_csv
test
def from_csv(cls, filename=None, text=None, dlm=',', lexicon=None, points=False, include=None, exclude=None, remap=None, function=None, null=None, ignore=None, source=None, stop=None, fieldnames=None): """ Load from a CSV file or text. """ if (filename is None) and (text is None): raise StriplogError("You must provide a filename or CSV text.") if (filename is not None): if source is None: source = filename with open(filename, 'r') as f: text = f.read() source = source or 'CSV' # Deal with multiple spaces in space delimited file. if dlm == ' ': text = re.sub(r'[ \t]+', ' ', text) if fieldnames is not None: text
python
{ "resource": "" }
q270942
Striplog.from_image
test
def from_image(cls, filename, start, stop, legend, source="Image", col_offset=0.1, row_offset=2, tolerance=0): """ Read an image and generate Striplog. Args: filename (str): An image file, preferably high-res PNG. start (float or int): The depth at the top of the image. stop (float or int): The depth at the bottom of the image. legend (Legend): A legend to look up the components in. source (str): A source for the data. Default: 'Image'. col_offset (Number): The proportion of the way across the image from which to extract the pixel column. Default: 0.1 (ie 10%). row_offset (int): The number of pixels to skip at the top of each change in colour. Default: 2. tolerance (float): The Euclidean distance between hex colours, which has a maximum (black to white) of 441.67 in base 10. Default: 0. Returns: Striplog: The ``striplog`` object. """ rgb = utils.loglike_from_image(filename, col_offset) loglike = np.array([utils.rgb_to_hex(t) for t in rgb]) # Get the pixels and colour values at 'tops' (i.e. changes). tops, hexes = utils.tops_from_loglike(loglike, offset=row_offset) # If there are consecutive tops, we assume it's because there is a #
python
{ "resource": "" }
q270943
Striplog.from_log
test
def from_log(cls, log, cutoff=None, components=None, legend=None, legend_field=None, field=None, right=False, basis=None, source='Log'): """ Turn a 1D array into a striplog, given a cutoff. Args: log (array-like): A 1D array or a list of integers. cutoff (number or array-like): The log value(s) at which to bin the log. Optional. components (array-like): A list of components. Use this or ``legend``. legend (``Legend``): A legend object. Use this or ``components``. legend_field ('str'): If you're not trying to match against components, then you can match the log values to this field in the Decors. field (str): The field in the Interval's ``data`` to store the log values as. right (bool): Which side of the cutoff to send things that are equal to, i.e. right on, the cutoff. basis (array-like): A depth basis for the log, so striplog knows where to put the boundaries. source (str): The source of the data. Default 'Log'. Returns: Striplog: The ``striplog`` object. """ if (components is None) and (legend is None) and (field is None): m = 'You must provide a list of components, and legend, or a field.' raise StriplogError(m) if (legend is not None) and (legend_field is None): try: # To treat it like a legend. components = [deepcopy(decor.component) for decor in legend] except AttributeError: # It's just a list of components. pass if legend_field is not None: field_values = [getattr(d, legend_field, 0) for d in legend] components = [Component() for i in range(int(max(field_values)+1))] for i, decor in enumerate(legend): components[i] = deepcopy(decor.component) if cutoff is not None: # First make sure
python
{ "resource": "" }
q270944
Striplog.from_las3
test
def from_las3(cls, string, lexicon=None, source="LAS", dlm=',', abbreviations=False): """ Turn LAS3 'lithology' section into a Striplog. Args: string (str): A section from an LAS3 file. lexicon (Lexicon): The language for conversion to components. source (str): A source for the data. dlm (str): The delimiter. abbreviations (bool): Whether to expand abbreviations. Returns: Striplog: The ``striplog`` object.
python
{ "resource": "" }
q270945
Striplog.from_canstrat
test
def from_canstrat(cls, filename, source='canstrat'): """ Eat a Canstrat DAT file and make a striplog. """ with open(filename) as f: dat = f.read() data = parse_canstrat(dat) list_of_Intervals = [] for d in data[7]: # 7 is the 'card type' for lithology info. if d.pop('skip'): continue top = d.pop('top') base = d.pop('base')
python
{ "resource": "" }
q270946
Striplog.copy
test
def copy(self): """Returns a shallow copy.""" return Striplog([i.copy() for i in self],
python
{ "resource": "" }
q270947
Striplog.to_csv
test
def to_csv(self, filename=None, as_text=True, use_descriptions=False, dlm=",", header=True): """ Returns a CSV string built from the summaries of the Intervals. Args: use_descriptions (bool): Whether to use descriptions instead of summaries, if available. dlm (str): The delimiter. header (bool): Whether to form a header row. Returns: str: A string of comma-separated values. """ if (filename is None): if (not as_text): raise StriplogError("You must provide a filename or set as_text to True.") else: as_text = False if as_text: output = StringIO() else: output = open(filename, 'w') fieldnames = ['Top', 'Base', 'Component'] writer = csv.DictWriter(output, delimiter=dlm,
python
{ "resource": "" }
q270948
Striplog.to_las3
test
def to_las3(self, use_descriptions=False, dlm=",", source="Striplog"): """ Returns an LAS 3.0 section string. Args: use_descriptions (bool): Whether to use descriptions instead of summaries, if available. dlm (str): The delimiter. source (str): The sourse of the data. Returns: str: A string forming Lithology section of an LAS3 file. """ data = self.to_csv(use_descriptions=use_descriptions,
python
{ "resource": "" }
q270949
Striplog.plot_axis
test
def plot_axis(self, ax, legend, ladder=False, default_width=1, match_only=None, colour=None, colour_function=None, cmap=None, default=None, width_field=None, **kwargs ): """ Plotting, but only the Rectangles. You have to set up the figure. Returns a matplotlib axis object. Args: ax (axis): The matplotlib axis to plot into. legend (Legend): The Legend to use for colours, etc. ladder (bool): Whether to use widths or not. Default False. default_width (int): A width for the plot if not using widths. Default 1. match_only (list): A list of strings matching the attributes you want to compare when plotting. colour (str): Which data field to use for colours. cmap (cmap): Matplotlib colourmap. Default ``viridis``. default (float): The default (null) value. width_field (str): The field to use for the width of the patches. **kwargs are passed through to matplotlib's ``patches.Rectangle``. Returns: axis: The matplotlib.pyplot axis. """ default_c = None patches = [] for iv in self.__list: origin = (0, iv.top.z) d = legend.get_decor(iv.primary, match_only=match_only) thick = iv.base.z - iv.top.z
python
{ "resource": "" }
q270950
Striplog.get_data
test
def get_data(self, field, function=None, default=None): """ Get data from the striplog. """ f = function or utils.null data = [] for iv in
python
{ "resource": "" }
q270951
Striplog.extract
test
def extract(self, log, basis, name, function=None): """ 'Extract' a log into the components of a striplog. Args: log (array_like). A log or other 1D data. basis (array_like). The depths or elevations of the log samples. name (str). The name of the attribute to store in the components. function (function). A function that takes an array as the only input, and returns whatever you want to store in the 'name' attribute of the primary component. Returns: None. The function works on the striplog in place. """ # Build a dict of {index: [log values]} to keep track. intervals = {} previous_ix = -1 for i, z in enumerate(basis): ix = self.read_at(z, index=True) if ix is None: continue
python
{ "resource": "" }
q270952
Striplog.find
test
def find(self, search_term, index=False): """ Look for a regex expression in the descriptions of the striplog. If there's no description, it looks in the summaries. If you pass a Component, then it will search the components, not the descriptions or summaries. Case insensitive. Args: search_term (string or Component): The thing you want to search for. Strings are treated as regular expressions. index (bool): Whether to return the index instead of the interval. Returns: Striplog: A striplog that contains only the 'hit' Intervals. However, if ``index`` was ``True``, then that's what you get. """ hits = [] for i, iv in enumerate(self): try: search_text = iv.description or iv.primary.summary()
python
{ "resource": "" }
q270953
Striplog.find_overlaps
test
def find_overlaps(self, index=False): """ Find overlaps in a striplog. Args: index (bool): If True, returns indices of intervals with gaps after them. Returns:
python
{ "resource": "" }
q270954
Striplog.find_gaps
test
def find_gaps(self, index=False): """ Finds gaps in a striplog. Args: index (bool): If True, returns indices of intervals with gaps after them. Returns:
python
{ "resource": "" }
q270955
Striplog.prune
test
def prune(self, limit=None, n=None, percentile=None, keep_ends=False): """ Remove intervals below a certain limit thickness. In place. Args: limit (float): Anything thinner than this will be pruned. n (int): The n thinnest beds will be pruned. percentile (float): The thinnest specified percentile will be pruned. keep_ends (bool): Whether to keep the first and last, regardless of whether they meet the pruning criteria.
python
{ "resource": "" }
q270956
Striplog.anneal
test
def anneal(self): """ Fill in empty intervals by growing from top and base. Note that this operation happens in-place and destroys any information about the ``Position`` (e.g. metadata associated with the top or base). See GitHub issue #54. """ strip = self.copy() gaps = strip.find_gaps(index=True) if not gaps: return for gap in gaps: before = strip[gap] after = strip[gap + 1]
python
{ "resource": "" }
q270957
Striplog.fill
test
def fill(self, component=None): """ Fill gaps with the component provided. Example t = s.fill(Component({'lithology': 'cheese'})) """ c = [component] if component is not None else [] # Make the intervals to go in the gaps.
python
{ "resource": "" }
q270958
Striplog.union
test
def union(self, other): """ Makes a striplog of all unions. Args: Striplog. The striplog instance to union with. Returns: Striplog. The result of the union. """ if not isinstance(other, self.__class__): m = "You can only union striplogs with each other."
python
{ "resource": "" }
q270959
Striplog.intersect
test
def intersect(self, other): """ Makes a striplog of all intersections. Args: Striplog. The striplog instance to intersect with. Returns: Striplog. The result of the intersection. """ if not isinstance(other, self.__class__): m = "You can only intersect striplogs with each other." raise StriplogError(m) result = [] for iv in self:
python
{ "resource": "" }
q270960
Striplog.merge_overlaps
test
def merge_overlaps(self): """ Merges overlaps by merging overlapping Intervals. The function takes no arguments and returns ``None``. It operates on the striplog 'in place' TODO: This function will not work if any interval overlaps more than one other intervals at either its base or top. """ overlaps = np.array(self.find_overlaps(index=True)) if not overlaps.any(): return for overlap in overlaps: before = self[overlap].copy() after =
python
{ "resource": "" }
q270961
Striplog.hist
test
def hist(self, lumping=None, summary=False, sort=True, plot=True, legend=None, ax=None ): """ Plots a histogram and returns the data for it. Args: lumping (str): If given, the bins will be lumped based on this attribute of the primary components of the intervals encountered. summary (bool): If True, the summaries of the components are returned as the bins. Otherwise, the default behaviour is to return the Components themselves. sort (bool): If True (default), the histogram is sorted by value, starting with the largest. plot (bool): If True (default), produce a bar plot. legend (Legend): The legend with which to colour the bars. ax (axis): An axis object, which will be returned if provided. If you don't provide one, it will be created but not returned. Returns: Tuple: A tuple of tuples of entities and counts. TODO: Deal with numeric properties, so I can histogram 'Vp' values, say. """ # This seems like overkill, but collecting all this stuff gives # the user some choice about what they get back. comps = [] labels = [] entries = defaultdict(int) for i in self: if lumping: k = i.primary[lumping] else: if summary: k = i.primary.summary() else: k = i.primary comps.append(i.primary) labels.append(i.primary.summary())
python
{ "resource": "" }
q270962
Striplog.invert
test
def invert(self, copy=False): """ Inverts the striplog, changing its order and the order of its contents. Operates in place by default. Args: copy (bool): Whether to operate in place or make a copy. Returns: None if operating in-place, or an inverted copy of the striplog if not. """ if copy: return Striplog([i.invert(copy=True) for i in self])
python
{ "resource": "" }
q270963
Striplog.crop
test
def crop(self, extent, copy=False): """ Crop to a new depth range. Args: extent (tuple): The new start and stop depth. Must be 'inside' existing striplog. copy (bool): Whether to operate in place or make a copy. Returns: Operates in place by deault; if copy is True, returns a striplog. """ try: if extent[0] is None: extent = (self.start.z, extent[1])
python
{ "resource": "" }
q270964
Striplog.quality
test
def quality(self, tests, alias=None): """ Run a series of tests and return the corresponding results. Based on curve testing for ``welly``. Args: tests (list): a list of functions. Returns: list. The results. Stick to booleans (True = pass) or ints. """ # This is hacky... striplog should probably merge with welly... # Ignore aliases alias = alias or {} alias = alias.get('striplog', alias.get('Striplog', [])) # Gather the tests. # First, anything called 'all', 'All', or 'ALL'. # Second, anything with the name of the curve we're in now. # Third, anything that the alias list has for this curve. # (This requires a reverse look-up so it's a
python
{ "resource": "" }
q270965
hex_to_name
test
def hex_to_name(hexx): """ Convert hex to a color name, using matplotlib's colour names. Args: hexx (str): A hexadecimal colour, starting with '#'. Returns: str: The name of the colour, or None if not found. """
python
{ "resource": "" }
q270966
loglike_from_image
test
def loglike_from_image(filename, offset): """ Get a log-like stream of RGB values from an image. Args: filename (str): The filename of a PNG image. offset (Number): If < 1, interpreted as proportion of way across the image. If > 1, interpreted as pixels from left. Returns: ndarray: A 2d array (a column of RGB triples) at the specified offset. TODO: Generalize this to extract 'logs' from images in other ways, such as giving the mean of a range of pixel columns, or
python
{ "resource": "" }
q270967
CustomFormatter.get_field
test
def get_field(self, field_name, args, kwargs): """ Return an underscore if the attribute is absent. Not all components have the same attributes. """ try: s = super(CustomFormatter, self) return s.get_field(field_name, args,
python
{ "resource": "" }
q270968
Jobs.get_jobs
test
def get_jobs(self, prefix=None): """ Lists all the jobs registered with Nomad. https://www.nomadproject.io/docs/http/jobs.html arguments: - prefix :(str) optional, specifies a string to filter jobs on based on an prefix. This is specified as a querystring parameter. returns: list raises:
python
{ "resource": "" }
q270969
Jobs.parse
test
def parse(self, hcl, canonicalize=False): """ Parse a HCL Job file. Returns a dict with the JSON formatted job. This API endpoint is only supported from Nomad version 0.8.3. https://www.nomadproject.io/api/jobs.html#parse-job returns: dict raises:
python
{ "resource": "" }
q270970
Acl.update_token
test
def update_token(self, id, token): """ Update token. https://www.nomadproject.io/api/acl-tokens.html arguments: - AccdesorID
python
{ "resource": "" }
q270971
Allocations.get_allocations
test
def get_allocations(self, prefix=None): """ Lists all the allocations. https://www.nomadproject.io/docs/http/allocs.html arguments: - prefix :(str) optional, specifies a string to filter allocations on based on an prefix. This is specified as a querystring parameter. returns: list raises:
python
{ "resource": "" }
q270972
Deployment.fail_deployment
test
def fail_deployment(self, id): """ This endpoint is used to mark a deployment as failed. This should be done to force the scheduler to stop creating allocations as part of the deployment or to cause a rollback to a previous job version. https://www.nomadproject.io/docs/http/deployments.html arguments: - id returns: dict raises:
python
{ "resource": "" }
q270973
Deployment.pause_deployment
test
def pause_deployment(self, id, pause): """ This endpoint is used to pause or unpause a deployment. This is done to pause a rolling upgrade or resume it. https://www.nomadproject.io/docs/http/deployments.html arguments: - id - pause, Specifies whether to pause or resume the deployment. returns: dict raises: - nomad.api.exceptions.BaseNomadException
python
{ "resource": "" }
q270974
Deployment.deployment_allocation_health
test
def deployment_allocation_health(self, id, healthy_allocations=list(), unhealthy_allocations=list()): """ This endpoint is used to set the health of an allocation that is in the deployment manually. In some use cases, automatic detection of allocation health may not be desired. As such those task groups can be marked with an upgrade policy that uses health_check = "manual". Those allocations must have their health marked manually using this endpoint. Marking an allocation as healthy will allow the rolling upgrade to proceed.
python
{ "resource": "" }
q270975
Node.drain_node
test
def drain_node(self, id, enable=False): """ Toggle the drain mode of the node. When enabled, no further allocations will be assigned and existing allocations will be migrated. https://www.nomadproject.io/docs/http/node.html arguments: - id (str uuid): node id - enable (bool): enable node drain or not to enable node drain returns: dict
python
{ "resource": "" }
q270976
Node.drain_node_with_spec
test
def drain_node_with_spec(self, id, drain_spec, mark_eligible=None): """ This endpoint toggles the drain mode of the node. When draining is enabled, no further allocations will be assigned to this node, and existing allocations will be migrated to new nodes. If an empty dictionary is given as drain_spec this will disable/toggle the drain. https://www.nomadproject.io/docs/http/node.html arguments: - id (str uuid): node id - drain_spec (dict): https://www.nomadproject.io/api/nodes.html#drainspec - mark_eligible (bool): https://www.nomadproject.io/api/nodes.html#markeligible returns: dict raises: - nomad.api.exceptions.BaseNomadException - nomad.api.exceptions.URLNotFoundNomadException """ payload = {} if drain_spec and mark_eligible is not None: payload = { "NodeID": id, "DrainSpec": drain_spec,
python
{ "resource": "" }
q270977
Node.eligible_node
test
def eligible_node(self, id, eligible=None, ineligible=None): """ Toggle the eligibility of the node. https://www.nomadproject.io/docs/http/node.html arguments: - id (str uuid): node id - eligible (bool): Set to True to mark node eligible - ineligible (bool): Set to True to mark node ineligible returns: dict raises: - nomad.api.exceptions.BaseNomadException - nomad.api.exceptions.URLNotFoundNomadException
python
{ "resource": "" }
q270978
ls.list_files
test
def list_files(self, id=None, path="/"): """ List files in an allocation directory. https://www.nomadproject.io/docs/http/client-fs-ls.html arguments: - id - path
python
{ "resource": "" }
q270979
stream_file.stream
test
def stream(self, id, offset, origin, path="/"): """ This endpoint streams the contents of a file in an allocation directory. https://www.nomadproject.io/api/client.html#stream-file arguments: - id: (str) allocation_id required - offset: (int) required - origin: (str) either start|end - path: (str) optional returns: (str) text raises:
python
{ "resource": "" }
q270980
stat.stat_file
test
def stat_file(self, id=None, path="/"): """ Stat a file in an allocation directory. https://www.nomadproject.io/docs/http/client-fs-stat.html arguments: - id - path returns:
python
{ "resource": "" }
q270981
Agent.join_agent
test
def join_agent(self, addresses): """Initiate a join between the agent and target peers. https://www.nomadproject.io/docs/http/agent-join.html returns: dict raises: - nomad.api.exceptions.BaseNomadException
python
{ "resource": "" }
q270982
Agent.update_servers
test
def update_servers(self, addresses): """Updates the list of known servers to the provided list. Replaces all previous server addresses with the new list. https://www.nomadproject.io/docs/http/agent-servers.html returns: 200 status code raises:
python
{ "resource": "" }
q270983
Agent.force_leave
test
def force_leave(self, node): """Force a failed gossip member into the left state. https://www.nomadproject.io/docs/http/agent-force-leave.html returns: 200 status code raises: - nomad.api.exceptions.BaseNomadException
python
{ "resource": "" }
q270984
Nodes.get_nodes
test
def get_nodes(self, prefix=None): """ Lists all the client nodes registered with Nomad. https://www.nomadproject.io/docs/http/nodes.html arguments: - prefix :(str) optional, specifies a string to filter nodes on based on an prefix. This is specified as a querystring parameter. returns: list raises:
python
{ "resource": "" }
q270985
Evaluations.get_evaluations
test
def get_evaluations(self, prefix=None): """ Lists all the evaluations. https://www.nomadproject.io/docs/http/evals.html arguments: - prefix :(str) optional, specifies a string to filter evaluations on based on an prefix. This is specified as a querystring parameter. returns: list raises:
python
{ "resource": "" }
q270986
Namespaces.get_namespaces
test
def get_namespaces(self, prefix=None): """ Lists all the namespaces registered with Nomad. https://www.nomadproject.io/docs/enterprise/namespaces/index.html arguments: - prefix :(str) optional, specifies a string to filter namespaces on based on an prefix. This is specified as a querystring parameter. returns: list raises:
python
{ "resource": "" }
q270987
Job.register_job
test
def register_job(self, id, job): """ Registers a new job or updates an existing job https://www.nomadproject.io/docs/http/job.html arguments:
python
{ "resource": "" }
q270988
Job.plan_job
test
def plan_job(self, id, job, diff=False, policy_override=False): """ Invoke a dry-run of the scheduler for the job. https://www.nomadproject.io/docs/http/job.html arguments: - id - job, dict - diff, boolean - policy_override, boolean returns: dict raises: - nomad.api.exceptions.BaseNomadException - nomad.api.exceptions.URLNotFoundNomadException """
python
{ "resource": "" }
q270989
Job.dispatch_job
test
def dispatch_job(self, id, payload=None, meta=None): """ Dispatches a new instance of a parameterized job. https://www.nomadproject.io/docs/http/job.html arguments: - id - payload - meta returns: dict raises: - nomad.api.exceptions.BaseNomadException
python
{ "resource": "" }
q270990
Job.revert_job
test
def revert_job(self, id, version, enforce_prior_version=None): """ This endpoint reverts the job to an older version. https://www.nomadproject.io/docs/http/job.html arguments: - id - version, Specifies the job version to revert to. optional_arguments: - enforce_prior_version, Optional value specifying the current job's version. This is checked and acts as a check-and-set value before reverting to the specified job. returns: dict raises: - nomad.api.exceptions.BaseNomadException
python
{ "resource": "" }
q270991
Job.stable_job
test
def stable_job(self, id, version, stable): """ This endpoint sets the job's stability. https://www.nomadproject.io/docs/http/job.html arguments: - id - version, Specifies the job version to revert to. - stable, Specifies whether the job should
python
{ "resource": "" }
q270992
Job.deregister_job
test
def deregister_job(self, id, purge=None): """ Deregisters a job, and stops all allocations part of it. https://www.nomadproject.io/docs/http/job.html arguments: - id - purge (bool), optionally specifies whether the job should be stopped and purged immediately (`purge=True`) or deferred to the Nomad garbage collector (`purge=False`). returns: dict raises: - nomad.api.exceptions.BaseNomadException - nomad.api.exceptions.URLNotFoundNomadException
python
{ "resource": "" }
q270993
Operator.get_configuration
test
def get_configuration(self, stale=False): """ Query the status of a client node registered with Nomad. https://www.nomadproject.io/docs/http/operator.html returns: dict optional arguments: - stale, (defaults to False), Specifies if the cluster should respond without an active leader. This is specified as a querystring parameter. raises:
python
{ "resource": "" }
q270994
Operator.delete_peer
test
def delete_peer(self, peer_address, stale=False): """ Remove the Nomad server with given address from the Raft configuration. The return code signifies success or failure. https://www.nomadproject.io/docs/http/operator.html arguments: - peer_address, The address specifies the server to remove and is given as an IP:port optional arguments: - stale, (defaults to False), Specifies if the cluster should respond without an active leader.
python
{ "resource": "" }
q270995
Deployments.get_deployments
test
def get_deployments(self, prefix=""): """ This endpoint lists all deployments. https://www.nomadproject.io/docs/http/deployments.html optional_arguments: - prefix, (default "") Specifies a string to filter deployments on based on an index prefix. This is specified as a querystring parameter. returns: list of dicts raises:
python
{ "resource": "" }
q270996
PJFMutators._get_random
test
def _get_random(self, obj_type): """ Get a random mutator from a list of mutators """
python
{ "resource": "" }
q270997
PJFMutators.get_mutator
test
def get_mutator(self, obj, obj_type): """ Get a random mutator for the given type """ if obj_type == unicode: obj_type = str
python
{ "resource": "" }
q270998
PJFMutators.get_string_polyglot_attack
test
def get_string_polyglot_attack(self, obj): """ Return a polyglot attack containing the original object """
python
{ "resource": "" }
q270999
PJFMutators.fuzz
test
def fuzz(self, obj): """ Perform the fuzzing """ buf = list(obj) FuzzFactor = random.randrange(1, len(buf)) numwrites=random.randrange(math.ceil((float(len(buf)) / FuzzFactor)))+1
python
{ "resource": "" }