_id stringlengths 2 7 | title stringlengths 1 88 | partition stringclasses 3 values | text stringlengths 31 13.1k | language stringclasses 1 value | meta_information dict |
|---|---|---|---|---|---|
q278600 | CopyDoc._parse_attr | test | def _parse_attr(self, tagname, attr, value):
"""
Parse attribute. Delegate to href parser for hrefs, otherwise return | python | {
"resource": ""
} |
q278601 | translate_key_values | test | def translate_key_values(adict, translations, default=''):
"""Modify the keys in adict to the ones in translations.
Be careful, this will modify your input dictionary.
The keys not present in translations will be left intact.
Parameters
----------
adict: a dictionary
translations: iterable of 2-tuples
Each 2-tuple must have the following format:
| python | {
"resource": ""
} |
q278602 | JSONMixin.to_json_str | test | def to_json_str(self):
"""Convert data to json string representation.
Returns:
json representation as string.
"""
| python | {
"resource": ""
} |
q278603 | find_file_match | test | def find_file_match(folder_path, regex=''):
"""
Returns absolute paths of files that match the regex within folder_path and
all its children folders.
Note: The regex matching is done using the match function
of the re module.
| python | {
"resource": ""
} |
q278604 | concat | test | def concat(ctx, *strings):
'''
Yields one string, concatenation of argument strings
'''
strings = flatten([ (s.compute(ctx) if callable(s) else s) for s in strings ])
strings = (next(string_arg(ctx, s), '') for s | python | {
"resource": ""
} |
q278605 | starts_with | test | def starts_with(ctx, full, part):
'''
Yields one boolean, whether the first string starts with the second
'''
full = next(string_arg(ctx, full), '')
| python | {
"resource": ""
} |
q278606 | contains | test | def contains(ctx, full, part):
'''
Yields one boolean, whether the first string contains the | python | {
"resource": ""
} |
q278607 | string_length | test | def string_length(ctx, s=None):
'''
Yields one number
'''
if s is None:
s = ctx.node
| python | {
"resource": ""
} |
q278608 | boolean | test | def boolean(ctx, obj):
'''
Yields one boolean, false if the argument sequence is empty, otherwise
* false if the first item is a boolean and false
* false if the first item is a number and positive or negative zero or NaN
* false if the first item is a string and ''
* true in all other cases | python | {
"resource": ""
} |
q278609 | foreach_ | test | def foreach_(ctx, seq, expr):
'''
Yields the result of applying an expression to each item in the input sequence.
* seq: input sequence
* expr: expression to be converted to string, then dynamically evaluated for each item on the sequence to produce the result
'''
from . import context, parse as uxpathparse
if hasattr(seq, 'compute'):
| python | {
"resource": ""
} |
q278610 | lookup_ | test | def lookup_(ctx, tableid, key):
'''
Yields a sequence of a single value, the result of looking up a value from the tables provided in the context, or an empty sequence if lookup is unsuccessful
* tableid: id of the lookup table to use
* expr: expression to be converted to string, then dynamically evaluated for each item on the sequence to produce the result
'''
| python | {
"resource": ""
} |
q278611 | replace_chars_for_svg_code | test | def replace_chars_for_svg_code(svg_content):
""" Replace known special characters to SVG code.
Parameters
----------
svg_content: str
Returns
-------
corrected_svg: str
Corrected SVG content
"""
result = svg_content
svg_char = [
| python | {
"resource": ""
} |
q278612 | _check_svg_file | test | def _check_svg_file(svg_file):
""" Try to read a SVG file if `svg_file` is a string.
Raise an exception in case of error or return the svg object.
If `svg_file` is a svgutils svg object, will just return it.
Parameters
----------
svg_file: str or svgutils.transform.SVGFigure object
If a `str`: path to a '.svg' file,
otherwise a svgutils svg object is expected.
Returns
-------
svgutils svg object
Raises
------
Exception if any error happens.
"""
if isinstance(svg_file, str):
try:
| python | {
"resource": ""
} |
q278613 | merge_svg_files | test | def merge_svg_files(svg_file1, svg_file2, x_coord, y_coord, scale=1):
""" Merge `svg_file2` in `svg_file1` in the given positions `x_coord`, `y_coord` and `scale`.
Parameters
----------
svg_file1: str or svgutils svg document object
Path to a '.svg' file.
svg_file2: str or svgutils svg document object
Path to a '.svg' file.
x_coord: float
Horizontal axis position of the `svg_file2` content.
y_coord: float
Vertical axis position of the `svg_file2` content.
scale: float
Scale to apply to `svg_file2` content.
Returns
| python | {
"resource": ""
} |
q278614 | merge_pdfs | test | def merge_pdfs(pdf_filepaths, out_filepath):
""" Merge all the PDF files in `pdf_filepaths` in a new PDF file `out_filepath`.
Parameters
----------
pdf_filepaths: list of str
Paths to PDF files.
out_filepath: str
Path to the result PDF file.
Returns
-------
| python | {
"resource": ""
} |
q278615 | _embed_font_to_svg | test | def _embed_font_to_svg(filepath, font_files):
""" Return the ElementTree of the SVG content in `filepath`
with the font content embedded.
"""
with open(filepath, 'r') as svgf:
tree = etree.parse(svgf)
if not font_files:
return tree
fontfaces = FontFaceGroup()
for font_file in font_files:
| python | {
"resource": ""
} |
q278616 | embed_font_to_svg | test | def embed_font_to_svg(filepath, outfile, font_files):
""" Write ttf and otf font content from `font_files`
in the svg file in `filepath` and write the result in
`outfile`.
Parameters
----------
filepath: str
The SVG file whose content must be modified.
outfile: str
The file path where | python | {
"resource": ""
} |
q278617 | SearchMethod._check_inputs | test | def _check_inputs(self):
''' make some basic checks on the inputs to make sure they are valid'''
try:
_ = self._inputs[0]
except TypeError:
raise RuntimeError(
"inputs should be iterable but found type='{0}', value="
"'{1}'".format(type(self._inputs), str(self._inputs)))
| python | {
"resource": ""
} |
q278618 | SearchMethod._check_function | test | def _check_function(self):
''' make some basic checks on the function to make sure it is valid'''
# note, callable is valid for Python 2 and Python 3.2 onwards but
# not inbetween
if not callable(self._function):
raise RuntimeError(
| python | {
"resource": ""
} |
q278619 | BruteForce._recurse | test | def _recurse(self, inputs, output):
'''internal recursion routine called by the run method that generates
all input combinations'''
if inputs:
my_input = inputs[0]
name = my_input.name
if my_input.state:
my_options = my_input.options(self.state)
else:
my_options = my_input.options
for option in my_options:
my_output = list(output)
| python | {
"resource": ""
} |
q278620 | create_input | test | def create_input(option, template_name, template_location="template"):
'''create an input file using jinja2 by filling a template
with the values from the option variable passed in.'''
# restructure option list into jinja2 input format
jinja2_input = {}
for item in option:
try:
jinja2_input.update(item)
except ValueError:
raise RuntimeError(
("inputs.py, create_input : format of item '{0}' is not "
"supported. Expecting a dictionary.".format(str(item))))
# load the template and fill it with the option variable contents
import jinja2
try:
template_loader = jinja2.FileSystemLoader(searchpath=template_location)
| python | {
"resource": ""
} |
q278621 | Subsets._recurse | test | def _recurse(self, inputs, output, depth, max_depth):
'''We work out all combinations using this internal recursion method'''
if depth < max_depth:
for index, option in enumerate(inputs):
my_output = list(output)
| python | {
"resource": ""
} |
q278622 | to_string | test | def to_string(obj):
'''
Cast an arbitrary object or sequence to a string type
'''
if isinstance(obj, LiteralWrapper):
val = obj.obj
elif isinstance(obj, Iterable) and not isinstance(obj, str):
val = next(obj, None)
else:
val = obj | python | {
"resource": ""
} |
q278623 | to_number | test | def to_number(obj):
'''
Cast an arbitrary object or sequence to a number type
'''
if isinstance(obj, LiteralWrapper):
val = obj.obj
elif isinstance(obj, Iterable) and not isinstance(obj, str):
val = next(obj, None)
else:
val = obj
if val is None:
#FIXME: Should be NaN, not 0
yield 0
elif isinstance(val, str):
yield float(val)
elif isinstance(val, node):
| python | {
"resource": ""
} |
q278624 | to_boolean | test | def to_boolean(obj):
'''
Cast an arbitrary sequence to a boolean type
'''
#if hasattr(obj, '__iter__'):
if isinstance(obj, LiteralWrapper):
val = obj.obj
elif isinstance(obj, Iterable) and not isinstance(obj, str):
val = next(obj, None)
else:
val = obj
if val is None:
yield False
elif isinstance(val, bool):
yield val
elif isinstance(val, str):
yield bool(str)
| python | {
"resource": ""
} |
q278625 | _serialize | test | def _serialize(xp_ast):
'''Generate token strings which, when joined together, form a valid
XPath serialization of the AST.'''
if hasattr(xp_ast, '_serialize'):
| python | {
"resource": ""
} |
q278626 | change_xml_encoding | test | def change_xml_encoding(filepath, src_enc, dst_enc='utf-8'):
""" Modify the encoding entry in the XML file.
Parameters
----------
filepath: str
Path to the file to be modified.
src_enc: str
Encoding that is written in the file
dst_enc: str
| python | {
"resource": ""
} |
q278627 | save_into_qrcode | test | def save_into_qrcode(text, out_filepath, color='', box_size=10, pixel_size=1850):
""" Save `text` in a qrcode svg image file.
Parameters
----------
text: str
The string to be codified in the QR image.
out_filepath: str
Path to the output file
color: str
A RGB color expressed in 6 hexadecimal values.
box_size: scalar
Size of the QR code boxes.
"""
try:
qr = qrcode.QRCode(version=1, error_correction=qrcode.constants.ERROR_CORRECT_L,
box_size=box_size, border=0, )
qr.add_data(text)
qr.make(fit=True)
| python | {
"resource": ""
} |
q278628 | launch | test | def launch(option):
'''Set the gromacs input data using the supplied input options, run
gromacs and extract and return the required outputs.'''
from melody.inputs import create_input
_ = create_input(option, template_name="input.mdp")
# save the input file in the appropriate place and launch gromacs using
# longbow ...
# determine if the run was | python | {
"resource": ""
} |
q278629 | call_command | test | def call_command(cmd_name, args_strings):
"""Call CLI command with arguments and returns its return value.
Parameters
----------
cmd_name: str
Command name or full path to the binary file.
arg_strings: str
Argument strings list.
Returns
-------
return_value
Command return value.
"""
if not os.path.isabs(cmd_name):
cmd_fullpath = which(cmd_name)
else:
cmd_fullpath = cmd_name
try:
cmd_line = [cmd_fullpath] + args_strings
log.debug('Calling: `{}`.'.format(' '.join(cmd_line)))
# retval = subprocess.check_call(cmd_line)
| python | {
"resource": ""
} |
q278630 | tex2pdf | test | def tex2pdf(tex_file, output_file=None, output_format='pdf'):
""" Call PDFLatex to convert TeX files to PDF.
Parameters
----------
tex_file: str
Path to the input LateX file.
output_file: str
Path to the output PDF file.
If None, will use the same output directory as the tex_file.
output_format: str
Output file format. Choices: 'pdf' or 'dvi'. Default: 'pdf'
Returns
-------
return_value
PDFLatex command call return value.
"""
if not os.path.exists(tex_file):
raise IOError('Could not find file {}.'.format(tex_file))
if output_format != 'pdf' and output_format != 'dvi':
raise ValueError("Invalid output format given {}. Can only accept 'pdf' or 'dvi'.".format(output_format))
cmd_name = 'pdflatex'
check_command(cmd_name)
args_strings = [cmd_name]
if output_file is not None:
args_strings += ['-output-directory="{}" '.format(os.path.abspath(os.path.dirname(output_file)))]
result_dir = os.path.dirname(output_file) if output_file else os.path.dirname(tex_file)
args_strings += ['-output-format="{}"'.format(output_format)]
| python | {
"resource": ""
} |
q278631 | GOLoopFuse.options | test | def options(self, my_psy):
'''Returns all potential loop fusion options for the psy object
provided'''
# compute options dynamically here as they may depend on previous
# changes to the psy tree
my_options = []
invokes = my_psy.invokes.invoke_list
#print "there are {0} invokes".format(len(invokes))
if self._dependent_invokes:
raise RuntimeError(
"dependent invokes assumes fusion in one invoke might "
"affect fusion in another invoke. This is not yet "
"implemented")
else:
# treat each invoke separately
for idx, invoke in enumerate(invokes):
print "invoke {0}".format(idx)
# iterate through each outer loop
| python | {
"resource": ""
} |
q278632 | transform | test | def transform(geom, to_sref):
"""Returns a transformed Geometry.
Arguments:
geom -- any coercible Geometry value or Envelope
to_sref -- SpatialReference or EPSG ID as int
"""
# If we have an envelope, assume it's in the target sref.
try:
geom = getattr(geom, 'polygon', Envelope(geom).polygon)
| python | {
"resource": ""
} |
q278633 | Geometry | test | def Geometry(*args, **kwargs):
"""Returns an ogr.Geometry instance optionally created from a geojson str
or dict. The spatial reference may also be provided.
"""
# Look for geojson as a positional or keyword arg.
arg = kwargs.pop('geojson', None) or len(args) and args[0]
try:
srs = kwargs.pop('srs', None) or arg.srs.wkt
except AttributeError:
srs = SpatialReference(4326)
if hasattr(arg, 'keys'):
geom = ogr.CreateGeometryFromJson(json.dumps(arg))
elif hasattr(arg, 'startswith'):
# WKB as hexadecimal string.
char = arg[0] if arg else ' '
i = char if isinstance(char, int) else ord(char)
if i in (0, 1):
geom = | python | {
"resource": ""
} |
q278634 | Envelope.expand | test | def expand(self, other):
"""Expands this envelope by the given Envelope or tuple.
Arguments:
other -- Envelope, two-tuple, or four-tuple
"""
if len(other) == 2:
other | python | {
"resource": ""
} |
q278635 | Envelope.intersect | test | def intersect(self, other):
"""Returns the intersection of this and another Envelope."""
inter = Envelope(tuple(self))
if inter.intersects(other):
mid = len(other) // 2
inter.ll = map(max, inter.ll, other[:mid])
| python | {
"resource": ""
} |
q278636 | Envelope.intersects | test | def intersects(self, other):
"""Returns true if this envelope intersects another.
Arguments:
other -- Envelope or tuple of (minX, minY, maxX, maxY)
"""
try:
| python | {
"resource": ""
} |
q278637 | Envelope.polygon | test | def polygon(self):
"""Returns an OGR Geometry for this envelope."""
ring = ogr.Geometry(ogr.wkbLinearRing)
for coord in self.ll, self.lr, self.ur, self.ul, self.ll:
| python | {
"resource": ""
} |
q278638 | Table.from_ZNM | test | def from_ZNM(cls, Z, N, M, name=''):
"""
Creates a table from arrays Z, N and M
Example:
________
>>> Z = [82, 82, 83]
>>> N = [126, 127, 130]
>>> M = [-21.34, -18.0, -14.45]
>>> Table.from_ZNM(Z, N, M, name='Custom Table')
Z N
82 126 -21.34
127 -18.00
83 130 -14.45
| python | {
"resource": ""
} |
q278639 | Table.to_file | test | def to_file(self, path):
"""Export the contents to a file as comma separated values.
Parameters
----------
path : string
File path where the data should be saved to
Example
-------
Export the last ten elements of AME2012 | python | {
"resource": ""
} |
q278640 | Table.select | test | def select(self, condition, name=''):
"""
Selects nuclei according to a condition on Z,N or M
Parameters
----------
condition : function,
Can have one of the signatures f(M), f(Z,N) or f(Z, N, M)
must return a boolean value
name: string, optional name for the resulting Table
Example:
--------
Select all nuclei with A > 160:
>>> A_gt_160 = lambda Z,N: Z + N > 160
>>> Table('AME2003').select(A_gt_160)
"""
if condition.func_code.co_argcount == 1:
idx = [(Z, N) for (Z, | python | {
"resource": ""
} |
q278641 | Table.at | test | def at(self, nuclei):
"""Return a selection of the Table at positions given by ``nuclei``
Parameters
----------
nuclei: list of tuples
A list where each element is tuple of the form (Z,N)
Example
-------
Return binding energies at magic nuclei: | python | {
"resource": ""
} |
q278642 | Table.intersection | test | def intersection(self, table):
"""
Select nuclei which also belong to ``table``
Parameters
----------
table: Table, Table object
Example:
| python | {
"resource": ""
} |
q278643 | Table.not_in | test | def not_in(self, table):
"""
Select nuclei not in table
Parameters
----------
table: Table, Table object from where nuclei should be removed
Example:
----------
Find the new nuclei in AME2003 with Z,N >= 8:
| python | {
"resource": ""
} |
q278644 | Table.odd_even | test | def odd_even(self):
"""
Selects odd-even nuclei from the table
"""
| python | {
"resource": ""
} |
q278645 | Table.even_odd | test | def even_odd(self):
"""
Selects even-odd nuclei from the table
"""
| python | {
"resource": ""
} |
q278646 | Table.even_even | test | def even_even(self):
"""
Selects even-even nuclei from the table
"""
| python | {
"resource": ""
} |
q278647 | Table.error | test | def error(self, relative_to='AME2003'):
"""
Calculate error difference
Parameters
----------
relative_to : string,
a valid mass table name.
Example:
| python | {
"resource": ""
} |
q278648 | Table.rmse | test | def rmse(self, relative_to='AME2003'):
"""Calculate root mean squared error
Parameters
----------
relative_to : string,
a valid mass table name.
Example:
----------
>>> template = '{0:10}|{1:^6.2f}|{2:^6.2f}|{3:^6.2f}'
>>> print 'Model ', 'AME95 ', 'AME03 ', 'AME12 ' # Table header
... for name in Table.names:
... print template.format(name, Table(name).rmse(relative_to='AME1995'),
... Table(name).rmse(relative_to='AME2003'),
... Table(name).rmse(relative_to='AME2012'))
Model AME95 AME03 AME12
AME2003 | 0.13 | 0.00 | 0.13
AME2003all| 0.42 | 0.40 | 0.71
AME2012 | 0.16 | 0.13 | 0.00
| python | {
"resource": ""
} |
q278649 | Table.binding_energy | test | def binding_energy(self):
"""
Return binding energies instead of mass excesses
"""
M_P = 938.2723
# MeV
M_E = 0.5110
| python | {
"resource": ""
} |
q278650 | Table.s2n | test | def s2n(self):
"""Return 2 neutron separation energy"""
M_N = 8.0713171 # neutron mass excess in MeV
f = lambda | python | {
"resource": ""
} |
q278651 | Table.s1n | test | def s1n(self):
"""Return 1 neutron separation energy"""
M_N = 8.0713171 # neutron mass excess in MeV
f = | python | {
"resource": ""
} |
q278652 | Table.s2p | test | def s2p(self):
"""Return 2 proton separation energy"""
M_P = 7.28897050 # proton mass excess in MeV
f = lambda | python | {
"resource": ""
} |
q278653 | Table.s1p | test | def s1p(self):
"""Return 1 proton separation energy"""
M_P = 7.28897050 # proton mass excess in MeV
f | python | {
"resource": ""
} |
q278654 | Table.derived | test | def derived(self, name, relative_coords, formula):
"""Helper function for derived quantities"""
relZ, relN = relative_coords
daughter_idx = [(x[0] + relZ, x[1] + relN) for x in self.df.index]
| python | {
"resource": ""
} |
q278655 | _uses_db | test | def _uses_db(func, self, *args, **kwargs):
""" Use as a decorator for operations on the database, to ensure connection setup and
teardown. Can only be used on methods on objects with a `self.session` attribute.
"""
if not self.session:
_logger.debug('Creating new db session')
self._init_db_session()
try:
ret = func(self, *args, | python | {
"resource": ""
} |
q278656 | Domain.derive_key | test | def derive_key(self, master_password):
""" Computes the key from the salt and the master password. """
encoder = encoding.Encoder(self.charset)
bytes = ('%s:%s' % (master_password, self.name)).encode('utf8')
start_time = time.clock()
# we fix the scrypt parameters in case the defaults change
digest = scrypt.hash(bytes, self.salt, N=1<<14, r=8, p=1) | python | {
"resource": ""
} |
q278657 | PWM.bootstrap | test | def bootstrap(self, path_or_uri):
""" Initialize a database.
:param database_path: The absolute path to the database to initialize.
| python | {
"resource": ""
} |
q278658 | PWM.search | test | def search(self, query):
""" Search the database for the given query. Will find partial matches. """
| python | {
"resource": ""
} |
q278659 | PWM.modify_domain | test | def modify_domain(self, domain_name, new_salt=False, username=None):
""" Modify an existing domain.
:param domain_name: The name of the domain to modify.
:param new_salt: Whether to generate a new salt for the domain.
:param username: If given, change domain username to this value. | python | {
"resource": ""
} |
q278660 | PWM.create_domain | test | def create_domain(self, domain_name, username=None, alphabet=Domain.DEFAULT_ALPHABET,
length=Domain.DEFAULT_KEY_LENGTH):
""" Create a new domain entry in the database.
:param username: The username to associate with this domain.
:param alphabet: A character set restriction to impose on keys generated for this domain.
:param length: The length of the generated key, in case of restrictions on the site.
| python | {
"resource": ""
} |
q278661 | extract_hbs | test | def extract_hbs(fileobj, keywords, comment_tags, options):
"""Extract messages from Handlebars templates.
It returns an iterator yielding tuples in the following form ``(lineno,
funcname, message, comments)``.
TODO: Things to improve:
--- Return comments
"""
server = get_pipeserver() | python | {
"resource": ""
} |
q278662 | vsiprefix | test | def vsiprefix(path):
"""Returns a GDAL virtual filesystem prefixed path.
Arguments:
path -- file path as str
"""
vpath = path.lower()
scheme = VSI_SCHEMES.get(urlparse(vpath).scheme, '')
for ext in VSI_TYPES:
if ext in vpath:
filesys = VSI_TYPES[ext] | python | {
"resource": ""
} |
q278663 | SpatialReference.srid | test | def srid(self):
"""Returns the EPSG ID as int if it exists."""
epsg_id = (self.GetAuthorityCode('PROJCS') or
| python | {
"resource": ""
} |
q278664 | main | test | def main():
""" Main entry point for the CLI. """
args = get_args()
ret_code = args.target(args)
| python | {
"resource": ""
} |
q278665 | _init_logging | test | def _init_logging(verbose=False):
""" Initialize loggers. """
config = {
'version': 1,
'formatters': {
'console': {
'format': '* %(message)s',
}
},
'handlers': {
'console': {
'class': 'logging.StreamHandler',
'level': 'DEBUG',
'formatter': 'console',
'stream': 'ext://sys.stdout',
}
},
'loggers': {
'pwm': {
'level': 'DEBUG' if verbose else 'INFO',
'handlers': ['console'],
'propagate': True,
},
| python | {
"resource": ""
} |
q278666 | update_file | test | def update_file(url, filename):
"""Update the content of a single file."""
resp = urlopen(url)
if resp.code != 200:
raise Exception('GET {} failed.'.format(url)) | python | {
"resource": ""
} |
q278667 | available_drivers | test | def available_drivers():
"""Returns a dictionary of enabled GDAL Driver metadata keyed by the
'ShortName' attribute.
"""
drivers = {}
for i | python | {
"resource": ""
} |
q278668 | driver_for_path | test | def driver_for_path(path, drivers=None):
"""Returns the gdal.Driver for a path or None based on the file extension.
Arguments:
path -- file path as str with a GDAL supported file extension
| python | {
"resource": ""
} |
q278669 | geom_to_array | test | def geom_to_array(geom, size, affine):
"""Converts an OGR polygon to a 2D NumPy array.
Arguments:
geom -- OGR Geometry
size -- array size in pixels as a tuple of (width, height)
affine -- AffineTransform
"""
| python | {
"resource": ""
} |
q278670 | rasterize | test | def rasterize(layer, rast):
"""Returns a Raster from layer features.
Arguments:
layer -- Layer to rasterize
rast -- Raster with target affine, size, and sref
"""
driver = ImageDriver('MEM')
r2 = driver.raster(driver.ShortName, rast.size)
r2.affine = rast.affine
sref = rast.sref
if not sref.srid:
sref = SpatialReference(4326)
| python | {
"resource": ""
} |
q278671 | open | test | def open(path, mode=gdalconst.GA_ReadOnly):
"""Returns a Raster instance.
Arguments:
path -- local or remote path as str or file-like object
Keyword args:
mode -- gdal constant representing access mode
"""
path = getattr(path, 'name', path)
try:
return Raster(vsiprefix(path), mode)
| python | {
"resource": ""
} |
q278672 | frombytes | test | def frombytes(data, size, bandtype=gdal.GDT_Byte):
"""Returns an in-memory raster initialized from a pixel buffer.
Arguments:
data -- byte buffer of raw pixel data
size -- two or three-tuple of (xsize, ysize, | python | {
"resource": ""
} |
q278673 | ImageDriver.copy | test | def copy(self, source, dest):
"""Returns a copied Raster instance.
Arguments:
source -- the source Raster instance or filepath as str
dest -- destination filepath as str
"""
if not self.copyable:
raise IOError('Driver does not support raster copying')
if not isinstance(source, Raster):
source = Raster(source)
should_close = True
else:
should_close = False
if source.name == dest:
| python | {
"resource": ""
} |
q278674 | ImageDriver.options | test | def options(self):
"""Returns a dict of driver specific raster creation options.
See GDAL format docs at http://www.gdal.org/formats_list.html
"""
if self._options is None:
try:
elem = ET.fromstring(
self.info.get('DMD_CREATIONOPTIONLIST', ''))
except ET.ParseError:
elem = []
opts = {}
for child in elem:
| python | {
"resource": ""
} |
q278675 | ImageDriver.raster | test | def raster(self, path, size, bandtype=gdal.GDT_Byte):
"""Returns a new Raster instance.
gdal.Driver.Create() does not support all formats.
Arguments:
path -- file object or path as str
size -- two or three-tuple of (xsize, ysize, bandcount)
bandtype -- GDAL pixel data type
"""
path = getattr(path, 'name', path)
try:
is_multiband = len(size) > 2
nx, ny, nbands = size if is_multiband else size + (1,)
except (TypeError, ValueError) as exc:
exc.args = ('Size must be 2 or 3-item sequence',)
raise
| python | {
"resource": ""
} |
q278676 | Raster.SetGeoTransform | test | def SetGeoTransform(self, affine):
"""Sets the affine transformation.
Intercepts the gdal.Dataset call to ensure use as a property setter.
Arguments:
| python | {
"resource": ""
} |
q278677 | Raster.array | test | def array(self, envelope=()):
"""Returns an NDArray, optionally subset by spatial envelope.
Keyword args:
envelope -- coordinate extent tuple or Envelope
"""
args = ()
| python | {
"resource": ""
} |
q278678 | Raster.envelope | test | def envelope(self):
"""Returns the minimum bounding rectangle as a tuple of min X, min Y,
max X, max Y.
"""
if self._envelope is None:
origin = self.affine.origin
ur_x = origin[0] + self.ds.RasterXSize * self.affine.scale[0]
ll_y = origin[1] | python | {
"resource": ""
} |
q278679 | Raster.driver | test | def driver(self):
"""Returns the underlying ImageDriver instance."""
if self._driver is None:
| python | {
"resource": ""
} |
q278680 | Raster.new | test | def new(self, size=(), affine=None):
"""Derive new Raster instances.
Keyword args:
size -- tuple of image size (width, height)
affine -- AffineTransform or six-tuple of geotransformation values
"""
size = size or self.size + (len(self),)
band = self.ds.GetRasterBand(1)
driver = ImageDriver('MEM')
rcopy = driver.raster(driver.ShortName, size, band.DataType)
rcopy.sref = self.GetProjection()
| python | {
"resource": ""
} |
q278681 | Raster.masked_array | test | def masked_array(self, geometry=None):
"""Returns a MaskedArray using nodata values.
Keyword args:
geometry -- any geometry, envelope, or coordinate extent tuple
"""
if geometry is None:
return self._masked_array()
geom = transform(geometry, self.sref)
env = Envelope.from_geom(geom).intersect(self.envelope)
arr = self._masked_array(env)
if geom.GetGeometryType() != ogr.wkbPoint:
| python | {
"resource": ""
} |
q278682 | Raster.nodata | test | def nodata(self):
"""Returns read only property for band nodata value, assuming single
| python | {
"resource": ""
} |
q278683 | Raster.ReadRaster | test | def ReadRaster(self, *args, **kwargs):
"""Returns raster data bytes for partial or full extent.
Overrides gdal.Dataset.ReadRaster() with the full raster size by
default.
"""
args = args or | python | {
"resource": ""
} |
q278684 | Raster.resample | test | def resample(self, size, interpolation=gdalconst.GRA_NearestNeighbour):
"""Returns a new instance resampled to provided size.
Arguments:
size -- tuple of x,y image dimensions
"""
# Find the scaling factor for pixel size.
factors = (size[0] / float(self.RasterXSize),
| python | {
"resource": ""
} |
q278685 | Raster.save | test | def save(self, to, driver=None):
"""Save this instance to the path and format provided.
Arguments:
to -- output path as str, file, or MemFileIO instance
Keyword args:
driver -- GDAL driver name as string or ImageDriver
"""
path = getattr(to, 'name', to)
if not driver and hasattr(path, 'encode'):
| python | {
"resource": ""
} |
q278686 | Raster.SetProjection | test | def SetProjection(self, sref):
"""Sets the spatial reference.
Intercepts the gdal.Dataset call to ensure use as a property setter.
Arguments:
sref -- SpatialReference or any format supported by the constructor
"""
if | python | {
"resource": ""
} |
q278687 | Raster.warp | test | def warp(self, to_sref, dest=None, interpolation=gdalconst.GRA_NearestNeighbour):
"""Returns a new reprojected instance.
Arguments:
to_sref -- spatial reference as a proj4 or wkt string, or a
SpatialReference
Keyword args:
dest -- filepath as str
interpolation -- GDAL interpolation type
"""
if not hasattr(to_sref, 'ExportToWkt'):
to_sref = SpatialReference(to_sref)
dest_wkt = to_sref.ExportToWkt()
dtype = self[0].DataType
err_thresh = 0.125
# Determine new values for destination raster dimensions and
# geotransform.
vrt = gdal.AutoCreateWarpedVRT(self.ds, None, dest_wkt,
interpolation, err_thresh)
if vrt is None:
raise ValueError('Could not warp %s to %s' % (self, dest_wkt))
warpsize = (vrt.RasterXSize, vrt.RasterYSize, len(self))
warptrans = vrt.GetGeoTransform()
vrt = None
if dest is None:
| python | {
"resource": ""
} |
q278688 | calc_chunklen | test | def calc_chunklen(alph_len):
'''
computes the ideal conversion ratio for the given alphabet.
A ratio is considered ideal when the number of bits in one output
encoding chunk that don't add up to one input encoding chunk is minimal.
'''
binlen, enclen = min([
| python | {
"resource": ""
} |
q278689 | lookup_alphabet | test | def lookup_alphabet(charset):
'''
retrieves a named charset or treats the input as a custom alphabet and use that
'''
| python | {
"resource": ""
} |
q278690 | Encoder._encode_chunk | test | def _encode_chunk(self, data, index):
'''
gets a chunk from the input data, converts it to a number | python | {
"resource": ""
} |
q278691 | Encoder._chunk_to_long | test | def _chunk_to_long(self, chunk):
'''
parses a chunk of bytes to integer using big-endian representation
'''
return sum([
256**(self.chunklen[0]-1-i) | python | {
"resource": ""
} |
q278692 | Encoder._get_chunk | test | def _get_chunk(self, data, index):
'''
partition the data into chunks and retrieve the chunk at the given index
'''
| python | {
"resource": ""
} |
q278693 | memoize | test | def memoize(func):
"""Cache result of function call."""
cache = {}
@wraps(func)
def inner(filename):
if filename not in cache:
| python | {
"resource": ""
} |
q278694 | _regexp | test | def _regexp(filename):
"""Get a list of patterns from a file and make a regular expression."""
| python | {
"resource": ""
} |
q278695 | normalize_date_format | test | def normalize_date_format(date):
'''
Dates can be defined in many ways, but zipline use
aware datetime objects only. Plus, the software work
with utc timezone so we convert it.
'''
if isinstance(date, int):
# This is probably epoch time
date = time.strftime('%Y-%m-%d %H:%M:%S',
| python | {
"resource": ""
} |
q278696 | _detect_timezone | test | def _detect_timezone():
'''
Get timezone as set by the system
'''
default_timezone = 'America/New_York'
locale_code = locale.getdefaultlocale()
| python | {
"resource": ""
} |
q278697 | FinancialDataStatusDatastatus.to_dict | test | def to_dict(self):
"""
Returns the model properties as a dict
"""
result = {}
for attr, _ in iteritems(self.swagger_types):
value = getattr(self, attr)
if isinstance(value, list):
result[attr] = list(map(
lambda x: x.to_dict() if hasattr(x, "to_dict") else x,
value
| python | {
"resource": ""
} |
q278698 | activate_pdb_hook | test | def activate_pdb_hook():
''' Catch exceptions with a prompt for post-mortem analyzis'''
def debug_exception(type_exception, value, tb):
import pdb
| python | {
"resource": ""
} |
q278699 | emphasis | test | def emphasis(obj, align=True):
''' Clearer data printing '''
if isinstance(obj, dict):
if align:
pretty_msg = os.linesep.join(
["%25s: %s" % (k, obj[k]) for k in sorted(obj.keys())])
else:
| python | {
"resource": ""
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.