当前位置: 首页>>代码示例>>Python>>正文


Python DataArray.isel方法代码示例

本文整理汇总了Python中xarray.DataArray.isel方法的典型用法代码示例。如果您正苦于以下问题:Python DataArray.isel方法的具体用法?Python DataArray.isel怎么用?Python DataArray.isel使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在xarray.DataArray的用法示例。


在下文中一共展示了DataArray.isel方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_cftime_datetime_mean

# 需要导入模块: from xarray import DataArray [as 别名]
# 或者: from xarray.DataArray import isel [as 别名]
def test_cftime_datetime_mean():
    times = cftime_range('2000', periods=4)
    da = DataArray(times, dims=['time'])

    assert da.isel(time=0).mean() == da.isel(time=0)

    expected = DataArray(times.date_type(2000, 1, 2, 12))
    result = da.mean()
    assert_equal(result, expected)

    da_2d = DataArray(times.values.reshape(2, 2))
    result = da_2d.mean()
    assert_equal(result, expected)
开发者ID:pydata,项目名称:xarray,代码行数:15,代码来源:test_duck_array_ops.py

示例2: test_default_title

# 需要导入模块: from xarray import DataArray [as 别名]
# 或者: from xarray.DataArray import isel [as 别名]
 def test_default_title(self):
     a = DataArray(easy_array((4, 3, 2)), dims=['a', 'b', 'c'])
     a.coords['c'] = [0, 1]
     a.coords['d'] = u'foo'
     self.plotfunc(a.isel(c=1))
     title = plt.gca().get_title()
     self.assertTrue('c = 1, d = foo' == title or 'd = foo, c = 1' == title)
开发者ID:CCI-Tools,项目名称:xarray,代码行数:9,代码来源:test_plot.py

示例3: TestFacetGrid

# 需要导入模块: from xarray import DataArray [as 别名]
# 或者: from xarray.DataArray import isel [as 别名]
class TestFacetGrid(PlotTestCase):
    def setUp(self):
        d = easy_array((10, 15, 3))
        self.darray = DataArray(d, dims=["y", "x", "z"], coords={"z": ["a", "b", "c"]})
        self.g = xplt.FacetGrid(self.darray, col="z")

    def test_no_args(self):
        self.g.map_dataarray(xplt.contourf, "x", "y")

        # Don't want colorbar labeled with 'None'
        alltxt = text_in_fig()
        self.assertNotIn("None", alltxt)

        for ax in self.g.axes.flat:
            self.assertTrue(ax.has_data())

            # default font size should be small
            fontsize = ax.title.get_size()
            self.assertLessEqual(fontsize, 12)

    def test_names_appear_somewhere(self):
        self.darray.name = "testvar"
        self.g.map_dataarray(xplt.contourf, "x", "y")
        for k, ax in zip("abc", self.g.axes.flat):
            self.assertEqual("z = {0}".format(k), ax.get_title())

        alltxt = text_in_fig()
        self.assertIn(self.darray.name, alltxt)
        for label in ["x", "y"]:
            self.assertIn(label, alltxt)

    def test_text_not_super_long(self):
        self.darray.coords["z"] = [100 * letter for letter in "abc"]
        g = xplt.FacetGrid(self.darray, col="z")
        g.map_dataarray(xplt.contour, "x", "y")
        alltxt = text_in_fig()
        maxlen = max(len(txt) for txt in alltxt)
        self.assertLess(maxlen, 50)

        t0 = g.axes[0, 0].get_title()
        self.assertTrue(t0.endswith("..."))

    def test_colorbar(self):
        vmin = self.darray.values.min()
        vmax = self.darray.values.max()
        expected = np.array((vmin, vmax))

        self.g.map_dataarray(xplt.imshow, "x", "y")

        for image in plt.gcf().findobj(mpl.image.AxesImage):
            clim = np.array(image.get_clim())
            self.assertTrue(np.allclose(expected, clim))

        self.assertEqual(1, len(find_possible_colorbars()))

    def test_empty_cell(self):
        g = xplt.FacetGrid(self.darray, col="z", col_wrap=2)
        g.map_dataarray(xplt.imshow, "x", "y")

        bottomright = g.axes[-1, -1]
        self.assertFalse(bottomright.has_data())
        self.assertFalse(bottomright.get_visible())

    def test_norow_nocol_error(self):
        with self.assertRaisesRegexp(ValueError, r"[Rr]ow"):
            xplt.FacetGrid(self.darray)

    def test_groups(self):
        self.g.map_dataarray(xplt.imshow, "x", "y")
        upperleft_dict = self.g.name_dicts[0, 0]
        upperleft_array = self.darray.loc[upperleft_dict]
        z0 = self.darray.isel(z=0)

        self.assertDataArrayEqual(upperleft_array, z0)

    def test_float_index(self):
        self.darray.coords["z"] = [0.1, 0.2, 0.4]
        g = xplt.FacetGrid(self.darray, col="z")
        g.map_dataarray(xplt.imshow, "x", "y")

    def test_nonunique_index_error(self):
        self.darray.coords["z"] = [0.1, 0.2, 0.2]
        with self.assertRaisesRegexp(ValueError, r"[Uu]nique"):
            xplt.FacetGrid(self.darray, col="z")

    def test_robust(self):
        z = np.zeros((20, 20, 2))
        darray = DataArray(z, dims=["y", "x", "z"])
        darray[:, :, 1] = 1
        darray[2, 0, 0] = -1000
        darray[3, 0, 0] = 1000
        g = xplt.FacetGrid(darray, col="z")
        g.map_dataarray(xplt.imshow, "x", "y", robust=True)

        # Color limits should be 0, 1
        # The largest number displayed in the figure should be less than 21
        numbers = set()
        alltxt = text_in_fig()
        for txt in alltxt:
            try:
#.........这里部分代码省略.........
开发者ID:spencerahill,项目名称:xarray,代码行数:103,代码来源:test_plot.py

示例4: test_default_title

# 需要导入模块: from xarray import DataArray [as 别名]
# 或者: from xarray.DataArray import isel [as 别名]
 def test_default_title(self):
     a = DataArray(easy_array((4, 3, 2)), dims=["a", "b", "c"])
     a.coords["d"] = u"foo"
     self.plotfunc(a.isel(c=1))
     title = plt.gca().get_title()
     self.assertTrue("c = 1, d = foo" == title or "d = foo, c = 1" == title)
开发者ID:spencerahill,项目名称:xarray,代码行数:8,代码来源:test_plot.py

示例5: TestFacetGrid

# 需要导入模块: from xarray import DataArray [as 别名]
# 或者: from xarray.DataArray import isel [as 别名]
class TestFacetGrid(PlotTestCase):

    def setUp(self):
        d = easy_array((10, 15, 3))
        self.darray = DataArray(d, dims=['y', 'x', 'z'],
                                coords={'z': ['a', 'b', 'c']})
        self.g = xplt.FacetGrid(self.darray, col='z')

    @pytest.mark.slow
    def test_no_args(self):
        self.g.map_dataarray(xplt.contourf, 'x', 'y')

        # Don't want colorbar labeled with 'None'
        alltxt = text_in_fig()
        self.assertNotIn('None', alltxt)

        for ax in self.g.axes.flat:
            self.assertTrue(ax.has_data())

            # default font size should be small
            fontsize = ax.title.get_size()
            self.assertLessEqual(fontsize, 12)

    @pytest.mark.slow
    def test_names_appear_somewhere(self):
        self.darray.name = 'testvar'
        self.g.map_dataarray(xplt.contourf, 'x', 'y')
        for k, ax in zip('abc', self.g.axes.flat):
            self.assertEqual('z = {0}'.format(k), ax.get_title())

        alltxt = text_in_fig()
        self.assertIn(self.darray.name, alltxt)
        for label in ['x', 'y']:
            self.assertIn(label, alltxt)

    @pytest.mark.slow
    def test_text_not_super_long(self):
        self.darray.coords['z'] = [100 * letter for letter in 'abc']
        g = xplt.FacetGrid(self.darray, col='z')
        g.map_dataarray(xplt.contour, 'x', 'y')
        alltxt = text_in_fig()
        maxlen = max(len(txt) for txt in alltxt)
        self.assertLess(maxlen, 50)

        t0 = g.axes[0, 0].get_title()
        self.assertTrue(t0.endswith('...'))

    @pytest.mark.slow
    def test_colorbar(self):
        vmin = self.darray.values.min()
        vmax = self.darray.values.max()
        expected = np.array((vmin, vmax))

        self.g.map_dataarray(xplt.imshow, 'x', 'y')

        for image in plt.gcf().findobj(mpl.image.AxesImage):
            clim = np.array(image.get_clim())
            self.assertTrue(np.allclose(expected, clim))

        self.assertEqual(1, len(find_possible_colorbars()))

    @pytest.mark.slow
    def test_empty_cell(self):
        g = xplt.FacetGrid(self.darray, col='z', col_wrap=2)
        g.map_dataarray(xplt.imshow, 'x', 'y')

        bottomright = g.axes[-1, -1]
        self.assertFalse(bottomright.has_data())
        self.assertFalse(bottomright.get_visible())

    @pytest.mark.slow
    def test_norow_nocol_error(self):
        with self.assertRaisesRegexp(ValueError, r'[Rr]ow'):
            xplt.FacetGrid(self.darray)

    @pytest.mark.slow
    def test_groups(self):
        self.g.map_dataarray(xplt.imshow, 'x', 'y')
        upperleft_dict = self.g.name_dicts[0, 0]
        upperleft_array = self.darray.loc[upperleft_dict]
        z0 = self.darray.isel(z=0)

        self.assertDataArrayEqual(upperleft_array, z0)

    @pytest.mark.slow
    def test_float_index(self):
        self.darray.coords['z'] = [0.1, 0.2, 0.4]
        g = xplt.FacetGrid(self.darray, col='z')
        g.map_dataarray(xplt.imshow, 'x', 'y')

    @pytest.mark.slow
    def test_nonunique_index_error(self):
        self.darray.coords['z'] = [0.1, 0.2, 0.2]
        with self.assertRaisesRegexp(ValueError, r'[Uu]nique'):
            xplt.FacetGrid(self.darray, col='z')

    @pytest.mark.slow
    def test_robust(self):
        z = np.zeros((20, 20, 2))
        darray = DataArray(z, dims=['y', 'x', 'z'])
#.........这里部分代码省略.........
开发者ID:CCI-Tools,项目名称:xarray,代码行数:103,代码来源:test_plot.py


注:本文中的xarray.DataArray.isel方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。