_id stringlengths 2 7 | title stringlengths 1 88 | partition stringclasses 3
values | text stringlengths 75 19.8k | language stringclasses 1
value | meta_information dict |
|---|---|---|---|---|---|
q23500 | Env.cache_url | train | def cache_url(self, var=DEFAULT_CACHE_ENV, default=NOTSET, backend=None):
"""Returns a config dictionary, defaulting to CACHE_URL.
:rtype: dict
"""
return self.cache_url_config(self.url(var, default=default), backend=backend) | python | {
"resource": ""
} |
q23501 | Env.email_url | train | def email_url(self, var=DEFAULT_EMAIL_ENV, default=NOTSET, backend=None):
"""Returns a config dictionary, defaulting to EMAIL_URL.
:rtype: dict
"""
return self.email_url_config(self.url(var, default=default), backend=backend) | python | {
"resource": ""
} |
q23502 | Env.search_url | train | def search_url(self, var=DEFAULT_SEARCH_ENV, default=NOTSET, engine=None):
"""Returns a config dictionary, defaulting to SEARCH_URL.
:rtype: dict
"""
return self.search_url_config(self.url(var, default=default), engine=engine) | python | {
"resource": ""
} |
q23503 | Env.parse_value | train | def parse_value(cls, value, cast):
"""Parse and cast provided value
:param value: Stringed value.
:param cast: Type to cast return value as.
:returns: Casted value
"""
if cast is None:
return value
elif cast is bool:
try:
... | python | {
"resource": ""
} |
q23504 | Env.db_url_config | train | def db_url_config(cls, url, engine=None):
"""Pulled from DJ-Database-URL, parse an arbitrary Database URL.
Support currently exists for PostgreSQL, PostGIS, MySQL, Oracle and SQLite.
SQLite connects to file based databases. The same URL format is used, omitting the hostname,
and using t... | python | {
"resource": ""
} |
q23505 | Env.cache_url_config | train | def cache_url_config(cls, url, backend=None):
"""Pulled from DJ-Cache-URL, parse an arbitrary Cache URL.
:param url:
:param backend:
:return:
"""
url = urlparse(url) if not isinstance(url, cls.URL_CLASS) else url
location = url.netloc.split(',')
if len(l... | python | {
"resource": ""
} |
q23506 | Path.path | train | def path(self, *paths, **kwargs):
"""Create new Path based on self.root and provided paths.
:param paths: List of sub paths
:param kwargs: required=False
:rtype: Path
"""
return self.__class__(self.__root__, *paths, **kwargs) | python | {
"resource": ""
} |
q23507 | warn_deprecated | train | def warn_deprecated(since, message='', name='', alternative='', pending=False,
obj_type='attribute', addendum=''):
"""Display deprecation warning in a standard way.
Parameters
----------
since : str
The release at which this API became deprecated.
message : str, optiona... | python | {
"resource": ""
} |
q23508 | generate_grid | train | def generate_grid(horiz_dim, bbox):
r"""Generate a meshgrid based on bounding box and x & y resolution.
Parameters
----------
horiz_dim: integer
Horizontal resolution
bbox: dictionary
Dictionary containing coordinates for corners of study area.
Returns
-------
grid_x: (... | python | {
"resource": ""
} |
q23509 | generate_grid_coords | train | def generate_grid_coords(gx, gy):
r"""Calculate x,y coordinates of each grid cell.
Parameters
----------
gx: numeric
x coordinates in meshgrid
gy: numeric
y coordinates in meshgrid
Returns
-------
(X, Y) ndarray
List of coordinates in meshgrid
"""
retur... | python | {
"resource": ""
} |
q23510 | get_xy_range | train | def get_xy_range(bbox):
r"""Return x and y ranges in meters based on bounding box.
bbox: dictionary
dictionary containing coordinates for corners of study area
Returns
-------
x_range: float
Range in meters in x dimension.
y_range: float
Range in meters in y dimension.
... | python | {
"resource": ""
} |
q23511 | get_xy_steps | train | def get_xy_steps(bbox, h_dim):
r"""Return meshgrid spacing based on bounding box.
bbox: dictionary
Dictionary containing coordinates for corners of study area.
h_dim: integer
Horizontal resolution in meters.
Returns
-------
x_steps, (X, ) ndarray
Number of grids in x di... | python | {
"resource": ""
} |
q23512 | get_boundary_coords | train | def get_boundary_coords(x, y, spatial_pad=0):
r"""Return bounding box based on given x and y coordinates assuming northern hemisphere.
x: numeric
x coordinates.
y: numeric
y coordinates.
spatial_pad: numeric
Number of meters to add to the x and y dimensions to reduce
edg... | python | {
"resource": ""
} |
q23513 | natural_neighbor_to_grid | train | def natural_neighbor_to_grid(xp, yp, variable, grid_x, grid_y):
r"""Generate a natural neighbor interpolation of the given points to a regular grid.
This assigns values to the given grid using the Liang and Hale [Liang2010]_.
approach.
Parameters
----------
xp: (N, ) ndarray
x-coordina... | python | {
"resource": ""
} |
q23514 | natural_neighbor | train | def natural_neighbor(xp, yp, variable, grid_x, grid_y):
"""Wrap natural_neighbor_to_grid for deprecated natural_neighbor function."""
return natural_neighbor_to_grid(xp, yp, variable, grid_x, grid_y) | python | {
"resource": ""
} |
q23515 | inverse_distance_to_grid | train | def inverse_distance_to_grid(xp, yp, variable, grid_x, grid_y, r, gamma=None, kappa=None,
min_neighbors=3, kind='cressman'):
r"""Generate an inverse distance interpolation of the given points to a regular grid.
Values are assigned to the given grid using inverse distance weighting ... | python | {
"resource": ""
} |
q23516 | inverse_distance | train | def inverse_distance(xp, yp, variable, grid_x, grid_y, r, gamma=None, kappa=None,
min_neighbors=3, kind='cressman'):
"""Wrap inverse_distance_to_grid for deprecated inverse_distance function."""
return inverse_distance_to_grid(xp, yp, variable, grid_x, grid_y, r, gamma=gamma,
... | python | {
"resource": ""
} |
q23517 | interpolate_to_isosurface | train | def interpolate_to_isosurface(level_var, interp_var, level, **kwargs):
r"""Linear interpolation of a variable to a given vertical level from given values.
This function assumes that highest vertical level (lowest pressure) is zeroth index.
A classic use of this function would be to compute the potential te... | python | {
"resource": ""
} |
q23518 | interpolate | train | def interpolate(x, y, z, interp_type='linear', hres=50000,
minimum_neighbors=3, gamma=0.25, kappa_star=5.052,
search_radius=None, rbf_func='linear', rbf_smooth=0,
boundary_coords=None):
"""Wrap interpolate_to_grid for deprecated interpolate function."""
return int... | python | {
"resource": ""
} |
q23519 | interpolate_nans_1d | train | def interpolate_nans_1d(x, y, kind='linear'):
"""Interpolate NaN values in y.
Interpolate NaN values in the y dimension. Works with unsorted x values.
Parameters
----------
x : array-like
1-dimensional array of numeric x-values
y : array-like
1-dimensional array of numeric y-va... | python | {
"resource": ""
} |
q23520 | interpolate_1d | train | def interpolate_1d(x, xp, *args, **kwargs):
r"""Interpolates data with any shape over a specified axis.
Interpolation over a specified axis for arrays of any shape.
Parameters
----------
x : array-like
1-D array of desired interpolated values.
xp : array-like
The x-coordinates... | python | {
"resource": ""
} |
q23521 | log_interpolate_1d | train | def log_interpolate_1d(x, xp, *args, **kwargs):
r"""Interpolates data with logarithmic x-scale over a specified axis.
Interpolation on a logarithmic x-scale for interpolation values in pressure coordintates.
Parameters
----------
x : array-like
1-D array of desired interpolated values.
... | python | {
"resource": ""
} |
q23522 | distances_from_cross_section | train | def distances_from_cross_section(cross):
"""Calculate the distances in the x and y directions along a cross-section.
Parameters
----------
cross : `xarray.DataArray`
The input DataArray of a cross-section from which to obtain geometeric distances in
the x and y directions.
Returns
... | python | {
"resource": ""
} |
q23523 | latitude_from_cross_section | train | def latitude_from_cross_section(cross):
"""Calculate the latitude of points in a cross-section.
Parameters
----------
cross : `xarray.DataArray`
The input DataArray of a cross-section from which to obtain latitudes.
Returns
-------
latitude : `xarray.DataArray`
Latitude of ... | python | {
"resource": ""
} |
q23524 | unit_vectors_from_cross_section | train | def unit_vectors_from_cross_section(cross, index='index'):
r"""Calculate the unit tanget and unit normal vectors from a cross-section.
Given a path described parametrically by :math:`\vec{l}(i) = (x(i), y(i))`, we can find
the unit tangent vector by the formula
.. math:: \vec{T}(i) =
\frac{1}{... | python | {
"resource": ""
} |
q23525 | cross_section_components | train | def cross_section_components(data_x, data_y, index='index'):
r"""Obtain the tangential and normal components of a cross-section of a vector field.
Parameters
----------
data_x : `xarray.DataArray`
The input DataArray of the x-component (in terms of data projection) of the vector
field.
... | python | {
"resource": ""
} |
q23526 | normal_component | train | def normal_component(data_x, data_y, index='index'):
r"""Obtain the normal component of a cross-section of a vector field.
Parameters
----------
data_x : `xarray.DataArray`
The input DataArray of the x-component (in terms of data projection) of the vector
field.
data_y : `xarray.Dat... | python | {
"resource": ""
} |
q23527 | tangential_component | train | def tangential_component(data_x, data_y, index='index'):
r"""Obtain the tangential component of a cross-section of a vector field.
Parameters
----------
data_x : `xarray.DataArray`
The input DataArray of the x-component (in terms of data projection) of the vector
field.
data_y : `xa... | python | {
"resource": ""
} |
q23528 | read_colortable | train | def read_colortable(fobj):
r"""Read colortable information from a file.
Reads a colortable, which consists of one color per line of the file, where
a color can be one of: a tuple of 3 floats, a string with a HTML color name,
or a string with a HTML hex color.
Parameters
----------
fobj : a... | python | {
"resource": ""
} |
q23529 | convert_gempak_table | train | def convert_gempak_table(infile, outfile):
r"""Convert a GEMPAK color table to one MetPy can read.
Reads lines from a GEMPAK-style color table file, and writes them to another file in
a format that MetPy can parse.
Parameters
----------
infile : file-like object
The file-like object to... | python | {
"resource": ""
} |
q23530 | ColortableRegistry.scan_resource | train | def scan_resource(self, pkg, path):
r"""Scan a resource directory for colortable files and add them to the registry.
Parameters
----------
pkg : str
The package containing the resource directory
path : str
The path to the directory with the color tables
... | python | {
"resource": ""
} |
q23531 | ColortableRegistry.scan_dir | train | def scan_dir(self, path):
r"""Scan a directory on disk for color table files and add them to the registry.
Parameters
----------
path : str
The path to the directory with the color tables
"""
for fname in glob.glob(os.path.join(path, '*' + TABLE_EXT)):
... | python | {
"resource": ""
} |
q23532 | ColortableRegistry.add_colortable | train | def add_colortable(self, fobj, name):
r"""Add a color table from a file to the registry.
Parameters
----------
fobj : file-like object
The file to read the color table from
name : str
The name under which the color table will be stored
"""
... | python | {
"resource": ""
} |
q23533 | cressman_point | train | def cressman_point(sq_dist, values, radius):
r"""Generate a Cressman interpolation value for a point.
The calculated value is based on the given distances and search radius.
Parameters
----------
sq_dist: (N, ) ndarray
Squared distance between observations and grid point
values: (N, ) ... | python | {
"resource": ""
} |
q23534 | barnes_point | train | def barnes_point(sq_dist, values, kappa, gamma=None):
r"""Generate a single pass barnes interpolation value for a point.
The calculated value is based on the given distances, kappa and gamma values.
Parameters
----------
sq_dist: (N, ) ndarray
Squared distance between observations and grid... | python | {
"resource": ""
} |
q23535 | natural_neighbor_point | train | def natural_neighbor_point(xp, yp, variable, grid_loc, tri, neighbors, triangle_info):
r"""Generate a natural neighbor interpolation of the observations to the given point.
This uses the Liang and Hale approach [Liang2010]_. The interpolation will fail if
the grid point has no natural neighbors.
Param... | python | {
"resource": ""
} |
q23536 | natural_neighbor_to_points | train | def natural_neighbor_to_points(points, values, xi):
r"""Generate a natural neighbor interpolation to the given points.
This assigns values to the given interpolation points using the Liang and Hale
[Liang2010]_. approach.
Parameters
----------
points: array_like, shape (n, 2)
Coordinat... | python | {
"resource": ""
} |
q23537 | inverse_distance_to_points | train | def inverse_distance_to_points(points, values, xi, r, gamma=None, kappa=None, min_neighbors=3,
kind='cressman'):
r"""Generate an inverse distance weighting interpolation to the given points.
Values are assigned to the given interpolation points based on either [Cressman1959]_ or
... | python | {
"resource": ""
} |
q23538 | interpolate_to_points | train | def interpolate_to_points(points, values, xi, interp_type='linear', minimum_neighbors=3,
gamma=0.25, kappa_star=5.052, search_radius=None, rbf_func='linear',
rbf_smooth=0):
r"""Interpolate unstructured point data to the given points.
This function interpolate... | python | {
"resource": ""
} |
q23539 | _make_datetime | train | def _make_datetime(s):
r"""Convert 7 bytes from a GINI file to a `datetime` instance."""
s = bytearray(s) # For Python 2
year, month, day, hour, minute, second, cs = s
if year < 70:
year += 100
return datetime(1900 + year, month, day, hour, minute, second, 10000 * cs) | python | {
"resource": ""
} |
q23540 | _scaled_int | train | def _scaled_int(s):
r"""Convert a 3 byte string to a signed integer value."""
s = bytearray(s) # For Python 2
# Get leftmost bit (sign) as 1 (if 0) or -1 (if 1)
sign = 1 - ((s[0] & 0x80) >> 6)
# Combine remaining bits
int_val = (((s[0] & 0x7f) << 16) | (s[1] << 8) | s[2])
log.debug('Sourc... | python | {
"resource": ""
} |
q23541 | _name_lookup | train | def _name_lookup(names):
r"""Create an io helper to convert an integer to a named value."""
mapper = dict(zip(range(len(names)), names))
def lookup(val):
return mapper.get(val, 'Unknown')
return lookup | python | {
"resource": ""
} |
q23542 | cf_to_proj | train | def cf_to_proj(var):
r"""Convert a Variable with projection information to a Proj.4 Projection instance.
The attributes of this Variable must conform to the Climate and Forecasting (CF)
netCDF conventions.
Parameters
----------
var : Variable
The projection variable with appropriate at... | python | {
"resource": ""
} |
q23543 | get_perturbation | train | def get_perturbation(ts, axis=-1):
r"""Compute the perturbation from the mean of a time series.
Parameters
----------
ts : array_like
The time series from which you wish to find the perturbation
time series (perturbation from the mean).
Returns
-------
array_like
... | python | {
"resource": ""
} |
q23544 | tke | train | def tke(u, v, w, perturbation=False, axis=-1):
r"""Compute turbulence kinetic energy.
Compute the turbulence kinetic energy (e) from the time series of the
velocity components.
Parameters
----------
u : array_like
The wind component along the x-axis
v : array_like
The wind ... | python | {
"resource": ""
} |
q23545 | kinematic_flux | train | def kinematic_flux(vel, b, perturbation=False, axis=-1):
r"""Compute the kinematic flux from two time series.
Compute the kinematic flux from the time series of two variables `vel`
and b. Note that to be a kinematic flux, at least one variable must be
a component of velocity.
Parameters
------... | python | {
"resource": ""
} |
q23546 | friction_velocity | train | def friction_velocity(u, w, v=None, perturbation=False, axis=-1):
r"""Compute the friction velocity from the time series of velocity components.
Compute the friction velocity from the time series of the x, z,
and optionally y, velocity components.
Parameters
----------
u : array_like
T... | python | {
"resource": ""
} |
q23547 | open_as_needed | train | def open_as_needed(filename):
"""Return a file-object given either a filename or an object.
Handles opening with the right class based on the file extension.
"""
if hasattr(filename, 'read'):
return filename
if filename.endswith('.bz2'):
return bz2.BZ2File(filename, 'rb')
elif... | python | {
"resource": ""
} |
q23548 | zlib_decompress_all_frames | train | def zlib_decompress_all_frames(data):
"""Decompress all frames of zlib-compressed bytes.
Repeatedly tries to decompress `data` until all data are decompressed, or decompression
fails. This will skip over bytes that are not compressed with zlib.
Parameters
----------
data : bytearray or bytes
... | python | {
"resource": ""
} |
q23549 | hexdump | train | def hexdump(buf, num_bytes, offset=0, width=32):
"""Perform a hexudmp of the buffer.
Returns the hexdump as a canonically-formatted string.
"""
ind = offset
end = offset + num_bytes
lines = []
while ind < end:
chunk = buf[ind:ind + width]
actual_width = len(chunk)
he... | python | {
"resource": ""
} |
q23550 | UnitLinker.units | train | def units(self, val):
"""Override the units on the underlying variable."""
if isinstance(val, units.Unit):
self._unit = val
else:
self._unit = units(val) | python | {
"resource": ""
} |
q23551 | NamedStruct.unpack_from | train | def unpack_from(self, buff, offset=0):
"""Read bytes from a buffer and return as a namedtuple."""
return self._create(super(NamedStruct, self).unpack_from(buff, offset)) | python | {
"resource": ""
} |
q23552 | DictStruct.unpack_from | train | def unpack_from(self, buff, offset=0):
"""Unpack the next bytes from a file object."""
return self._create(super(DictStruct, self).unpack_from(buff, offset)) | python | {
"resource": ""
} |
q23553 | IOBuffer.set_mark | train | def set_mark(self):
"""Mark the current location and return its id so that the buffer can return later."""
self._bookmarks.append(self._offset)
return len(self._bookmarks) - 1 | python | {
"resource": ""
} |
q23554 | IOBuffer.jump_to | train | def jump_to(self, mark, offset=0):
"""Jump to a previously set mark."""
self._offset = self._bookmarks[mark] + offset | python | {
"resource": ""
} |
q23555 | IOBuffer.splice | train | def splice(self, mark, newdata):
"""Replace the data after the marked location with the specified data."""
self.jump_to(mark)
self._data = self._data[:self._offset] + bytearray(newdata) | python | {
"resource": ""
} |
q23556 | IOBuffer.read_struct | train | def read_struct(self, struct_class):
"""Parse and return a structure from the current buffer offset."""
struct = struct_class.unpack_from(bytearray_to_buff(self._data), self._offset)
self.skip(struct_class.size)
return struct | python | {
"resource": ""
} |
q23557 | IOBuffer.read_func | train | def read_func(self, func, num_bytes=None):
"""Parse data from the current buffer offset using a function."""
# only advance if func succeeds
res = func(self.get_next(num_bytes))
self.skip(num_bytes)
return res | python | {
"resource": ""
} |
q23558 | IOBuffer.read_binary | train | def read_binary(self, num, item_type='B'):
"""Parse the current buffer offset as the specified code."""
if 'B' in item_type:
return self.read(num)
if item_type[0] in ('@', '=', '<', '>', '!'):
order = item_type[0]
item_type = item_type[1:]
else:
... | python | {
"resource": ""
} |
q23559 | IOBuffer.read | train | def read(self, num_bytes=None):
"""Read and return the specified bytes from the buffer."""
res = self.get_next(num_bytes)
self.skip(len(res))
return res | python | {
"resource": ""
} |
q23560 | IOBuffer.get_next | train | def get_next(self, num_bytes=None):
"""Get the next bytes in the buffer without modifying the offset."""
if num_bytes is None:
return self._data[self._offset:]
else:
return self._data[self._offset:self._offset + num_bytes] | python | {
"resource": ""
} |
q23561 | IOBuffer.skip | train | def skip(self, num_bytes):
"""Jump the ahead the specified bytes in the buffer."""
if num_bytes is None:
self._offset = len(self._data)
else:
self._offset += num_bytes | python | {
"resource": ""
} |
q23562 | draw_polygon_with_info | train | def draw_polygon_with_info(ax, polygon, off_x=0, off_y=0):
"""Draw one of the natural neighbor polygons with some information."""
pts = np.array(polygon)[ConvexHull(polygon).vertices]
for i, pt in enumerate(pts):
ax.plot([pt[0], pts[(i + 1) % len(pts)][0]],
[pt[1], pts[(i + 1) % len(... | python | {
"resource": ""
} |
q23563 | _check_and_flip | train | def _check_and_flip(arr):
"""Transpose array or list of arrays if they are 2D."""
if hasattr(arr, 'ndim'):
if arr.ndim >= 2:
return arr.T
else:
return arr
elif not is_string_like(arr) and iterable(arr):
return tuple(_check_and_flip(a) for a in arr)
else:
... | python | {
"resource": ""
} |
q23564 | ensure_yx_order | train | def ensure_yx_order(func):
"""Wrap a function to ensure all array arguments are y, x ordered, based on kwarg."""
@functools.wraps(func)
def wrapper(*args, **kwargs):
# Check what order we're given
dim_order = kwargs.pop('dim_order', None)
x_first = _is_x_first_dim(dim_order)
... | python | {
"resource": ""
} |
q23565 | vorticity | train | def vorticity(u, v, dx, dy):
r"""Calculate the vertical vorticity of the horizontal wind.
Parameters
----------
u : (M, N) ndarray
x component of the wind
v : (M, N) ndarray
y component of the wind
dx : float or ndarray
The grid spacing(s) in the x-direction. If an array... | python | {
"resource": ""
} |
q23566 | divergence | train | def divergence(u, v, dx, dy):
r"""Calculate the horizontal divergence of the horizontal wind.
Parameters
----------
u : (M, N) ndarray
x component of the wind
v : (M, N) ndarray
y component of the wind
dx : float or ndarray
The grid spacing(s) in the x-direction. If an a... | python | {
"resource": ""
} |
q23567 | total_deformation | train | def total_deformation(u, v, dx, dy):
r"""Calculate the horizontal total deformation of the horizontal wind.
Parameters
----------
u : (M, N) ndarray
x component of the wind
v : (M, N) ndarray
y component of the wind
dx : float or ndarray
The grid spacing(s) in the x-dire... | python | {
"resource": ""
} |
q23568 | advection | train | def advection(scalar, wind, deltas):
r"""Calculate the advection of a scalar field by the wind.
The order of the dimensions of the arrays must match the order in which
the wind components are given. For example, if the winds are given [u, v],
then the scalar and wind arrays must be indexed as x,y (whi... | python | {
"resource": ""
} |
q23569 | frontogenesis | train | def frontogenesis(thta, u, v, dx, dy, dim_order='yx'):
r"""Calculate the 2D kinematic frontogenesis of a temperature field.
The implementation is a form of the Petterssen Frontogenesis and uses the formula
outlined in [Bluestein1993]_ pg.248-253.
.. math:: F=\frac{1}{2}\left|\nabla \theta\right|[D cos... | python | {
"resource": ""
} |
q23570 | geostrophic_wind | train | def geostrophic_wind(heights, f, dx, dy):
r"""Calculate the geostrophic wind given from the heights or geopotential.
Parameters
----------
heights : (M, N) ndarray
The height field, with either leading dimensions of (x, y) or trailing dimensions
of (y, x), depending on the value of ``di... | python | {
"resource": ""
} |
q23571 | ageostrophic_wind | train | def ageostrophic_wind(heights, f, dx, dy, u, v, dim_order='yx'):
r"""Calculate the ageostrophic wind given from the heights or geopotential.
Parameters
----------
heights : (M, N) ndarray
The height field.
f : array_like
The coriolis parameter. This can be a scalar to be applied
... | python | {
"resource": ""
} |
q23572 | storm_relative_helicity | train | def storm_relative_helicity(u, v, heights, depth, bottom=0 * units.m,
storm_u=0 * units('m/s'), storm_v=0 * units('m/s')):
# Partially adapted from similar SharpPy code
r"""Calculate storm relative helicity.
Calculates storm relatively helicity following [Markowski2010] 230-231.... | python | {
"resource": ""
} |
q23573 | absolute_vorticity | train | def absolute_vorticity(u, v, dx, dy, lats, dim_order='yx'):
"""Calculate the absolute vorticity of the horizontal wind.
Parameters
----------
u : (M, N) ndarray
x component of the wind
v : (M, N) ndarray
y component of the wind
dx : float or ndarray
The grid spacing(s) i... | python | {
"resource": ""
} |
q23574 | potential_vorticity_baroclinic | train | def potential_vorticity_baroclinic(potential_temperature, pressure, u, v, dx, dy, lats):
r"""Calculate the baroclinic potential vorticity.
.. math:: PV = -g \left(\frac{\partial u}{\partial p}\frac{\partial \theta}{\partial y}
- \frac{\partial v}{\partial p}\frac{\partial \theta}{\partial x}
... | python | {
"resource": ""
} |
q23575 | inertial_advective_wind | train | def inertial_advective_wind(u, v, u_geostrophic, v_geostrophic, dx, dy, lats):
r"""Calculate the inertial advective wind.
.. math:: \frac{\hat k}{f} \times (\vec V \cdot \nabla)\hat V_g
.. math:: \frac{\hat k}{f} \times \left[ \left( u \frac{\partial u_g}{\partial x} + v
\frac{\partial u_g}{... | python | {
"resource": ""
} |
q23576 | q_vector | train | def q_vector(u, v, temperature, pressure, dx, dy, static_stability=1):
r"""Calculate Q-vector at a given pressure level using the u, v winds and temperature.
.. math:: \vec{Q} = (Q_1, Q_2)
= - \frac{R}{\sigma p}\left(
\frac{\partial \vec{v}_g}{\partial x} \... | python | {
"resource": ""
} |
q23577 | basic_map | train | def basic_map(proj):
"""Make our basic default map for plotting"""
fig = plt.figure(figsize=(15, 10))
add_metpy_logo(fig, 0, 80, size='large')
view = fig.add_axes([0, 0, 1, 1], projection=proj)
view.set_extent([-120, -70, 20, 50])
view.add_feature(cfeature.STATES.with_scale('50m'))
view.add_... | python | {
"resource": ""
} |
q23578 | get_points_within_r | train | def get_points_within_r(center_points, target_points, r):
r"""Get all target_points within a specified radius of a center point.
All data must be in same coordinate system, or you will get undetermined results.
Parameters
----------
center_points: (X, Y) ndarray
location from which to grab... | python | {
"resource": ""
} |
q23579 | get_point_count_within_r | train | def get_point_count_within_r(center_points, target_points, r):
r"""Get count of target points within a specified radius from center points.
All data must be in same coordinate system, or you will get undetermined results.
Parameters
----------
center_points: (X, Y) ndarray
locations from w... | python | {
"resource": ""
} |
q23580 | triangle_area | train | def triangle_area(pt1, pt2, pt3):
r"""Return the area of a triangle.
Parameters
----------
pt1: (X,Y) ndarray
Starting vertex of a triangle
pt2: (X,Y) ndarray
Second vertex of a triangle
pt3: (X,Y) ndarray
Ending vertex of a triangle
Returns
-------
area: fl... | python | {
"resource": ""
} |
q23581 | dist_2 | train | def dist_2(x0, y0, x1, y1):
r"""Return the squared distance between two points.
This is faster than calculating distance but should
only be used with comparable ratios.
Parameters
----------
x0: float
Starting x coordinate
y0: float
Starting y coordinate
x1: float
... | python | {
"resource": ""
} |
q23582 | distance | train | def distance(p0, p1):
r"""Return the distance between two points.
Parameters
----------
p0: (X,Y) ndarray
Starting coordinate
p1: (X,Y) ndarray
Ending coordinate
Returns
-------
d: float
distance
See Also
--------
dist_2
"""
return math.sqr... | python | {
"resource": ""
} |
q23583 | circumcircle_radius_2 | train | def circumcircle_radius_2(pt0, pt1, pt2):
r"""Calculate and return the squared radius of a given triangle's circumcircle.
This is faster than calculating radius but should only be used with comparable ratios.
Parameters
----------
pt0: (x, y)
Starting vertex of triangle
pt1: (x, y)
... | python | {
"resource": ""
} |
q23584 | circumcenter | train | def circumcenter(pt0, pt1, pt2):
r"""Calculate and return the circumcenter of a circumcircle generated by a given triangle.
All three points must be unique or a division by zero error will be raised.
Parameters
----------
pt0: (x, y)
Starting vertex of triangle
pt1: (x, y)
Seco... | python | {
"resource": ""
} |
q23585 | find_natural_neighbors | train | def find_natural_neighbors(tri, grid_points):
r"""Return the natural neighbor triangles for each given grid cell.
These are determined by the properties of the given delaunay triangulation.
A triangle is a natural neighbor of a grid cell if that triangles circumcenter
is within the circumradius of the ... | python | {
"resource": ""
} |
q23586 | find_nn_triangles_point | train | def find_nn_triangles_point(tri, cur_tri, point):
r"""Return the natural neighbors of a triangle containing a point.
This is based on the provided Delaunay Triangulation.
Parameters
----------
tri: Object
A Delaunay Triangulation
cur_tri: int
Simplex code for Delaunay Triangula... | python | {
"resource": ""
} |
q23587 | find_local_boundary | train | def find_local_boundary(tri, triangles):
r"""Find and return the outside edges of a collection of natural neighbor triangles.
There is no guarantee that this boundary is convex, so ConvexHull is not
sufficient in some situations.
Parameters
----------
tri: Object
A Delaunay Triangulati... | python | {
"resource": ""
} |
q23588 | area | train | def area(poly):
r"""Find the area of a given polygon using the shoelace algorithm.
Parameters
----------
poly: (2, N) ndarray
2-dimensional coordinates representing an ordered
traversal around the edge a polygon.
Returns
-------
area: float
"""
a = 0.0
n = len(... | python | {
"resource": ""
} |
q23589 | order_edges | train | def order_edges(edges):
r"""Return an ordered traversal of the edges of a two-dimensional polygon.
Parameters
----------
edges: (2, N) ndarray
List of unordered line segments, where each
line segment is represented by two unique
vertex codes.
Returns
-------
ordered... | python | {
"resource": ""
} |
q23590 | precipitable_water | train | def precipitable_water(dewpt, pressure, bottom=None, top=None):
r"""Calculate precipitable water through the depth of a sounding.
Formula used is:
.. math:: -\frac{1}{\rho_l g} \int\limits_{p_\text{bottom}}^{p_\text{top}} r dp
from [Salby1996]_, p. 28.
Parameters
----------
dewpt : `pin... | python | {
"resource": ""
} |
q23591 | mean_pressure_weighted | train | def mean_pressure_weighted(pressure, *args, **kwargs):
r"""Calculate pressure-weighted mean of an arbitrary variable through a layer.
Layer top and bottom specified in height or pressure.
Parameters
----------
pressure : `pint.Quantity`
Atmospheric pressure profile
*args : `pint.Quanti... | python | {
"resource": ""
} |
q23592 | bunkers_storm_motion | train | def bunkers_storm_motion(pressure, u, v, heights):
r"""Calculate the Bunkers right-mover and left-mover storm motions and sfc-6km mean flow.
Uses the storm motion calculation from [Bunkers2000]_.
Parameters
----------
pressure : array-like
Pressure from sounding
u : array-like
... | python | {
"resource": ""
} |
q23593 | bulk_shear | train | def bulk_shear(pressure, u, v, heights=None, bottom=None, depth=None):
r"""Calculate bulk shear through a layer.
Layer top and bottom specified in meters or pressure.
Parameters
----------
pressure : `pint.Quantity`
Atmospheric pressure profile
u : `pint.Quantity`
U-component o... | python | {
"resource": ""
} |
q23594 | supercell_composite | train | def supercell_composite(mucape, effective_storm_helicity, effective_shear):
r"""Calculate the supercell composite parameter.
The supercell composite parameter is designed to identify
environments favorable for the development of supercells,
and is calculated using the formula developed by
[Thompson... | python | {
"resource": ""
} |
q23595 | critical_angle | train | def critical_angle(pressure, u, v, heights, stormu, stormv):
r"""Calculate the critical angle.
The critical angle is the angle between the 10m storm-relative inflow vector
and the 10m-500m shear vector. A critical angle near 90 degrees indicates
that a storm in this environment on the indicated storm m... | python | {
"resource": ""
} |
q23596 | broadcast_indices | train | def broadcast_indices(x, minv, ndim, axis):
"""Calculate index values to properly broadcast index array within data array.
See usage in interp.
"""
ret = []
for dim in range(ndim):
if dim == axis:
ret.append(minv)
else:
broadcast_slice = [np.newaxis] * ndim
... | python | {
"resource": ""
} |
q23597 | Registry.register | train | def register(self, name):
"""Register a callable with the registry under a particular name.
Parameters
----------
name : str
The name under which to register a function
Returns
-------
dec : callable
A decorator that takes a function and ... | python | {
"resource": ""
} |
q23598 | wind_speed | train | def wind_speed(u, v):
r"""Compute the wind speed from u and v-components.
Parameters
----------
u : array_like
Wind component in the X (East-West) direction
v : array_like
Wind component in the Y (North-South) direction
Returns
-------
wind speed: array_like
The... | python | {
"resource": ""
} |
q23599 | wind_direction | train | def wind_direction(u, v):
r"""Compute the wind direction from u and v-components.
Parameters
----------
u : array_like
Wind component in the X (East-West) direction
v : array_like
Wind component in the Y (North-South) direction
Returns
-------
direction: `pint.Quantity`... | python | {
"resource": ""
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.