home / github / issue_comments

Menu
  • Search all tables
  • GraphQL API

issue_comments: 609023296

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/3931#issuecomment-609023296 https://api.github.com/repos/pydata/xarray/issues/3931 609023296 MDEyOklzc3VlQ29tbWVudDYwOTAyMzI5Ng== 30388627 2020-04-04T12:45:03Z 2020-04-04T12:50:12Z NONE

@mathause Thanks! It works well. Here's the solution:

Code

``` def interp1d_np(data, x, xi): from scipy import interpolate # return np.interp(xi, x, data) f = interpolate.interp1d(x, data, fill_value='extrapolate') return f(xi)

interped = xr.apply_ufunc( interp1d_np, # first the function bottom_up, # now arguments in the order expected by 'interp1_np' pressure.values, # as above interp_p.values, # as above input_core_dims=[["z"], ["z"], ["new_z"]], # list with one entry per arg output_core_dims=[["new_z"]], # returned data has one dimension exclude_dims=set(("z",)), # dimensions allowed to change size. Must be a set! vectorize=True, # loop over non-core dims ) interped = interped.rename({"new_z": "z"})

print(np.testing.assert_allclose(output.values, interped.values)) ```

Result:

None

However, when I apply it to my real data, I got some errors:

Code

``` def interp1d_np(data, x, xi): from scipy import interpolate f = interpolate.interp1d(x, data, fill_value='extrapolate') return f(xi)

interped = xr.apply_ufunc(
    interp1d_np,
    regrid_vars['no2'],
    regrid_vars['p'].values,
    s5p['p'].values,
    input_core_dims=[["bottom_top"], ["bottom_top"], ["new_dim"]],
    output_core_dims=[["new_dim"]],
    exclude_dims=set(("bottom_top",)),
    vectorize=True,
)

```

Error:

File "/home/xin/miniconda3/envs/satpy/lib/python3.7/site-packages/numpy/lib/function_base.py", line 1830, in _update_dim_sizes % (dim, size, dim_sizes[dim])) ValueError: inconsistent size for core dimension 'dim0': 450 vs 39 Here's the output of print(regrid_vars['no2'].shape, regrid_vars['p'].values.shape, s5p['p'].values.shape): (39, 389, 450) (39, 389, 450) (25, 389, 450) The shape looks fine.

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