_id stringlengths 2 7 | title stringlengths 1 88 | partition stringclasses 3
values | text stringlengths 75 19.8k | language stringclasses 1
value | meta_information dict |
|---|---|---|---|---|---|
q21800 | TimeLine.zoom_out | train | def zoom_out(self):
"""Decrease zoom factor and redraw TimeLine"""
index = self._zoom_factors.index(self._zoom_factor)
if index == 0:
# Already zoomed out all the way
return
self._zoom_factor = self._zoom_factors[index - 1]
if self._zoom_factors.index(self... | python | {
"resource": ""
} |
q21801 | TimeLine.zoom_reset | train | def zoom_reset(self):
"""Reset the zoom factor to default and redraw TimeLine"""
self._zoom_factor = self._zoom_factors[0] if self._zoom_default == 0 else self._zoom_default
if self._zoom_factors.index(self._zoom_factor) == 0:
self._button_zoom_out.config(state=tk.DISABLED)
... | python | {
"resource": ""
} |
q21802 | TimeLine.set_time | train | def set_time(self, time):
"""
Set the time marker to a specific time
:param time: Time to set for the time marker on the TimeLine
:type time: float
"""
x = self.get_time_position(time)
_, y = self._canvas_ticks.coords(self._time_marker_image)
self._canvas... | python | {
"resource": ""
} |
q21803 | TimeLine._time_show | train | def _time_show(self):
"""Show the time marker window"""
if not self._time_visible:
self._time_visible = True
self._time_window = tk.Toplevel(self)
self._time_window.attributes("-topmost", True)
self._time_window.overrideredirect(True)
self._tim... | python | {
"resource": ""
} |
q21804 | TimeLine.tag_configure | train | def tag_configure(self, tag_name, **kwargs):
"""
Create a marker tag
:param tag_name: Identifier for the tag
:param move_callback: Callback to be called upon moving a
marker. Arguments to callback:
``(iid: str, (old_start: float, old_finish: float),
... | python | {
"resource": ""
} |
q21805 | TimeLine.marker_tags | train | def marker_tags(self, iid):
"""Generator for all the tags of a certain marker"""
tags = self._markers[iid]["tags"]
for tag in tags:
yield tag | python | {
"resource": ""
} |
q21806 | TimeLine._set_scroll_v | train | def _set_scroll_v(self, *args):
"""Scroll both categories Canvas and scrolling container"""
self._canvas_categories.yview(*args)
self._canvas_scroll.yview(*args) | python | {
"resource": ""
} |
q21807 | TimeLine._set_scroll | train | def _set_scroll(self, *args):
"""Set horizontal scroll of scroll container and ticks Canvas"""
self._canvas_scroll.xview(*args)
self._canvas_ticks.xview(*args) | python | {
"resource": ""
} |
q21808 | TimeLine.get_time_position | train | def get_time_position(self, time):
"""
Get x-coordinate for given time
:param time: Time to determine x-coordinate on Canvas for
:type time: float
:return: X-coordinate for the given time
:rtype: int
:raises: ValueError
"""
if time < self._start o... | python | {
"resource": ""
} |
q21809 | TimeLine.get_position_time | train | def get_position_time(self, position):
"""
Get time for x-coordinate
:param position: X-coordinate position to determine time for
:type position: int
:return: Time for the given x-coordinate
:rtype: float
"""
return self._start + position * (self._resolut... | python | {
"resource": ""
} |
q21810 | TimeLine.get_time_string | train | def get_time_string(time, unit):
"""
Create a properly formatted string given a time and unit
:param time: Time to format
:type time: float
:param unit: Unit to apply format of. Only supports hours ('h')
and minutes ('m').
:type unit: str
:return: A s... | python | {
"resource": ""
} |
q21811 | TimeLine._right_click | train | def _right_click(self, event):
"""Function bound to right click event for marker canvas"""
iid = self.current_iid
if iid is None:
if self._menu is not None:
self._menu.post(event.x, event.y)
return
args = (iid, (event.x_root, event.y_root))
... | python | {
"resource": ""
} |
q21812 | TimeLine._left_click | train | def _left_click(self, event):
"""Function bound to left click event for marker canvas"""
self.update_active()
iid = self.current_iid
if iid is None:
return
args = (iid, event.x_root, event.y_root)
self.call_callbacks(iid, "left_callback", args) | python | {
"resource": ""
} |
q21813 | TimeLine.update_state | train | def update_state(self, iid, state):
"""
Set a custom state of the marker
:param iid: identifier of the marker to set the state of
:type iid: str
:param state: supports "active", "hover", "normal"
:type state: str
"""
if state not in ["normal", "hover", "a... | python | {
"resource": ""
} |
q21814 | TimeLine.update_active | train | def update_active(self):
"""Update the active marker on the marker Canvas"""
if self.active is not None:
self.update_state(self.active, "normal")
if self.current_iid == self.active:
self._active = None
return
self._active = self.current_iid
if ... | python | {
"resource": ""
} |
q21815 | TimeLine.call_callbacks | train | def call_callbacks(self, iid, type, args):
"""
Call the available callbacks for a certain marker
:param iid: marker identifier
:type iid: str
:param type: type of callback (key in tag dictionary)
:type type: str
:param args: arguments for the callback
:ty... | python | {
"resource": ""
} |
q21816 | TimeLine.time | train | def time(self):
"""
Current value the time marker is pointing to
:rtype: float
"""
x, _, = self._canvas_ticks.coords(self._time_marker_image)
return self.get_position_time(x) | python | {
"resource": ""
} |
q21817 | TimeLine.current | train | def current(self):
"""
Currently active item on the _timeline Canvas
:rtype: str
"""
results = self._timeline.find_withtag(tk.CURRENT)
return results[0] if len(results) != 0 else None | python | {
"resource": ""
} |
q21818 | TimeLine.current_iid | train | def current_iid(self):
"""
Currently active item's iid
:rtype: str
"""
current = self.current
if current is None or current not in self._canvas_markers:
return None
return self._canvas_markers[current] | python | {
"resource": ""
} |
q21819 | TimeLine.pixel_width | train | def pixel_width(self):
"""
Width of the whole TimeLine in pixels
:rtype: int
"""
return self.zoom_factor * ((self._finish - self._start) / self._resolution) | python | {
"resource": ""
} |
q21820 | TimeLine.configure | train | def configure(self, cnf={}, **kwargs):
"""Update options of the TimeLine widget"""
kwargs.update(cnf)
TimeLine.check_kwargs(kwargs)
scrollbars = 'autohidescrollbars' in kwargs
for option in self.options:
attribute = "_" + option
setattr(self, attribute, kw... | python | {
"resource": ""
} |
q21821 | TimeLine.cget | train | def cget(self, item):
"""Return the value of an option"""
return getattr(self, "_" + item) if item in self.options else ttk.Frame.cget(self, item) | python | {
"resource": ""
} |
q21822 | TimeLine.itemconfigure | train | def itemconfigure(self, iid, rectangle_options, text_options):
"""
Configure options of items drawn on the Canvas
Low-level access to the individual elements of markers and other
items drawn on the timeline Canvas. All modifications are
overwritten when the TimeLine is redrawn.
... | python | {
"resource": ""
} |
q21823 | TimeLine.calculate_text_coords | train | def calculate_text_coords(rectangle_coords):
"""Calculate Canvas text coordinates based on rectangle coords"""
return (int(rectangle_coords[0] + (rectangle_coords[2] - rectangle_coords[0]) / 2),
int(rectangle_coords[1] + (rectangle_coords[3] - rectangle_coords[1]) / 2)) | python | {
"resource": ""
} |
q21824 | TimeLine.check_marker_kwargs | train | def check_marker_kwargs(self, kwargs):
"""
Check the types of the keyword arguments for marker creation
:param kwargs: dictionary of options for marker creation
:type kwargs: dict
:raises: TypeError, ValueError
"""
text = kwargs.get("text", "")
if not isi... | python | {
"resource": ""
} |
q21825 | ScrolledFrame.__grid_widgets | train | def __grid_widgets(self):
"""Places all the child widgets in the appropriate positions."""
scrollbar_column = 0 if self.__compound is tk.LEFT else 2
self._canvas.grid(row=0, column=1, sticky="nswe")
self._scrollbar.grid(row=0, column=scrollbar_column, sticky="ns") | python | {
"resource": ""
} |
q21826 | AutoHideScrollbar._get_info | train | def _get_info(self, layout):
"""Alternative to pack_info and place_info in case of bug."""
info = str(self.tk.call(layout, 'info', self._w)).split("-")
dic = {}
for i in info:
if i:
key, val = i.strip().split()
dic[key] = val
return dic | python | {
"resource": ""
} |
q21827 | CheckboxTreeview.expand_all | train | def expand_all(self):
"""Expand all items."""
def aux(item):
self.item(item, open=True)
children = self.get_children(item)
for c in children:
aux(c)
children = self.get_children("")
for c in children:
aux(c) | python | {
"resource": ""
} |
q21828 | CheckboxTreeview.collapse_all | train | def collapse_all(self):
"""Collapse all items."""
def aux(item):
self.item(item, open=False)
children = self.get_children(item)
for c in children:
aux(c)
children = self.get_children("")
for c in children:
aux(c) | python | {
"resource": ""
} |
q21829 | CheckboxTreeview.change_state | train | def change_state(self, item, state):
"""
Replace the current state of the item.
i.e. replace the current state tag but keeps the other tags.
:param item: item id
:type item: str
:param state: "checked", "unchecked" or "tristate": new state of the item
:... | python | {
"resource": ""
} |
q21830 | CheckboxTreeview.get_checked | train | def get_checked(self):
"""Return the list of checked items that do not have any child."""
checked = []
def get_checked_children(item):
if not self.tag_has("unchecked", item):
ch = self.get_children(item)
if not ch and self.tag_has("checked", item):
... | python | {
"resource": ""
} |
q21831 | CheckboxTreeview._check_descendant | train | def _check_descendant(self, item):
"""Check the boxes of item's descendants."""
children = self.get_children(item)
for iid in children:
self.change_state(iid, "checked")
self._check_descendant(iid) | python | {
"resource": ""
} |
q21832 | CheckboxTreeview._tristate_parent | train | def _tristate_parent(self, item):
"""
Put the box of item in tristate and change the state of the boxes of
item's ancestors accordingly.
"""
self.change_state(item, "tristate")
parent = self.parent(item)
if parent:
self._tristate_parent(parent) | python | {
"resource": ""
} |
q21833 | CheckboxTreeview._uncheck_descendant | train | def _uncheck_descendant(self, item):
"""Uncheck the boxes of item's descendant."""
children = self.get_children(item)
for iid in children:
self.change_state(iid, "unchecked")
self._uncheck_descendant(iid) | python | {
"resource": ""
} |
q21834 | CheckboxTreeview._uncheck_ancestor | train | def _uncheck_ancestor(self, item):
"""
Uncheck the box of item and change the state of the boxes of item's
ancestors accordingly.
"""
self.change_state(item, "unchecked")
parent = self.parent(item)
if parent:
children = self.get_children(parent)
... | python | {
"resource": ""
} |
q21835 | CheckboxTreeview._box_click | train | def _box_click(self, event):
"""Check or uncheck box when clicked."""
x, y, widget = event.x, event.y, event.widget
elem = widget.identify("element", x, y)
if "image" in elem:
# a box was clicked
item = self.identify_row(y)
if self.tag_has("unchecked",... | python | {
"resource": ""
} |
q21836 | TickScale._apply_style | train | def _apply_style(self):
"""Apply the scale style to the frame and labels."""
ttk.Frame.configure(self, style=self._style_name + ".TFrame")
self.label.configure(style=self._style_name + ".TLabel")
bg = self.style.lookup('TFrame', 'background', default='light grey')
for label in se... | python | {
"resource": ""
} |
q21837 | TickScale._init | train | def _init(self):
"""Create and grid the widgets."""
for label in self.ticklabels:
label.destroy()
self.label.place_forget()
self.ticks = []
self.ticklabels = []
if self._resolution > 0:
nb_steps = round((self.scale.cget('to') - self.scale.cget('fro... | python | {
"resource": ""
} |
q21838 | TickScale._place_ticks_horizontal | train | def _place_ticks_horizontal(self):
"""Display the ticks for a horizontal scale."""
# first tick
tick = self.ticks[0]
label = self.ticklabels[0]
x = self.convert_to_pixels(tick)
half_width = label.winfo_reqwidth() / 2
if x - half_width < 0:
x = half_wid... | python | {
"resource": ""
} |
q21839 | TickScale._place_ticks_vertical | train | def _place_ticks_vertical(self):
"""Display the ticks for a vertical slider."""
for tick, label in zip(self.ticks, self.ticklabels):
y = self.convert_to_pixels(tick)
label.place_configure(y=y) | python | {
"resource": ""
} |
q21840 | TickScale._increment | train | def _increment(self, *args):
"""Move the slider only by increment given by resolution."""
value = self._var.get()
if self._resolution:
value = self._start + int(round((value - self._start) / self._resolution)) * self._resolution
self._var.set(value)
self.display_v... | python | {
"resource": ""
} |
q21841 | TickScale._update_display | train | def _update_display(self, event=None):
"""Redisplay the ticks and the label so that they adapt to the new size of the scale."""
try:
if self._showvalue:
self.display_value(self.scale.get())
if self._tickinterval:
self.place_ticks()
except I... | python | {
"resource": ""
} |
q21842 | ColorSquare._fill | train | def _fill(self):
"""Create the gradient."""
r, g, b = hue2col(self._hue)
width = self.winfo_width()
height = self.winfo_height()
h = float(height - 1)
w = float(width - 1)
if height:
c = [(r + i / h * (255 - r), g + i / h * (255 - g), b + i / h * (255 ... | python | {
"resource": ""
} |
q21843 | ColorSquare._draw | train | def _draw(self, color):
"""Draw the gradient and the selection cross on the canvas."""
width = self.winfo_width()
height = self.winfo_height()
self.delete("bg")
self.delete("cross_h")
self.delete("cross_v")
del self.bg
self.bg = tk.PhotoImage(width=width, ... | python | {
"resource": ""
} |
q21844 | ColorSquare.set_hue | train | def set_hue(self, value):
"""
Change hue.
:param value: new hue value (between 0 and 360)
:type value: int
"""
old = self._hue
self._hue = value
if value != old:
self._fill()
self.event_generate("<<ColorChanged>>") | python | {
"resource": ""
} |
q21845 | ColorSquare._on_click | train | def _on_click(self, event):
"""Move cross on click."""
x = event.x
y = event.y
self.coords('cross_h', 0, y, self.winfo_width(), y)
self.coords('cross_v', x, 0, x, self.winfo_height())
self.event_generate("<<ColorChanged>>") | python | {
"resource": ""
} |
q21846 | ColorSquare._on_move | train | def _on_move(self, event):
"""Make the cross follow the cursor."""
w = self.winfo_width()
h = self.winfo_height()
x = min(max(event.x, 0), w)
y = min(max(event.y, 0), h)
self.coords('cross_h', 0, y, w, y)
self.coords('cross_v', x, 0, x, h)
self.event_gener... | python | {
"resource": ""
} |
q21847 | ColorSquare.get | train | def get(self):
"""
Get selected color.
:return: color under cursor as a (RGB, HSV, HEX) tuple
"""
x = self.coords('cross_v')[0]
y = self.coords('cross_h')[1]
xp = min(x, self.bg.width() - 1)
yp = min(y, self.bg.height() - 1)
try:
r, g,... | python | {
"resource": ""
} |
q21848 | ColorSquare.set_hsv | train | def set_hsv(self, sel_color):
"""
Put cursor on sel_color given in HSV.
:param sel_color: color in HSV format
:type sel_color: sequence(int)
"""
width = self.winfo_width()
height = self.winfo_height()
h, s, v = sel_color
self.set_hue(h)
x ... | python | {
"resource": ""
} |
q21849 | AdyenClient._determine_hpp_url | train | def _determine_hpp_url(self, platform, action):
"""This returns the Adyen HPP endpoint based on the provided platform,
and action.
Args:
platform (str): Adyen platform, ie 'live' or 'test'.
action (str): the HPP action to perform.
possible actions: select, ... | python | {
"resource": ""
} |
q21850 | HTTPClient._pycurl_post | train | def _pycurl_post(self,
url,
json=None,
data=None,
username="",
password="",
headers={},
timeout=30):
"""This function will POST to the url endpoint using pycurl. ret... | python | {
"resource": ""
} |
q21851 | HTTPClient._requests_post | train | def _requests_post(self, url,
json=None,
data=None,
username="",
password="",
xapikey="",
headers=None,
timeout=30):
"""This function will POST to the ... | python | {
"resource": ""
} |
q21852 | HTTPClient._urllib_post | train | def _urllib_post(self, url,
json="",
data="",
username="",
password="",
headers=None,
timeout=30):
"""This function will POST to the url endpoint using urllib2. returning
an Ady... | python | {
"resource": ""
} |
q21853 | check_in | train | def check_in(request, action):
"""This function checks for missing properties in the request dict
for the corresponding action."""
if not request:
req_str = ""
for idx, val in enumerate(actions[action]):
req_str += "\n" + val
erstr = "Provide a request dict with the follo... | python | {
"resource": ""
} |
q21854 | resolve_type_name | train | def resolve_type_name(ctx, param, value): # pylint: disable=unused-argument
"""Resolve CLI option type name"""
def _resolve(value):
"""Resolve single type name"""
value = [
type_id
for type_id, type_name in W1ThermSensor.TYPE_NAMES.items()
if type_name == va... | python | {
"resource": ""
} |
q21855 | ls | train | def ls(types, as_json): # pylint: disable=invalid-name
"""List all available sensors"""
sensors = W1ThermSensor.get_available_sensors(types)
if as_json:
data = [
{"id": i, "hwid": s.id, "type": s.type_name}
for i, s in enumerate(sensors, 1)
]
click.echo(json... | python | {
"resource": ""
} |
q21856 | all | train | def all(types, unit, precision, as_json): # pylint: disable=redefined-builtin
"""Get temperatures of all available sensors"""
sensors = W1ThermSensor.get_available_sensors(types)
temperatures = []
for sensor in sensors:
if precision:
sensor.set_precision(precision, persist=False)
... | python | {
"resource": ""
} |
q21857 | get | train | def get(id_, hwid, type_, unit, precision, as_json):
"""Get temperature of a specific sensor"""
if id_ and (hwid or type_):
raise click.BadOptionUsage(
"If --id is given --hwid and --type are not allowed."
)
if id_:
try:
sensor = W1ThermSensor.get_available_s... | python | {
"resource": ""
} |
q21858 | precision | train | def precision(precision, id_, hwid, type_):
"""Change the precision for the sensor and persist it in the sensor's EEPROM"""
if id_ and (hwid or type_):
raise click.BadOptionUsage(
"If --id is given --hwid and --type are not allowed."
)
if id_:
try:
sensor = W... | python | {
"resource": ""
} |
q21859 | load_kernel_modules | train | def load_kernel_modules():
"""
Load kernel modules needed by the temperature sensor
if they are not already loaded.
If the base directory then does not exist an exception is raised an the kernel module loading
should be treated as failed.
:raises KernelModuleLoadError: if the kernel module coul... | python | {
"resource": ""
} |
q21860 | W1ThermSensor.get_available_sensors | train | def get_available_sensors(cls, types=None):
"""
Return all available sensors.
:param list types: the type of the sensor to look for.
If types is None it will search for all available types.
:returns: a list of sensor instances.
:rt... | python | {
"resource": ""
} |
q21861 | W1ThermSensor.raw_sensor_strings | train | def raw_sensor_strings(self):
"""
Reads the raw strings from the kernel module sysfs interface
:returns: raw strings containing all bytes from the sensor memory
:rtype: str
:raises NoSensorFoundError: if the sensor could not be found
:raises SensorNo... | python | {
"resource": ""
} |
q21862 | W1ThermSensor.raw_sensor_count | train | def raw_sensor_count(self):
"""
Returns the raw integer ADC count from the sensor
Note: Must be divided depending on the max. sensor resolution
to get floating point celsius
:returns: the raw value from the sensor ADC
:rtype: int
:raises... | python | {
"resource": ""
} |
q21863 | W1ThermSensor._get_unit_factor | train | def _get_unit_factor(cls, unit):
"""
Returns the unit factor depending on the unit constant
:param int unit: the unit of the factor requested
:returns: a function to convert the raw sensor value to the given unit
:rtype: lambda function
:raises Unsu... | python | {
"resource": ""
} |
q21864 | W1ThermSensor.get_temperature | train | def get_temperature(self, unit=DEGREES_C):
"""
Returns the temperature in the specified unit
:param int unit: the unit of the temperature requested
:returns: the temperature in the given unit
:rtype: float
:raises UnsupportedUnitError: if the unit i... | python | {
"resource": ""
} |
q21865 | W1ThermSensor.get_temperatures | train | def get_temperatures(self, units):
"""
Returns the temperatures in the specified units
:param list units: the units for the sensor temperature
:returns: the sensor temperature in the given units. The order of
the temperatures matches the order of the given units... | python | {
"resource": ""
} |
q21866 | W1ThermSensor.get_precision | train | def get_precision(self):
"""
Get the current precision from the sensor.
:returns: sensor resolution from 9-12 bits
:rtype: int
"""
config_str = self.raw_sensor_strings[1].split()[4] # Byte 5 is the config register
bit_base = int(config_str, 16) >> 5 ... | python | {
"resource": ""
} |
q21867 | W1ThermSensor.set_precision | train | def set_precision(self, precision, persist=False):
"""
Set the precision of the sensor for the next readings.
If the ``persist`` argument is set to ``False`` this value
is "only" stored in the volatile SRAM, so it is reset when
the sensor gets power-cycled.
... | python | {
"resource": ""
} |
q21868 | round_to_n | train | def round_to_n(x, n):
"""
Round to sig figs
"""
return round(x, -int(np.floor(np.log10(x))) + (n - 1)) | python | {
"resource": ""
} |
q21869 | sharey | train | def sharey(axes):
"""
Shared axes limits without shared locators, ticks, etc.
By Joe Kington
"""
linker = Linker(axes)
for ax in axes:
ax._linker = linker | python | {
"resource": ""
} |
q21870 | fix_ticks | train | def fix_ticks(ax):
"""
Center ticklabels and hide any outside axes limits.
By Joe Kington
"""
plt.setp(ax.get_yticklabels(), ha='center', x=0.5,
transform=ax._yaxis_transform)
# We'll still wind up with some tick labels beyond axes limits for reasons
# I don't fully understand... | python | {
"resource": ""
} |
q21871 | list_and_add | train | def list_and_add(a, b):
"""
Concatenate anything into a list.
Args:
a: the first thing
b: the second thing
Returns:
list. All the things in a list.
"""
if not isinstance(b, list):
b = [b]
if not isinstance(a, list):
a = [a]
return a + b | python | {
"resource": ""
} |
q21872 | lasio_get | train | def lasio_get(l,
section,
item,
attrib='value',
default=None,
remap=None,
funcs=None):
"""
Grabs, renames and transforms stuff from a lasio object.
Args:
l (lasio): a lasio instance.
section (str): The LAS s... | python | {
"resource": ""
} |
q21873 | parabolic | train | def parabolic(f, x):
"""
Interpolation. From ageobot, from somewhere else.
"""
xv = 1/2. * (f[x-1] - f[x+1]) / (f[x-1] - 2 * f[x] + f[x+1]) + x
yv = f[x] - 1/4. * (f[x-1] - f[x+1]) * (xv - x)
return (xv, yv) | python | {
"resource": ""
} |
q21874 | find_nearest | train | def find_nearest(a, value, index=False):
"""
Find the array value, or index of the array value, closest to some given
value.
Args:
a (ndarray)
value (float)
index (bool): whether to return the index instead of the array value.
Returns:
float. The array value (or ind... | python | {
"resource": ""
} |
q21875 | find_previous | train | def find_previous(a, value, index=False, return_distance=False):
"""
Find the nearest array value, or index of the array value, before some
given value. Optionally also return the fractional distance of the given
value from that previous value.
Args:
a (ndarray)
value (float)
... | python | {
"resource": ""
} |
q21876 | dd2dms | train | def dd2dms(dd):
"""
Decimal degrees to DMS.
Args:
dd (float). Decimal degrees.
Return:
tuple. Degrees, minutes, and seconds.
"""
m, s = divmod(dd * 3600, 60)
d, m = divmod(m, 60)
return int(d), int(m), s | python | {
"resource": ""
} |
q21877 | ricker | train | def ricker(f, length, dt):
"""
A Ricker wavelet.
Args:
f (float): frequency in Haz, e.g. 25 Hz.
length (float): Length in s, e.g. 0.128.
dt (float): sample interval in s, e.g. 0.001.
Returns:
tuple. time basis, amplitude values.
"""
t = np.linspace(-int(length/2... | python | {
"resource": ""
} |
q21878 | hex_is_dark | train | def hex_is_dark(hexx, percent=50):
"""
Function to decide if a hex colour is dark.
Args:
hexx (str): A hexadecimal colour, starting with '#'.
Returns:
bool: The colour's brightness is less than the given percent.
"""
r, g, b = hex_to_rgb(hexx)
luma = (0.2126 * r + 0.7152 * ... | python | {
"resource": ""
} |
q21879 | text_colour_for_hex | train | def text_colour_for_hex(hexx, percent=50, dark='#000000', light='#ffffff'):
"""
Function to decide what colour to use for a given hex colour.
Args:
hexx (str): A hexadecimal colour, starting with '#'.
Returns:
bool: The colour's brightness is less than the given percent.
"""
re... | python | {
"resource": ""
} |
q21880 | get_lines | train | def get_lines(handle, line):
"""
Get zero-indexed line from an open file-like.
"""
for i, l in enumerate(handle):
if i == line:
return l | python | {
"resource": ""
} |
q21881 | find_file | train | def find_file(pattern, path):
"""
A bit like grep. Finds a pattern, looking in path. Returns the filename.
"""
for fname in glob.iglob(path):
with open(fname) as f:
if re.search(pattern, f.read()):
return fname
return | python | {
"resource": ""
} |
q21882 | Location.from_lasio | train | def from_lasio(cls, l, remap=None, funcs=None):
"""
Make a Location object from a lasio object. Assumes we're starting
with a lasio object, l.
Args:
l (lasio).
remap (dict): Optional. A dict of 'old': 'new' LAS field names.
funcs (dict): Optional. A d... | python | {
"resource": ""
} |
q21883 | Location.add_deviation | train | def add_deviation(self, dev, td=None):
"""
Add a deviation survey to this instance, and try to compute a position
log from it.
"""
self.deviation = dev
try:
self.compute_position_log(td=td)
except:
self.position = None
return | python | {
"resource": ""
} |
q21884 | Location.md2tvd | train | def md2tvd(self, kind='linear'):
"""
Provides an transformation and interpolation function that converts
MD to TVD.
Args:
kind (str): The kind of interpolation to do, e.g. 'linear',
'cubic', 'nearest'.
Returns:
function.
"""
... | python | {
"resource": ""
} |
q21885 | Project.add_canstrat_striplogs | train | def add_canstrat_striplogs(self,
path, uwi_transform=None, name='canstrat'):
"""
This may be too specific a method... just move it to the workflow.
Requires striplog.
"""
from striplog import Striplog
uwi_transform = uwi_transform or utils... | python | {
"resource": ""
} |
q21886 | Project.__all_curve_names | train | def __all_curve_names(self, uwis=None, unique=True, count=False, nodepth=True):
"""
Utility function to get all curve names from all wells, regardless
of data type or repetition.
"""
uwis = uwis or self.uwis
c = utils.flatten_list([list(w.data.keys()) for w in self if w.u... | python | {
"resource": ""
} |
q21887 | Project.get_mnemonics | train | def get_mnemonics(self, mnemonics, uwis=None, alias=None):
"""
Looks at all the wells in turn and returns the highest thing
in the alias table.
Args:
mnemonics (list)
alias (dict)
Returns:
list. A list of lists.
"""
# Let's no... | python | {
"resource": ""
} |
q21888 | Project.count_mnemonic | train | def count_mnemonic(self, mnemonic, uwis=uwis, alias=None):
"""
Counts the wells that have a given curve, given the mnemonic and an
alias dict.
"""
all_mnemonics = self.get_mnemonics([mnemonic], uwis=uwis, alias=alias)
return len(list(filter(None, utils.flatten_list(all_mn... | python | {
"resource": ""
} |
q21889 | Project.plot_kdes | train | def plot_kdes(self, mnemonic, alias=None, uwi_regex=None, return_fig=False):
"""
Plot KDEs for all curves with the given name.
Args:
menmonic (str): the name of the curve to look for.
alias (dict): a welly alias dictionary.
uwi_regex (str): a regex pattern. O... | python | {
"resource": ""
} |
q21890 | Project.find_wells_with_curve | train | def find_wells_with_curve(self, mnemonic, alias=None):
"""
Returns a new Project with only the wells which have the named curve.
Args:
menmonic (str): the name of the curve to look for.
alias (dict): a welly alias dictionary.
Returns:
project... | python | {
"resource": ""
} |
q21891 | Project.find_wells_without_curve | train | def find_wells_without_curve(self, mnemonic, alias=None):
"""
Returns a new Project with only the wells which DO NOT have the named curve.
Args:
menmonic (str): the name of the curve to look for.
alias (dict): a welly alias dictionary.
Returns:
... | python | {
"resource": ""
} |
q21892 | Project.get_wells | train | def get_wells(self, uwis=None):
"""
Returns a new Project with only the wells named by UWI.
Args:
uwis (list): list or tuple of UWI strings.
Returns:
project.
"""
if uwis is None:
return Project(self.__list)
return Pro... | python | {
"resource": ""
} |
q21893 | Project.omit_wells | train | def omit_wells(self, uwis=None):
"""
Returns a new project where wells with specified uwis have been omitted
Args:
uwis (list): list or tuple of UWI strings.
Returns:
project
"""
if uwis is None:
raise ValueError('Must specify at le... | python | {
"resource": ""
} |
q21894 | Project.get_well | train | def get_well(self, uwi):
"""
Returns a Well object identified by UWI
Args:
uwi (string): the UWI string for the well.
Returns:
well
"""
if uwi is None:
raise ValueError('a UWI must be provided')
matching_wells = [w for... | python | {
"resource": ""
} |
q21895 | Project.merge_wells | train | def merge_wells(self, right, keys=None):
"""
Returns a new Project object containing wells from self where
curves from the wells on the right have been added. Matching between
wells in self and right is based on uwi match and ony wells in self
are considered
Args:
... | python | {
"resource": ""
} |
q21896 | Project.df | train | def df(self):
"""
Makes a pandas DataFrame containing Curve data for all the wells
in the Project. The DataFrame has a dual index of well UWI and
curve Depths. Requires `pandas`.
Args:
No arguments.
Returns:
`pandas.DataFrame`.
"""
... | python | {
"resource": ""
} |
q21897 | Curve.basis | train | def basis(self):
"""
The depth or time basis of the curve's points. Computed
on the fly from the start, stop and step.
Returns
ndarray. The array, the same length as the curve.
"""
return np.linspace(self.start, self.stop, self.shape[0], endpoint=True) | python | {
"resource": ""
} |
q21898 | Curve.describe | train | def describe(self):
"""
Return basic statistics about the curve.
"""
stats = {}
stats['samples'] = self.shape[0]
stats['nulls'] = self[np.isnan(self)].shape[0]
stats['mean'] = float(np.nanmean(self.real))
stats['min'] = float(np.nanmin(self.real))
... | python | {
"resource": ""
} |
q21899 | Curve.from_lasio_curve | train | def from_lasio_curve(cls, curve,
depth=None,
basis=None,
start=None,
stop=None,
step=0.1524,
run=-1,
null=-999.25,
servi... | python | {
"resource": ""
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.