本文整理汇总了Python中dask.array方法的典型用法代码示例。如果您正苦于以下问题:Python dask.array方法的具体用法?Python dask.array怎么用?Python dask.array使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类dask
的用法示例。
在下文中一共展示了dask.array方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: read
# 需要导入模块: import dask [as 别名]
# 或者: from dask import array [as 别名]
def read(self, columns):
"""
Return the requested columns as dask arrays.
Parameters
----------
columns : list of str
the names of the requested columns
Returns
-------
list of :class:`dask.array.Array` :
the list of column data, in the form of dask arrays
"""
missing = set(columns) - set(self.columns)
if len(missing) > 0:
msg = "source does not contain columns: %s; " %str(missing)
msg += "try adding columns via `source[column] = data`"
raise ValueError(msg)
return [self[col] for col in columns]
示例2: persist
# 需要导入模块: import dask [as 别名]
# 或者: from dask import array [as 别名]
def persist(self, columns=None):
"""
Return a CatalogSource, where the selected columns are
computed and persist in memory.
"""
import dask.array as da
if columns is None:
columns = self.columns
r = {}
for key in columns:
r[key] = self[key]
r = da.compute(r)[0] # particularity of dask
from nbodykit.source.catalog.array import ArrayCatalog
c = ArrayCatalog(r, comm=self.comm)
c.attrs.update(self.attrs)
return c
示例3: delayed_dask_stack
# 需要导入模块: import dask [as 别名]
# 或者: from dask import array [as 别名]
def delayed_dask_stack():
"""A 4D (20, 10, 10, 10) delayed dask array, simulates disk io."""
# we will return a dict with a 'calls' variable that tracks call count
output = {'calls': 0}
# create a delayed version of function that simply generates np.arrays
# but also counts when it has been called
@dask.delayed
def get_array():
nonlocal output
output['calls'] += 1
return np.random.rand(10, 10, 10)
# then make a mock "timelapse" of 3D stacks
# see https://napari.org/tutorials/applications/dask.html for details
_list = [get_array() for fn in range(20)]
output['stack'] = da.stack(
[da.from_delayed(i, shape=(10, 10, 10), dtype=np.float) for i in _list]
)
assert output['stack'].shape == (20, 10, 10, 10)
return output
示例4: __new__
# 需要导入模块: import dask [as 别名]
# 或者: from dask import array [as 别名]
def __new__(cls, dm, **kwargs):
if isinstance(dm, da.Array):
dm = DaskMeta.from_darray(dm)
elif isinstance(dm, dict):
dm = DaskMeta(**dm)
elif isinstance(dm, DaskMeta):
pass
elif dm.__class__.__name__ in ("Op", "GraphMeta", "TmsMeta", "TemplateMeta"):
itr = [dm.dask, dm.name, dm.chunks, dm.dtype, dm.shape]
dm = DaskMeta._make(itr)
else:
raise ValueError("{} must be initialized with a DaskMeta, a dask array, or a dict with DaskMeta fields".format(cls.__name__))
self = da.Array.__new__(cls, dm.dask, dm.name, dm.chunks, dtype=dm.dtype, shape=dm.shape)
if "__geo_transform__" in kwargs:
self.__geo_transform__ = kwargs["__geo_transform__"]
if "__geo_interface__" in kwargs:
self.__geo_interface__ = kwargs["__geo_interface__"]
return self
示例5: aoi
# 需要导入模块: import dask [as 别名]
# 或者: from dask import array [as 别名]
def aoi(self, **kwargs):
""" Subsets the Image by the given bounds
Args:
bbox (list): optional. A bounding box array [minx, miny, maxx, maxy]
wkt (str): optional. A WKT geometry string
geojson (str): optional. A GeoJSON geometry dictionary
Returns:
image: an image instance of the same type
"""
g = self._parse_geoms(**kwargs)
if g is None:
return self
else:
return self[g]
示例6: to_slice
# 需要导入模块: import dask [as 别名]
# 或者: from dask import array [as 别名]
def to_slice(arr):
"""Test whether `arr` is an integer array that can be replaced by a slice
Parameters
----------
arr: numpy.array
Numpy integer array
Returns
-------
slice or None
If `arr` could be converted to an array, this is returned, otherwise
`None` is returned
See Also
--------
get_index_from_coord"""
if isinstance(arr, slice):
return arr
if len(arr) == 1:
return slice(arr[0], arr[0] + 1)
step = np.unique(arr[1:] - arr[:-1])
if len(step) == 1:
return slice(arr[0], arr[-1] + step[0], step[0])
示例7: __init__
# 需要导入模块: import dask [as 别名]
# 或者: from dask import array [as 别名]
def __init__(self, plotter=None, arr_name='arr0', auto_update=None):
"""
Parameters
----------
plotter: Plotter
Default: None. Interactive plotter that makes the plot via
formatoption keywords.
arr_name: str
Default: ``'data'``. unique string of the array
auto_update: bool
Default: None. A boolean indicating whether this list shall
automatically update the contained arrays when calling the
:meth:`update` method or not. See also the :attr:`no_auto_update`
attribute. If None, the value from the ``'lists.auto_update'``
key in the :attr:`psyplot.rcParams` dictionary is used."""
self.plotter = plotter
self.arr_name = arr_name
if auto_update is None:
auto_update = rcParams['lists.auto_update']
self.no_auto_update = not bool(auto_update)
self.replot = False
示例8: _insert_fldmean_bounds
# 需要导入模块: import dask [as 别名]
# 或者: from dask import array [as 别名]
def _insert_fldmean_bounds(self, da, keepdims=False):
xcoord = self.get_coord('x')
ycoord = self.get_coord('y')
sdims = (self.get_dim('y'), self.get_dim('x'))
xbounds = np.array([[xcoord.min(), xcoord.max()]])
ybounds = np.array([[ycoord.min(), ycoord.max()]])
xdims = (sdims[-1], 'bnds') if keepdims else ('bnds', )
ydims = (sdims[0], 'bnds') if keepdims else ('bnds', )
xattrs = xcoord.attrs.copy()
xattrs.pop('bounds', None)
yattrs = ycoord.attrs.copy()
yattrs.pop('bounds', None)
da.psy.base.coords[xcoord.name + '_bnds'] = xr.Variable(
xdims, xbounds if keepdims else xbounds[0], attrs=xattrs)
da.psy.base.coords[ycoord.name + '_bnds'] = xr.Variable(
ydims, ybounds if keepdims else ybounds[0], attrs=yattrs)
示例9: _contains_array
# 需要导入模块: import dask [as 别名]
# 或者: from dask import array [as 别名]
def _contains_array(self, val):
"""Checks whether exactly this array is in the list"""
arr = self(arr_name=val.psy.arr_name)[0]
is_not_list = any(
map(lambda a: not isinstance(a, InteractiveList),
[arr, val]))
is_list = any(map(lambda a: isinstance(a, InteractiveList),
[arr, val]))
# if one is an InteractiveList and the other not, they differ
if is_list and is_not_list:
return False
# if both are interactive lists, check the lists
if is_list:
return all(a in arr for a in val) and all(a in val for a in arr)
# else we check the shapes and values
return arr is val
示例10: next_available_name
# 需要导入模块: import dask [as 别名]
# 或者: from dask import array [as 别名]
def next_available_name(self, fmt_str='arr{0}', counter=None):
"""Create a new array out of the given format string
Parameters
----------
format_str: str
The base string to use. ``'{0}'`` will be replaced by a counter
counter: iterable
An iterable where the numbers should be drawn from. If None,
``range(100)`` is used
Returns
-------
str
A possible name that is not in the current project"""
names = self.arr_names
counter = counter or iter(range(1000))
try:
new_name = next(
filter(lambda n: n not in names,
map(fmt_str.format, counter)))
except StopIteration:
raise ValueError(
"{0} already in the list".format(fmt_str))
return new_name
示例11: append
# 需要导入模块: import dask [as 别名]
# 或者: from dask import array [as 别名]
def append(self, value, new_name=False):
"""
Append a new array to the list
Parameters
----------
value: InteractiveBase
The data object to append to this list
%(ArrayList.rename.parameters.new_name)s
Raises
------
%(ArrayList.rename.raises)s
See Also
--------
list.append, extend, rename"""
arr, renamed = self.rename(value, new_name)
if renamed is not None:
super(ArrayList, self).append(value)
示例12: remove
# 需要导入模块: import dask [as 别名]
# 或者: from dask import array [as 别名]
def remove(self, arr):
"""Removes an array from the list
Parameters
----------
arr: str or :class:`InteractiveBase`
The array name or the data object in this list to remove
Raises
------
ValueError
If no array with the specified array name is in the list"""
name = arr if isinstance(arr, six.string_types) else arr.psy.arr_name
if arr not in self:
raise ValueError(
"Array {0} not in the list".format(name))
for i, arr in enumerate(self):
if arr.psy.arr_name == name:
del self[i]
return
raise ValueError(
"No array found with name {0}".format(name))
示例13: __init__
# 需要导入模块: import dask [as 别名]
# 或者: from dask import array [as 别名]
def __init__(self, url, headers, **kwargs):
"""
Initialise local xarray, whose dask arrays contain tasks that pull data
The matadata contains a key "internal", which is a result of running
``serialize_zarr_ds`` on the xarray on the server. It is a dict
containing the metadata parts of the original dataset (i.e., the
keys with names like ".z*"). This can be opened by xarray as-is, and
will make a local xarray object. In ``._get_schema()``, the numpy
parts (coordinates) are fetched and the dask-array parts (cariables)
have their dask graphs redefined to tasks that fetch data from the
server.
"""
import xarray as xr
super(RemoteXarray, self).__init__(url, headers, **kwargs)
self._schema = None
self._ds = xr.open_zarr(self.metadata['internal'])
示例14: _filter_data
# 需要导入模块: import dask [as 别名]
# 或者: from dask import array [as 别名]
def _filter_data(self, data, is_src=True, add_dim=False):
"""Filter unused chunks from the given array."""
if add_dim:
if data.ndim not in [2, 3]:
raise NotImplementedError('Gradient search resampling only '
'supports 2D or 3D arrays.')
if data.ndim == 2:
data = data[np.newaxis, :, :]
data_out = []
for i, covers in enumerate(self.coverage_status):
if covers:
if is_src:
y_start, y_end, x_start, x_end = self.src_slices[i]
else:
y_start, y_end, x_start, x_end = self.dst_slices[i]
try:
val = data[:, y_start:y_end, x_start:x_end]
except IndexError:
val = data[y_start:y_end, x_start:x_end]
else:
val = None
data_out.append(val)
return data_out
示例15: _concatenate_chunks
# 需要导入模块: import dask [as 别名]
# 或者: from dask import array [as 别名]
def _concatenate_chunks(chunks):
"""Concatenate chunks to full output array."""
# Form the full array
col, res = [], []
prev_y = 0
for y, x in sorted(chunks):
if len(chunks[(y, x)]) > 1:
chunk = da.nanmax(da.stack(chunks[(y, x)], axis=-1), axis=-1)
else:
chunk = chunks[(y, x)][0]
if y == prev_y:
col.append(chunk)
continue
res.append(da.concatenate(col, axis=1))
col = [chunk]
prev_y = y
res.append(da.concatenate(col, axis=1))
res = da.concatenate(res, axis=2).squeeze()
return res