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


Python DataArray.compute方法代码示例

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


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

示例1: test_dataarray_pickle

# 需要导入模块: from xarray import DataArray [as 别名]
# 或者: from xarray.DataArray import compute [as 别名]
 def test_dataarray_pickle(self):
     # Test that pickling/unpickling does not convert the dask
     # backend to numpy
     a1 = DataArray(build_dask_array())
     a1.compute()
     self.assertFalse(a1._in_memory)
     self.assertEquals(kernel_call_count, 1)
     a2 = pickle.loads(pickle.dumps(a1))
     self.assertEquals(kernel_call_count, 1)
     self.assertDataArrayIdentical(a1, a2)
     self.assertFalse(a1._in_memory)
     self.assertFalse(a2._in_memory)
开发者ID:SixtyCapital,项目名称:xarray,代码行数:14,代码来源:test_dask.py

示例2: test_expand_without_dims

# 需要导入模块: from xarray import DataArray [as 别名]
# 或者: from xarray.DataArray import compute [as 别名]
 def test_expand_without_dims(self):
     from satpy.resample import NativeResampler
     import numpy as np
     import dask.array as da
     from xarray import DataArray
     from pyresample.geometry import AreaDefinition
     from pyresample.utils import proj4_str_to_dict
     ds1 = DataArray(da.zeros((100, 50), chunks=85))
     proj_dict = proj4_str_to_dict('+proj=lcc +datum=WGS84 +ellps=WGS84 '
                                   '+lon_0=-95. +lat_0=25 +lat_1=25 '
                                   '+units=m +no_defs')
     target = AreaDefinition(
         'test',
         'test',
         'test',
         proj_dict,
         x_size=100,
         y_size=200,
         area_extent=(-1000., -1500., 1000., 1500.),
     )
     # source geo def doesn't actually matter
     resampler = NativeResampler(None, target)
     new_arr = resampler.resample(ds1)
     self.assertEqual(new_arr.shape, (200, 100))
     new_arr2 = resampler.resample(ds1.compute())
     self.assertTrue(np.all(new_arr == new_arr2))
开发者ID:davidh-ssec,项目名称:satpy,代码行数:28,代码来源:test_resample.py

示例3: test_dataarray_pickle

# 需要导入模块: from xarray import DataArray [as 别名]
# 或者: from xarray.DataArray import compute [as 别名]
 def test_dataarray_pickle(self):
     # Test that pickling/unpickling converts the dask backend
     # to numpy in neither the data variable nor the non-index coords
     data = build_dask_array('data')
     nonindex_coord = build_dask_array('coord')
     a1 = DataArray(data, dims=['x'], coords={'y': ('x', nonindex_coord)})
     a1.compute()
     assert not a1._in_memory
     assert not a1.coords['y']._in_memory
     assert kernel_call_count == 2
     a2 = pickle.loads(pickle.dumps(a1))
     assert kernel_call_count == 2
     assert_identical(a1, a2)
     assert not a1._in_memory
     assert not a2._in_memory
     assert not a1.coords['y']._in_memory
     assert not a2.coords['y']._in_memory
开发者ID:jcmgray,项目名称:xarray,代码行数:19,代码来源:test_dask.py

示例4: ensembles2dataset_dask

# 需要导入模块: from xarray import DataArray [as 别名]
# 或者: from xarray.DataArray import compute [as 别名]
def ensembles2dataset_dask(ensdict, ncfpath, dsattrs={}, chunks=10,
                           verbose=True, print_every=1000):
    """
    Convert a dictionary of ensembles into an xarray Dataset object
    using dask.delayed to keep memory usage feasible.
    """
    mms2ms = 1e-3
    n=0
    # fbadens = np.array(ensdict_aux)==None
    # nt = len(ensdict) - np.sum(fbadens)
    # embed()

    ensdict0 = None
    while ensdict0 is None:
        ensdict0 = ensdict[n].compute()
        n+=1
    nz = ensdict0['fixed_leader_janus']['number_of_cells']

    fixj = ensdict0['fixed_leader_janus'].compute()
    fix5 = ensdict0['fixed_leader_beam5'].compute()

    # Add ping offset to get beam 5's timestamps.
    dt5 = fix5['ping_offset_time'] # In milliseconds.
    dt5 = np.array(Timedelta(dt5, unit='ms'))

    th = fixj['beam_angle']
    assert th==25 # Always 25 degrees.
    th = th*np.pi/180.
    Cth = np.cos(th)

    # Construct along-beam/vertical axes.
    cm2m = 1e-2
    r1janus = fixj['bin_1_distance']*cm2m
    r1b5 = fix5['bin_1_distance']*cm2m
    ncj = fixj['number_of_cells']
    nc5 = fix5['number_of_cells']
    lcj = fixj['depth_cell_length']*cm2m
    lc5 = fix5['depth_cell_length']*cm2m
    Lj = ncj*lcj # Distance from center of bin 1 to the center of last bin (Janus).
    L5 = nc5*lc5 # Distance from center of bin 1 to the center of last bin (beam 5).

    rb = r1janus + np.arange(0, Lj, lcj) # Distance from xducer head
                                         # (Janus).
    zab = Cth*rb                         # Vertical distance from xducer head
                                         # (Janus).
    zab5 = r1b5 + np.arange(0, L5, lc5)  # Distance from xducer head, also
                                         # depth for the vertical beam.

    rb = IndexVariable('z', rb, attrs={'units':'meters', 'long_name':"along-beam distance from the xducer's face to the center of the bins, for beams 1-4 (Janus)"})
    zab = IndexVariable('z', zab, attrs={'units':'meters', 'long_name':"vertical distance from the instrument's head to the center of the bins, for beams 1-4 (Janus)"})
    zab5 = IndexVariable('z5', zab5, attrs={'units':'meters', 'long_name':"vertical distance from xducer face to the center of the bins, for beam 5 (vertical)"})

    ensdict = from_sequence(ensdict)
    tjanus = ensdict.map_partitions(_alloc_timestamp_parts)
    t5 = _addtarr(tjanus, dt5)

    if verbose: print("Unpacking timestamps.")
    time = IndexVariable('time', tjanus.compute(), attrs={'long_name':'timestamps for beams 1-4 (Janus)'})
    time5 = IndexVariable('time5', t5.compute(), attrs={'long_name':'timestamps for beam 5 (vertical)'})
    if verbose: print("Done unpacking timestamps.")

    coords0 = dict(time=time)
    coords = dict(z=zab, time=time, rb=rb)
    coords5 = dict(z5=zab5, time5=time5)
    dims = ['z', 'time']
    dims5 = ['z5', 'time5']
    dims0 = ['time']

    coordsdict = coords0
    if verbose: print("Allocating heading, pitch, roll.")
    kwda = dict(coords=coordsdict, dims=dims0, attrs=dict(units=unit, long_name=lname))
    svars = ['heading', 'pitch', 'roll']
    long_names = svars
    units = ['degrees']*3
    grp = 'variable_leader_janus'
    vars1d = dict()
    for vname,lname,unit in zip(svars,long_names,units):
        if verbose: print(vname)
        wrk = ensdict.map_partitions(_alloc_hpr, grp, vname)
        # wrk = darr.from_array(np.array(wrk.compute()), chunks=chunks)
        wrk2 = delayed(_bag2DataArray)(wrk, chunks)(**kwda)
        vars1d.update({vname:wrk2})
    del(wrk, wrk2)

    ds2hpr = Dataset(data_vars=vars1d, coords=coordsdict)
    ds2hpr = ds2hpr.to_netcdf(ncfpath, compute=False, mode='w')
    if verbose: print("Saving heading, pitch, roll.")
    ds2hpr.compute()
    if verbose: print("Done saving heading, pitch, roll.")
    del(ds2hpr)

    coordsdict = coords5
    # Load beam 5 variables into memory to
    # be able to put them in a chunked DataArray.
    if verbose: print("Allocating beam 5 variables.")
    grps = ['velocity_beam5', 'correlation_beam5', 'echo_intensity_beam5']
    long_names = ['Beam 5 velocity', 'Beam 5 correlation', 'Beam 5 echo amplitude']
    units = ['mm/s, positive toward xducer face', 'unitless', 'dB']
    vars5 = dict()
    for grp,lname,unit in zip(grps,long_names,units):
#.........这里部分代码省略.........
开发者ID:USF-COT,项目名称:trdi_adcp_readers,代码行数:103,代码来源:readers.py


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