Python xarray.zeros_like() Examples

The following are 4 code examples of xarray.zeros_like(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module xarray , or try the search function .
Example #1
Source File: visualization.py    From minian with GNU General Public License v3.0 6 votes vote down vote up
def __init__(self, shiftds, sampling=2, pct_thres=99.9, on=0):
        self.shiftds = shiftds
        self.temps = shiftds['temps']
        self.on = on
        self.pct_thres = pct_thres
        self.hh = self.temps.sizes['height']
        self.ww = self.temps.sizes['width']
        self.mask = xr.zeros_like(self.temps, dtype=bool)
        self.ls_anm = np.unique(shiftds.coords['animal'].values)
        self.ls_ss = np.unique(shiftds.coords['session'].values)
        Selection = Stream.define(
            'selection',
            anm=param.Selector(self.ls_anm),
            ss=param.Selector(self.ls_ss))
        self.str_sel = Selection(anm=self.ls_anm[0], ss=self.ls_ss[0])
        # self.sampling = sampling
        self.str_box = BoxEdit()
        self.box = hv.DynamicMap(self._box, streams=[self.str_box])
        self.box = self.box.opts(
            style=dict(fill_alpha=0.3, line_color='white'))
        self.wgts = self._widgets()
        self.hvobjs = self._get_objs() 
Example #2
Source File: distributed.py    From cosima-cookbook with Apache License 2.0 6 votes vote down vote up
def compute_by_block(dsx):
    """
    
    """
    
    # determine index key for each chunk
    slices = []
    for chunks in dsx.chunks:
        L  = [0,] + list(np.cumsum(chunks))
        slices.append( [slice(a, b) 
                        for a,b in (zip(L[:-1], L[1:]))]  )
    indexes = list(product(*slices))
    
    # allocate memory to receive result
    if isinstance(dsx, xr.DataArray):
        result = xr.zeros_like(dsx).load()
    else:
        result = np.zeros(dsx.shape)
    
    #evaluate each chunk one at a time
    for index in tqdm_notebook(indexes, leave=False):
        block = dsx.__getitem__(index).compute()
        result.__setitem__(index, block)
    
    return result 
Example #3
Source File: test_statistics.py    From esmlab with Apache License 2.0 5 votes vote down vote up
def test_dimension_mismatch(function):
    darr = xr.DataArray([[1, 2], [3, 4]], dims=['x', 'y'])
    w = xr.zeros_like(darr)
    res = function(darr, dim=['x', 'z'], weights=w)
    xr.testing.assert_equal(res, darr) 
Example #4
Source File: cnmf.py    From minian with GNU General Public License v3.0 5 votes vote down vote up
def update_spatial_perpx(y, alpha, sub, C):
    res = np.zeros_like(sub, dtype=y.dtype)
    if np.sum(sub) > 0:
        C = C[:, sub]
        clf = LassoLars(alpha=alpha, positive=True)
        coef = clf.fit(C, y).coef_
        res[np.where(sub)[0]] = coef
    return res