home / github / issues

Menu
  • GraphQL API
  • Search all tables

issues: 249188875

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
249188875 MDU6SXNzdWUyNDkxODg4NzU= 1506 Support for basic math (multiplication, difference) on two xarray-Datasets 30219501 closed 0     3 2017-08-09T23:16:09Z 2017-08-10T16:14:41Z 2017-08-10T16:14:41Z NONE      

Lets assume one has loaded two datasets 'datmod' and 'datref' containing daily data over one year. Data look like:

Dimensions: (bnds: 2, rlat: 228, rlon: 234, time: 365) Coordinates: * rlon (rlon) float64 -28.24 -28.02 -27.8 -27.58 -27.36 -27.14 ... * rlat (rlat) float64 -23.52 -23.3 -23.08 -22.86 -22.64 -22.42 ... * time (time) datetime64[ns] 2013-01-01T11:30:00 ... Dimensions without coordinates: bnds Data variables: rotated_pole |S1 '' time_bnds (time, bnds) float64 1.073e+09 1.073e+09 1.073e+09 ... ASWGLOB_S (time, rlat, rlon) float64 nan nan nan nan nan nan nan nan ...

Now I want to compute a more complex metric as the temporal correlation and combine it with the functionality of groupby or resample, i.e. determine the temporal correlation for each month seperately. So, starting with ``` def anomaly(x): return x - x.mean('time')

a = datref.groupby('time.month').apply(anomaly) b = datmod.groupby('time.month').apply(anomaly) gives me the anomalies for each time step with respect to monthly means. However, for the nominator of the correlation (the denominator is not discussed here) the elementwise multiplication is needed: corr = a*b and later on this product is grouped monthly and averaged over time. The problem is that the product 'a*b' gives an dataset with missing variables <xarray.Dataset> Dimensions: (rlat: 228, rlon: 234, time: 0) Coordinates: * time (time) datetime64[ns] * rlon (rlon) float64 -28.24 -28.02 -27.8 -27.58 -27.36 -27.14 -26.92 ... * rlat (rlat) float64 -23.52 -23.3 -23.08 -22.86 -22.64 -22.42 -22.2 ... Data variables: month (time) int64 ```

I can overcome the problem by doing something like corr=a[varname].data - b[varname.data]. But then I have an numpy.array which does not support groupby- and aggregation-functionality, i.e. I must clone the dataset 'datmod' and replace all the data with data of 'corr'. Then I can use again Dataset-aggregation functionality.

Is there a way to overcome the problem of elementwise multiplication (as well as subtraction) or should such a feature be added in the future?

{
    "url": "https://api.github.com/repos/pydata/xarray/issues/1506/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

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