本文整理汇总了Python中xray.DataArray类的典型用法代码示例。如果您正苦于以下问题:Python DataArray类的具体用法?Python DataArray怎么用?Python DataArray使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了DataArray类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: TestPlot
class TestPlot(PlotTestCase):
def setUp(self):
self.darray = DataArray(np.random.randn(2, 3, 4))
def test1d(self):
self.darray[:, 0, 0].plot()
def test_2d_before_squeeze(self):
a = DataArray(np.arange(5).reshape(1, 5))
a.plot()
def test2d_uniform_calls_imshow(self):
self.assertTrue(self.imshow_called(self.darray[:, :, 0].plot))
def test2d_nonuniform_calls_contourf(self):
a = self.darray[:, :, 0]
a.coords['dim_1'] = [2, 1, 89]
self.assertTrue(self.contourf_called(a.plot))
def test3d(self):
self.darray.plot()
def test_can_pass_in_axis(self):
self.pass_in_axis(self.darray.plot)
def test__infer_interval_breaks(self):
self.assertArrayEqual([-0.5, 0.5, 1.5], _infer_interval_breaks([0, 1]))
self.assertArrayEqual([-0.5, 0.5, 5.0, 9.5, 10.5],
_infer_interval_breaks([0, 1, 9, 10]))
self.assertArrayEqual(pd.date_range('20000101', periods=4) - np.timedelta64(12, 'h'),
_infer_interval_breaks(pd.date_range('20000101', periods=3)))
开发者ID:rabernat,项目名称:xray,代码行数:32,代码来源:test_plot.py
示例2: test_groupby_count
def test_groupby_count(self):
array = DataArray([0, 0, np.nan, np.nan, 0, 0],
coords={'cat': ('x', ['a', 'b', 'b', 'c', 'c', 'c'])},
dims='x')
actual = array.groupby('cat').count()
expected = DataArray([1, 1, 2], coords=[('cat', ['a', 'b', 'c'])])
self.assertDataArrayIdentical(actual, expected)
开发者ID:akleeman,项目名称:xray,代码行数:7,代码来源:test_dataarray.py
示例3: test_to_and_from_cdms2
def test_to_and_from_cdms2(self):
try:
import cdms2
except ImportError:
raise unittest.SkipTest('cdms2 not installed')
original = DataArray(np.arange(6).reshape(2, 3),
[('distance', [-2, 2], {'units': 'meters'}),
('time', pd.date_range('2000-01-01', periods=3))],
name='foo', attrs={'baz': 123})
expected_coords = [Coordinate('distance', [-2, 2]),
Coordinate('time', [0, 1, 2])]
actual = original.to_cdms2()
self.assertArrayEqual(actual, original)
self.assertEqual(actual.id, original.name)
self.assertItemsEqual(actual.getAxisIds(), original.dims)
for axis, coord in zip(actual.getAxisList(), expected_coords):
self.assertEqual(axis.id, coord.name)
self.assertArrayEqual(axis, coord.values)
self.assertEqual(actual.baz, original.attrs['baz'])
component_times = actual.getAxis(1).asComponentTime()
self.assertEqual(len(component_times), 3)
self.assertEqual(str(component_times[0]), '2000-1-1 0:0:0.0')
roundtripped = DataArray.from_cdms2(actual)
self.assertDataArrayIdentical(original, roundtripped)
开发者ID:akleeman,项目名称:xray,代码行数:27,代码来源:test_dataarray.py
示例4: test_subplot_kws
def test_subplot_kws(self):
a = easy_array((10, 15, 4))
d = DataArray(a, dims=['y', 'x', 'z'])
d.coords['z'] = list('abcd')
g = d.plot(x='x', y='y', col='z', col_wrap=2, cmap='cool',
subplot_kws=dict(axisbg='r'))
for ax in g.axes.flat:
self.assertEqual(ax.get_axis_bgcolor(), 'r')
开发者ID:scottza,项目名称:xray,代码行数:8,代码来源:test_plot.py
示例5: test_to_dataframe
def test_to_dataframe(self):
# regression test for #260
arr = DataArray(np.random.randn(3, 4),
[('B', [1, 2, 3]), ('A', list('cdef'))])
expected = arr.to_series()
actual = arr.to_dataframe()[None]
self.assertArrayEqual(expected.values, actual.values)
self.assertArrayEqual(expected.index.values, actual.index.values)
开发者ID:WeatherGod,项目名称:xray,代码行数:8,代码来源:test_dataarray.py
示例6: test_math_automatic_alignment
def test_math_automatic_alignment(self):
a = DataArray(range(5), [('x', range(5))])
b = DataArray(range(5), [('x', range(1, 6))])
expected = DataArray(np.ones(4), [('x', [1, 2, 3, 4])])
self.assertDataArrayIdentical(a - b, expected)
with self.assertRaisesRegexp(ValueError, 'no overlapping labels'):
a.isel(x=slice(2)) + a.isel(x=slice(2, None))
开发者ID:akleeman,项目名称:xray,代码行数:8,代码来源:test_dataarray.py
示例7: test_is_null
def test_is_null(self):
x = np.random.RandomState(42).randn(5, 6)
x[x < 0] = np.nan
original = DataArray(x, [-np.arange(5), np.arange(6)], ['x', 'y'])
expected = DataArray(pd.isnull(x), [-np.arange(5), np.arange(6)],
['x', 'y'])
self.assertDataArrayIdentical(expected, original.isnull())
self.assertDataArrayIdentical(~expected, original.notnull())
开发者ID:akleeman,项目名称:xray,代码行数:8,代码来源:test_dataarray.py
示例8: test_resample_skipna
def test_resample_skipna(self):
times = pd.date_range('2000-01-01', freq='6H', periods=10)
array = DataArray(np.ones(10), [('time', times)])
array[1] = np.nan
actual = array.resample('1D', dim='time', skipna=False)
expected = DataArray([np.nan, 1, 1], [('time', times[::4])])
self.assertDataArrayIdentical(expected, actual)
开发者ID:akleeman,项目名称:xray,代码行数:8,代码来源:test_dataarray.py
示例9: test_resample_upsampling
def test_resample_upsampling(self):
times = pd.date_range('2000-01-01', freq='1D', periods=5)
array = DataArray(np.arange(5), [('time', times)])
expected_time = pd.date_range('2000-01-01', freq='12H', periods=9)
expected = array.reindex(time=expected_time)
for how in ['mean', 'median', 'sum', 'first', 'last', np.mean]:
actual = array.resample('12H', 'time', how=how)
self.assertDataArrayIdentical(expected, actual)
开发者ID:akleeman,项目名称:xray,代码行数:9,代码来源:test_dataarray.py
示例10: setUp
def setUp(self):
a = easy_array((10, 15, 3, 2))
darray = DataArray(a, dims=['y', 'x', 'col', 'row'])
darray.coords['col'] = np.array(['col' + str(x) for x in
darray.coords['col'].values])
darray.coords['row'] = np.array(['row' + str(x) for x in
darray.coords['row'].values])
self.darray = darray
开发者ID:cpaulik,项目名称:xray,代码行数:9,代码来源:test_plot.py
示例11: test_datetime_dimension
def test_datetime_dimension(self):
nrow = 3
ncol = 4
time = pd.date_range('2000-01-01', periods=nrow)
a = DataArray(easy_array((nrow, ncol)),
coords=[('time', time), ('y', range(ncol))])
a.plot()
ax = plt.gca()
self.assertTrue(ax.has_data())
开发者ID:cpaulik,项目名称:xray,代码行数:9,代码来源:test_plot.py
示例12: test_groupby_restore_dim_order
def test_groupby_restore_dim_order(self):
array = DataArray(np.random.randn(5, 3),
coords={'a': ('x', range(5)), 'b': ('y', range(3))},
dims=['x', 'y'])
for by, expected_dims in [('x', ('x', 'y')),
('y', ('x', 'y')),
('a', ('a', 'y')),
('b', ('x', 'b'))]:
result = array.groupby(by).apply(lambda x: x.squeeze())
self.assertEqual(result.dims, expected_dims)
开发者ID:akleeman,项目名称:xray,代码行数:10,代码来源:test_dataarray.py
示例13: test_reindex_method
def test_reindex_method(self):
x = DataArray([10, 20], dims='y')
y = [-0.5, 0.5, 1.5]
actual = x.reindex(y=y, method='backfill')
expected = DataArray([10, 20, np.nan], coords=[('y', y)])
self.assertDataArrayIdentical(expected, actual)
alt = Dataset({'y': y})
actual = x.reindex_like(alt, method='backfill')
self.assertDatasetIdentical(expected, actual)
开发者ID:akleeman,项目名称:xray,代码行数:10,代码来源:test_dataarray.py
示例14: test_convenient_facetgrid_4d
def test_convenient_facetgrid_4d(self):
a = easy_array((10, 15, 2, 3))
d = DataArray(a, dims=['y', 'x', 'columns', 'rows'])
g = d.plot(x='x', y='y', col='columns', row='rows')
self.assertArrayEqual(g.axes.shape, [3, 2])
for ax in g.axes.flat:
self.assertTrue(ax.has_data())
with self.assertRaisesRegexp(ValueError, '[Ff]acet'):
d.plot(x='x', y='y', col='columns', ax=plt.gca())
开发者ID:cpaulik,项目名称:xray,代码行数:11,代码来源:test_plot.py
示例15: test_concat
def test_concat(self):
self.ds['bar'] = Variable(['x', 'y'], np.random.randn(10, 20))
foo = self.ds['foo'].select()
bar = self.ds['bar'].rename('foo').select()
# from dataset array:
self.assertVariableEqual(Variable(['w', 'x', 'y'],
np.array([foo.values, bar.values])),
DataArray.concat([foo, bar], 'w'))
# from iteration:
grouped = [g for _, g in foo.groupby('x')]
stacked = DataArray.concat(grouped, self.ds['x'])
self.assertDataArrayIdentical(foo.select(), stacked)
开发者ID:ToddSmall,项目名称:xray,代码行数:12,代码来源:test_data_array.py
示例16: setUp
def setUp(self):
da = DataArray(easy_array(
(10, 15), start=-1), dims=['y', 'x'])
# add 2d coords
ds = da.to_dataset(name='testvar')
x, y = np.meshgrid(da.x.values, da.y.values)
ds['x2d'] = DataArray(x, dims=['y', 'x'])
ds['y2d'] = DataArray(y, dims=['y', 'x'])
ds.set_coords(['x2d', 'y2d'], inplace=True)
# set darray and plot method
self.darray = ds.testvar
self.plotmethod = getattr(self.darray.plot, self.plotfunc.__name__)
开发者ID:psederberg,项目名称:xray,代码行数:12,代码来源:test_plot.py
示例17: test_name
def test_name(self):
arr = self.dv
self.assertEqual(arr.name, 'foo')
copied = arr.copy()
arr.name = 'bar'
self.assertEqual(arr.name, 'bar')
self.assertDataArrayEqual(copied, arr)
actual = DataArray(Coordinate('x', [3]))
actual.name = 'y'
expected = DataArray(Coordinate('y', [3]))
self.assertDataArrayIdentical(actual, expected)
开发者ID:akleeman,项目名称:xray,代码行数:13,代码来源:test_dataarray.py
示例18: test_to_and_from_series
def test_to_and_from_series(self):
expected = self.dv.to_dataframe()['foo']
actual = self.dv.to_series()
self.assertArrayEqual(expected.values, actual.values)
self.assertArrayEqual(expected.index.values, actual.index.values)
self.assertEqual('foo', actual.name)
# test roundtrip
self.assertDataArrayIdentical(self.dv, DataArray.from_series(actual))
# test name is None
actual.name = None
expected_da = self.dv.rename(None)
self.assertDataArrayIdentical(expected_da,
DataArray.from_series(actual))
开发者ID:akleeman,项目名称:xray,代码行数:13,代码来源:test_dataarray.py
示例19: test_reduce
def test_reduce(self):
coords = {'x': [-1, -2], 'y': ['ab', 'cd', 'ef'],
'lat': (['x', 'y'], [[1, 2, 3], [-1, -2, -3]]),
'c': -999}
orig = DataArray([[-1, 0, 1], [-3, 0, 3]], coords, dims=['x', 'y'])
actual = orig.mean()
expected = DataArray(0, {'c': -999})
self.assertDataArrayIdentical(expected, actual)
actual = orig.mean(['x', 'y'])
self.assertDataArrayIdentical(expected, actual)
actual = orig.mean('x')
expected = DataArray([-2, 0, 2], {'y': coords['y'], 'c': -999}, 'y')
self.assertDataArrayIdentical(expected, actual)
actual = orig.mean(['x'])
self.assertDataArrayIdentical(expected, actual)
actual = orig.mean('y')
expected = DataArray([0, 0], {'x': coords['x'], 'c': -999}, 'x')
self.assertDataArrayIdentical(expected, actual)
self.assertVariableEqual(self.dv.reduce(np.mean, 'x'),
self.v.reduce(np.mean, 'x'))
orig = DataArray([[1, 0, np.nan], [3, 0, 3]], coords, dims=['x', 'y'])
actual = orig.count()
expected = DataArray(5, {'c': -999})
self.assertDataArrayIdentical(expected, actual)
开发者ID:akleeman,项目名称:xray,代码行数:31,代码来源:test_dataarray.py
示例20: test_broadcast_equals
def test_broadcast_equals(self):
a = DataArray([0, 0], {'y': 0}, dims='x')
b = DataArray([0, 0], {'y': ('x', [0, 0])}, dims='x')
self.assertTrue(a.broadcast_equals(b))
self.assertTrue(b.broadcast_equals(a))
self.assertFalse(a.equals(b))
self.assertFalse(a.identical(b))
c = DataArray([0], coords={'x': 0}, dims='y')
self.assertFalse(a.broadcast_equals(c))
self.assertFalse(c.broadcast_equals(a))
开发者ID:akleeman,项目名称:xray,代码行数:11,代码来源:test_dataarray.py
注:本文中的xray.DataArray类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论