本文整理匯總了Python中dask.array.ones方法的典型用法代碼示例。如果您正苦於以下問題:Python array.ones方法的具體用法?Python array.ones怎麽用?Python array.ones使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類dask.array
的用法示例。
在下文中一共展示了array.ones方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_transform
# 需要導入模塊: from dask import array [as 別名]
# 或者: from dask.array import ones [as 別名]
def test_transform(comm):
cosmo = cosmology.Planck15
data = numpy.ones(100, dtype=[
('Position', ('f4', 3)),
('Velocity', ('f4', 3))]
)
source = ArrayCatalog(data, BoxSize=100, Nmesh=32, comm=comm)
source['Velocity'] = source['Position'] + source['Velocity']
source['Position'] = source['Position'] + source['Velocity']
# Position triggers Velocity which triggers Position and Velocity
# which resolves to the true data.
# so total is 3.
assert_allclose(source['Position'], 3)
mesh = source.to_mesh()
示例2: test_delitem
# 需要導入模塊: from dask import array [as 別名]
# 或者: from dask.array import ones [as 別名]
def test_delitem(comm):
source = UniformCatalog(nbar=2e-4, BoxSize=512., seed=42, comm=comm)
# add a test column
test = numpy.ones(source.size)
source['test'] = test
# cannot delete hard coded column
with pytest.raises(ValueError):
del source['Position']
# cannot delete missing column
with pytest.raises(ValueError):
del source['BAD_COLUMN']
assert 'test' in source
del source['test']
assert 'test' not in source
示例3: test_simple
# 需要導入模塊: from dask import array [as 別名]
# 或者: from dask.array import ones [as 別名]
def test_simple(self):
array0 = da.ones(shape=(10, 10, 40, 40), chunks=(5, 5, 5, 5))
s0 = LazyDiffraction2D(array0)
s0_r = s0.radial_average()
assert (s0_r.data[:, :, :-1] == 1).all()
data_shape = 2, 2, 11, 11
array1 = np.zeros(data_shape)
array1[:, :, 5, 5] = 1
dask_array = da.from_array(array1, chunks=(1, 1, 1, 1))
s1 = LazyDiffraction2D(dask_array)
s1.axes_manager.signal_axes[0].offset = -5
s1.axes_manager.signal_axes[1].offset = -5
s1_r = s1.radial_average()
assert np.all(s1_r.data[:, :, 0] == 1)
assert np.all(s1_r.data[:, :, 1:] == 0)
示例4: test_add_missing_coordinates
# 需要導入模塊: from dask import array [as 別名]
# 或者: from dask.array import ones [as 別名]
def test_add_missing_coordinates(self):
"""Test coordinate updating."""
import dask.array as da
from xarray import DataArray
from pyresample.bilinear.xarr import XArrayResamplerBilinear
resampler = XArrayResamplerBilinear(self.source_def, self.target_def,
self.radius)
bands = ['R', 'G', 'B']
data = DataArray(da.ones((3, 10, 10)), dims=('bands', 'y', 'x'),
coords={'bands': bands,
'y': np.arange(10), 'x': np.arange(10)})
resampler._add_missing_coordinates(data)
# X and Y coordinates should not change
self.assertIsNone(resampler.out_coords_x)
self.assertIsNone(resampler.out_coords_y)
self.assertIsNone(resampler.out_coords['x'])
self.assertIsNone(resampler.out_coords['y'])
self.assertTrue('bands' in resampler.out_coords)
self.assertTrue(np.all(resampler.out_coords['bands'] == bands))
示例5: _mean4
# 需要導入模塊: from dask import array [as 別名]
# 或者: from dask.array import ones [as 別名]
def _mean4(data, offset=(0, 0), block_id=None):
rows, cols = data.shape
# we assume that the chunks except the first ones are aligned
if block_id[0] == 0:
row_offset = offset[0] % 2
else:
row_offset = 0
if block_id[1] == 0:
col_offset = offset[1] % 2
else:
col_offset = 0
row_after = (row_offset + rows) % 2
col_after = (col_offset + cols) % 2
pad = ((row_offset, row_after), (col_offset, col_after))
rows2 = rows + row_offset + row_after
cols2 = cols + col_offset + col_after
av_data = np.pad(data, pad, 'edge')
new_shape = (int(rows2 / 2.), 2, int(cols2 / 2.), 2)
data_mean = np.nanmean(av_data.reshape(new_shape), axis=(1, 3))
data_mean = np.repeat(np.repeat(data_mean, 2, axis=0), 2, axis=1)
data_mean = data_mean[row_offset:row_offset + rows, col_offset:col_offset + cols]
return data_mean
示例6: test_compute
# 需要導入模塊: from dask import array [as 別名]
# 或者: from dask.array import ones [as 別名]
def test_compute(self):
"""Test count bucket resampler computation."""
import dask.array as da
# 1D data
self.bucket.resampler = mock.MagicMock()
data = da.ones((5,))
self.bucket.resampler.get_count.return_value = data
res = self.bucket.compute(data)
self.bucket.resampler.get_count.assert_called_once_with()
self.assertEqual(res.shape, (1, 5))
# 2D data
self.bucket.resampler = mock.MagicMock()
data = da.ones((5, 5))
self.bucket.resampler.get_count.return_value = data
res = self.bucket.compute(data)
self.bucket.resampler.get_count.assert_called_once_with()
self.assertEqual(res.shape, (1, 5, 5))
# 3D data
self.bucket.resampler = mock.MagicMock()
data = da.ones((3, 5, 5))
self.bucket.resampler.get_count.return_value = data[0, :, :]
res = self.bucket.compute(data)
self.assertEqual(res.shape, (3, 5, 5))
示例7: test_resample
# 需要導入模塊: from dask import array [as 別名]
# 或者: from dask.array import ones [as 別名]
def test_resample(self, pyresample_bucket):
"""Test fraction bucket resamplers resample method."""
import xarray as xr
import dask.array as da
import numpy as np
self.bucket.resampler = mock.MagicMock()
self.bucket.precompute = mock.MagicMock()
self.bucket.compute = mock.MagicMock()
# Fractions return a dict
data = xr.DataArray(da.ones((1, 5, 5)), dims=('bands', 'y', 'x'))
arr = da.ones((5, 5))
self.bucket.compute.return_value = {0: arr, 1: arr, 2: arr}
res = self.bucket.resample(data)
self.assertTrue('categories' in res.coords)
self.assertTrue('categories' in res.dims)
self.assertTrue(np.all(res.coords['categories'] == np.array([0, 1, 2])))
示例8: setUp
# 需要導入模塊: from dask import array [as 別名]
# 或者: from dask.array import ones [as 別名]
def setUp(self):
"""Create test data."""
from satpy.composites import GenericCompositor
self.comp = GenericCompositor(name='test')
self.comp2 = GenericCompositor(name='test2', common_channel_mask=False)
all_valid = np.ones((1, 2, 2))
self.all_valid = xr.DataArray(all_valid, dims=['bands', 'y', 'x'])
first_invalid = np.reshape(np.array([np.nan, 1., 1., 1.]), (1, 2, 2))
self.first_invalid = xr.DataArray(first_invalid,
dims=['bands', 'y', 'x'])
second_invalid = np.reshape(np.array([1., np.nan, 1., 1.]), (1, 2, 2))
self.second_invalid = xr.DataArray(second_invalid,
dims=['bands', 'y', 'x'])
wrong_shape = np.reshape(np.array([1., 1., 1.]), (1, 3, 1))
self.wrong_shape = xr.DataArray(wrong_shape, dims=['bands', 'y', 'x'])
示例9: test_multiple_sensors
# 需要導入模塊: from dask import array [as 別名]
# 或者: from dask.array import ones [as 別名]
def test_multiple_sensors(self):
"""Test the background compositing from multiple sensor data."""
from satpy.composites import BackgroundCompositor
import numpy as np
comp = BackgroundCompositor("name")
# L mode images
attrs = {'mode': 'L', 'area': 'foo'}
foreground = xr.DataArray(np.array([[[1., 0.5],
[0., np.nan]]]),
dims=('bands', 'y', 'x'),
coords={'bands': [c for c in attrs['mode']]},
attrs=attrs.copy())
foreground.attrs['sensor'] = 'abi'
background = xr.DataArray(np.ones((1, 2, 2)), dims=('bands', 'y', 'x'),
coords={'bands': [c for c in attrs['mode']]},
attrs=attrs.copy())
background.attrs['sensor'] = 'glm'
res = comp([foreground, background])
self.assertEqual(res.attrs['area'], 'foo')
self.assertTrue(np.all(res == np.array([[1., 0.5], [0., 1.]])))
self.assertEqual(res.attrs['mode'], 'L')
self.assertEqual(res.attrs['sensor'], {'abi', 'glm'})
示例10: test_dims_setting
# 需要導入模塊: from dask import array [as 別名]
# 或者: from dask.array import ones [as 別名]
def test_dims_setting(expected_starting_dims, set_dims, expected_ending_dims):
# Read file
img = ArrayLikeReader(da.ones((2, 2, 2)))
# Check basics
assert img.dims == expected_starting_dims
# Set dims
img.dims = set_dims
# Check dims after update
assert img.dims == expected_ending_dims
示例11: test_guess_multiscale
# 需要導入模塊: from dask import array [as 別名]
# 或者: from dask.array import ones [as 別名]
def test_guess_multiscale():
data = np.random.random((10, 15))
assert not guess_multiscale(data)[0]
data = np.random.random((10, 15, 6))
assert not guess_multiscale(data)[0]
data = [np.random.random((10, 15, 6))]
assert not guess_multiscale(data)[0]
data = [np.random.random((10, 15, 6)), np.random.random((5, 7, 3))]
assert guess_multiscale(data)[0]
data = [np.random.random((10, 15, 6)), np.random.random((10, 7, 3))]
assert guess_multiscale(data)[0]
data = tuple(data)
assert guess_multiscale(data)[0]
data = tuple(
pyramid_gaussian(np.random.random((10, 15)), multichannel=False)
)
assert guess_multiscale(data)[0]
data = np.asarray(
tuple(pyramid_gaussian(np.random.random((10, 15)), multichannel=False))
)
assert guess_multiscale(data)[0]
# Check for integer overflow with big data
s = 8192
data = [da.ones((s,) * 3), da.ones((s // 2,) * 3), da.ones((s // 4,) * 3)]
assert guess_multiscale(data)[0]
示例12: test_dask_array_creates_cache
# 需要導入模塊: from dask import array [as 別名]
# 或者: from dask.array import ones [as 別名]
def test_dask_array_creates_cache():
"""Test that adding a dask array creates a dask cache and turns of fusion.
"""
# by default we have no dask_cache and task fusion is active
original = dask.config.get("optimization.fuse.active", None)
def mock_set_view_slice():
assert dask.config.get("optimization.fuse.active") is False
layer = layers.Image(da.ones((100, 100)))
layer._set_view_slice = mock_set_view_slice
layer.set_view_slice()
# adding a dask array will turn on the cache, and turn off task fusion.
assert isinstance(utils.dask_cache, dask.cache.Cache)
assert dask.config.get("optimization.fuse.active", None) == original
# if the dask version is too low to remove task fusion, emit a warning
_dask_ver = dask.__version__
dask.__version__ = '2.14.0'
with pytest.warns(UserWarning) as record:
_ = layers.Image(da.ones((100, 100)))
assert 'upgrade Dask to v2.15.0 or later' in record[0].message.args[0]
dask.__version__ = _dask_ver
# make sure we can resize the cache
assert utils.dask_cache.cache.total_bytes > 1000
utils.resize_dask_cache(1000)
assert utils.dask_cache.cache.total_bytes <= 1000
# This should only affect dask arrays, and not numpy data
def mock_set_view_slice2():
assert dask.config.get("optimization.fuse.active", None) == original
layer2 = layers.Image(np.ones((100, 100)))
layer2._set_view_slice = mock_set_view_slice2
layer2.set_view_slice()
# clean up cache
utils.dask_cache = None
示例13: test_list_of_dask_arrays_creates_cache
# 需要導入模塊: from dask import array [as 別名]
# 或者: from dask.array import ones [as 別名]
def test_list_of_dask_arrays_creates_cache():
"""Test that adding a list of dask array also creates a dask cache."""
original = dask.config.get("optimization.fuse.active", None)
_ = layers.Image([da.ones((100, 100)), da.ones((20, 20))])
assert isinstance(utils.dask_cache, dask.cache.Cache)
assert dask.config.get("optimization.fuse.active", None) == original
示例14: test_simple
# 需要導入模塊: from dask import array [as 別名]
# 或者: from dask.array import ones [as 別名]
def test_simple(self):
dask_array = da.ones((10, 10, 50, 50), chunks=(5, 5, 25, 25))
data = lt._calculate_function_on_dask_array(
dask_array, sum_frame, show_progressbar=False
)
assert data.shape == (10, 10)
assert (data == (np.ones((10, 10)) * 50 * 50)).all()
示例15: test_1d_nav
# 需要導入模塊: from dask import array [as 別名]
# 或者: from dask.array import ones [as 別名]
def test_1d_nav(self):
dask_array = da.ones((10, 50, 50), chunks=(5, 25, 25))
data = lt._calculate_function_on_dask_array(
dask_array, sum_frame, show_progressbar=False
)
assert data.shape == (10,)
assert (data == (np.ones((10,)) * 50 * 50)).all()