home / github / issues

Menu
  • GraphQL API
  • Search all tables

issues: 502060636

This data as json

id node_id number title user state locked assignee milestone comments created_at updated_at closed_at author_association active_lock_reason draft pull_request body reactions performed_via_github_app state_reason repo type
502060636 MDU6SXNzdWU1MDIwNjA2MzY= 3368 Shift DataArray along a coordinate for different values of each element of another coordinate 49461634 closed 0     1 2019-10-03T13:17:10Z 2020-03-29T14:18:11Z 2020-03-29T14:16:43Z NONE      

MCVE Code Sample

```python

Your code here

Original_DataArray = <xarray.DataArray 'Conexões Domésticas e Piscinas' (projetos_resi: 9, res_segmentacao: 21, time: 133, bands: 10)>

Shift_Map = <xarray.DataArray 'Anos por Desconto' (res_segmentacao: 21)> array([ 0, 0, 0, 24, 0, 24, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 24, 36, 60, 36, 0])

"Multi" Shift Function

def _fn(dataArray,over_shift_index,multi_shift_index,shift_map,initialValues=None): """
-dataArray: dataarray to shift -over_shift_index: index over apply shit of dataarray -multi_shift_index: index with the elements to apply a different value shift -shift_map: datarray indexed by multi_shift_index with the values to shift for each element """

_da = dataArray.copy()
_shift_map = shift_map.astype(int)

for name, sl in _da.groupby(multi_shift_index.name):
    _shift = subscript(_shift_map, multi_shift_index, name ).values.tolist()
    _sl = sl.squeeze(multi_shift_index.name).shift(time = _shift)

    _dict = {multi_shift_index.name : name}
    _da.loc[_dict] = _sl


return _da.fillna(0.)

```

Expected Output

Same estructure DataArray shifted along the "time" coordinate by a different value for each element of the "res_segmentacao" coordinate.

python exp_output= multidynamic( Original_DataArray , time, res_segmentacao, Shift_Map )

Problem Description

I´ve reached my objective but I wanted to consult if anyone had donde this in a more efficient way. Thanks!

{
    "url": "https://api.github.com/repos/pydata/xarray/issues/3368/reactions",
    "total_count": 0,
    "+1": 0,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
  completed 13221727 issue

Links from other tables

  • 0 rows from issues_id in issues_labels
  • 1 row from issue in issue_comments
Powered by Datasette · Queries took 0.745ms · About: xarray-datasette