home / github / issues

Menu
  • GraphQL API
  • Search all tables

issues: 538809911

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
538809911 MDU6SXNzdWU1Mzg4MDk5MTE= 3632 applying ufunc over lon and lat 44284270 closed 0     5 2019-12-17T03:25:44Z 2020-08-23T17:37:29Z 2020-08-23T17:37:29Z NONE      

I am trying to apply ufunc to my code to speed it up. Currently I am looping over lon and lat and it takes ages. After long reads I came up with this though am still not sure where I a going wrong. Suggestions and Ideas would be very helpful to get me going. thanks

``` python def get_grps(s, thresh=-1, Nmin=3): """ Nmin : int > 0 Min number of consecutive values below threshold. """ s = pd.Series(s) m = np.logical_and.reduce([s.shift(-i).le(thresh) for i in range(Nmin)]) if Nmin > 1: m = pd.Series(m, index=s.index).replace({False: np.NaN}).ffill(limit=Nmin-1).fillna(False) else: m = pd.Series(m, index=s.index)

# Form consecutive groups
gps = m.ne(m.shift(1)).cumsum().where(m)

# Return None if no groups, else the aggregations
if gps.isnull().all():
    return [0]
else:
    d = s.groupby(gps).agg([list, sum, 'size']).reset_index(drop=True)

    data = np.sum((d['size']))

    return data

```

 obj is 3d data of shape (324x180x360) (time,lat,lon)

``` python def consec_events(obj):

  time_nums = xr.DataArray(obj['time'].values.astype(np.float),
                         dims='time',
                         coords={'time': obj['time']},
                         name='time_nums')
   trend = xr.apply_ufunc(get_grps,time_nums, obj,
                       vectorize=True,
                       input_core_dims=[['time'], ['time']],
                       output_core_dims=[[]],
                       output_dtypes=[np.float],
                       dask='parallelized',output_sizes={'ntime':time_nums.shape[0]})

return trend

results = consec_events(spi) ```

ERROR IS HERE

... File "/Users/mada0007/anaconda3/envs/RESEARCH_QUESTION_TWO/lib/python3.7/site-packages/numpy/lib/function_base.py", line 2157, in _vectorize_call res = self._vectorize_call_with_signature(func, args) File "/Users/mada0007/anaconda3/envs/RESEARCH_QUESTION_TWO/lib/python3.7/site-packages/numpy/lib/function_base.py", line 2221, in _vectorize_call_with_signature output[index] = result ValueError: setting an array element with a sequence.

I am relatively new to apply this and I have been reading quite a lot. I would appreciatiate if I can be corrected on how to properly apply this over time dimension of my data and get resulting 2d array for each lon and lat?

{
    "url": "https://api.github.com/repos/pydata/xarray/issues/3632/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
  • 5 rows from issue in issue_comments
Powered by Datasette · Queries took 79.443ms · About: xarray-datasette