home / github / issue_comments

Menu
  • GraphQL API
  • Search all tables

issue_comments: 328341717

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/pull/1517#issuecomment-328341717 https://api.github.com/repos/pydata/xarray/issues/1517 328341717 MDEyOklzc3VlQ29tbWVudDMyODM0MTcxNw== 6628425 2017-09-10T13:09:40Z 2017-09-10T13:09:40Z MEMBER

@nbren12 for similar use cases I've had success writing a single function that does the ghosting, applies a function with map_blocks, and trims the edges. Then I apply that single function on a DataArray with apply_ufunc (so a single call to apply_ufunc rather than three). As an example, a simple centered difference on an array with periodic boundaries might be accomplished with: ```python def centered_diff_numpy(arr, axis=-1, spacing=1.): return (np.roll(arr, -1, axis=axis) - np.roll(arr, 1, axis=axis)) / (2. * spacing)

def centered_diff(da, dim, spacing=1.): def apply_centered_diff(arr, spacing=1.): if isinstance(arr, np.ndarray): return centered_diff_numpy(arr, spacing=spacing) else: axis = len(arr.shape) - 1 g = darray.ghost.ghost(arr, depth={axis: 1}, boundary={axis: 'periodic'}) result = darray.map_blocks(centered_diff_numpy, g, spacing=spacing) return darray.ghost.trim_internal(result, {axis: 1})

return computation.apply_ufunc(
    apply_centered_diff, da, input_core_dims=[[dim]],
    output_core_dims=[[dim]], dask_array='allowed', kwargs={'spacing': spacing})

Depending on your use case, you might also consider `dask.ghost.map_overlap` to do all of those three steps in one line, i.e. replace `apply_centered_diff` with the following:python def apply_centered_diff(arr, spacing=1.): if isinstance(arr, np.ndarray): return centered_diff_numpy(arr, spacing=spacing) else: axis = len(arr.shape) - 1 return darray.ghost.map_overlap( arr, centered_diff_numpy, depth={axis: 1}, boundary={axis: 'periodic'}, spacing=spacing) ``` (Not sure if this is what @shoyer had in mind, but just offering an example)

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