home / github / issue_comments

Menu
  • GraphQL API
  • Search all tables

issue_comments: 771320891

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/4849#issuecomment-771320891 https://api.github.com/repos/pydata/xarray/issues/4849 771320891 MDEyOklzc3VlQ29tbWVudDc3MTMyMDg5MQ== 39069044 2021-02-02T03:12:41Z 2021-02-02T03:12:41Z CONTRIBUTOR

Some more progress here.

  1. I liked the idea of being able to supply p0 and bounds as a dictionary mapping between parameter names and values, which is much more in the style of xarray. So I've included the logic to translate between this and the scipy args which are just ordered lists. The logic first prioritizes any of these values supplied directly in keyword args, then looks for defaults in the function definition, and otherwise falls back to the scipy defaults.
  2. There's now a working implementation of multi-dimensional fits using ravel to flatten the coordinate arrays. One limitation is that func must be specified like f((x, y), z) as scipy takes a single x argument for the fitting coordinate. Maybe there is a clever way around this, but I think it's ok.
  3. Some changes to the API.

The best way to specify the fitting coordinates is a bit tricky to figure out. My original use case for this was needing to fit a relationship between two time/lat/lon dataarrays with the fit done over all time. But probably a more common use would be to just fit a curve over one or two dimensions that already exist in your data. So it would be great to handle these possibilities seamlessly.

What I've settled on for now is a coords argument that takes a list of coordinates that should be the same length as the input coordinates of your fitting function. Additionally, there is a reduce_dim arg, so that, say if you want to fit a function in time but aggregate over all lat and lon, you can supply those dimensions here. So with a 3D x/y/time array, any of the following should work: ```python

Fit a 1d function in time, returns parameters with dims (x, y)

da.curvefit(coords='time', ...)

Fit a 2d function in space, returns parameters with dims (t)

da.curvefit(coords=['x', 'y'], ...)

Fit a 1d function with another 3d dataarray and aggregate over time, returns parameters with dims (x, y)

da.curvefit(coords=da1, reduce_dim='time', ...) `` The logic to make this work got a bit complicated, since we need to supply the rightinput_core_dimstoapply_ufunc, and also to explicitly broadcast the coordinates to ensure theravel` operation works. Any thoughts on cleanup here appreciated.

Will eventually need to add tests and improve docs and examples. Tests especially I could use some help on.

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