home / github / issue_comments

Menu
  • GraphQL API
  • Search all tables

issue_comments: 366819497

This data as json

html_url issue_url id node_id user created_at updated_at author_association body reactions performed_via_github_app issue
https://github.com/pydata/xarray/issues/1914#issuecomment-366819497 https://api.github.com/repos/pydata/xarray/issues/1914 366819497 MDEyOklzc3VlQ29tbWVudDM2NjgxOTQ5Nw== 10928117 2018-02-19T22:40:17Z 2018-02-19T22:58:02Z NONE

For "get done" I had for example the following (similar to what I linked as my initial attempt) ```python coordinates = { 'x': np.linspace(-1, 1), 'y': np.linspace(0, 10), }

constants = { 'a': 1, 'b': 5 }

inps = [{constants, {k: v for k, v in zip(coordinates.keys(), x)}} for x in list(it.product(*coordinates.values()))]

def f(x, y, a, b): """Some dummy function.""" v = a * x2 + b * y2 return xr.DataArray(v, {'x': x, 'y': y, 'a': a, 'b': b})

simulate computation on cluster

values = list(map(lambda s: f(**s), inps))

gather and unstack the inputs

ds = xr.concat(values, dim='new', coords='all') ds = ds.set_index(new=list(set(ds.coords) - set(ds.dims))) ds = ds.unstack('new') ```

It is very close to what you suggest. My main question is if this can be done better. Mainly I am wondering if 1. Is there any built-in iterator over the Cartesian product of coordinates. If no, are there people that also think it would be useful? 2. Gathering together / unstacking of the data. My 3 line combo of concat, set_index and unstack seems to do the trick but it seems a bit like over complication. Ideally I'd expect to have some mechanism that works similar to:

`python inputs = cartesian_product(coordinates) # list similar toinps`` above values = [function(inp) for inp in inputs] # or using ipypparallel map

xarray_data = ... # some empty xarray object for inp, val in zip(inputs, values): xarray_data[inp] = val ```

I asked how to generate product of coordinates from xarray object because I was expecting that I can create xarray_data as an empty object with all coordinates set and then fill it.


Added comment

Having an empty, as filled with nans, object to start with would have this benefit that one could save partial results and have clean information what was already computed.

{
    "total_count": 0,
    "+1": 0,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
  297560256
Powered by Datasette · Queries took 1.075ms · About: xarray-datasette