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/4300#issuecomment-770133047,https://api.github.com/repos/pydata/xarray/issues/4300,770133047,MDEyOklzc3VlQ29tbWVudDc3MDEzMzA0Nw==,39069044,2021-01-30T01:38:18Z,2021-01-30T01:38:18Z,CONTRIBUTOR,"I needed this functionality for a project, and piggy-backing off the last couple of comments decided the `curve_fit` wrapped by `apply_ufunc` approach works quite well. I put together a PR in #4849. Any feedback welcome!","{""total_count"": 2, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 2, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",,671609109 https://github.com/pydata/xarray/issues/4300#issuecomment-677666962,https://api.github.com/repos/pydata/xarray/issues/4300,677666962,MDEyOklzc3VlQ29tbWVudDY3NzY2Njk2Mg==,31700619,2020-08-20T13:32:33Z,2020-08-20T13:40:07Z,CONTRIBUTOR,"> > > cheers @TomNicholas , that's helpful. :) I've started messing with the idea in [this Gist](https://gist.github.com/AndrewWilliams3142/6ea8b4f4287e0d0290f52b2fcd50a662) if you want to have a look. > > It's pretty hacky at the moment, but might be helpful as a testbed. (And a way of getting my head around how `apply_ufunc` would work in this context) @AndrewWilliams3142 I've tried to extend this to a 3d matrix (timeseries of 2d matrices) using Dask, it seems to work! Have a look here https://gist.github.com/clausmichele/8350e1f7f15e6828f29579914276de71","{""total_count"": 1, ""+1"": 1, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",,671609109 https://github.com/pydata/xarray/issues/4300#issuecomment-673593388,https://api.github.com/repos/pydata/xarray/issues/4300,673593388,MDEyOklzc3VlQ29tbWVudDY3MzU5MzM4OA==,56925856,2020-08-13T16:59:30Z,2020-08-13T16:59:30Z,CONTRIBUTOR,"cheers @TomNicholas , that's helpful. :) I've started messing with the idea in [this Gist](https://gist.github.com/AndrewWilliams3142/6ea8b4f4287e0d0290f52b2fcd50a662) if you want to have a look. It's pretty hacky at the moment, but might be helpful as a testbed. (And a way of getting my head around how `apply_ufunc` would work in this context)","{""total_count"": 0, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",,671609109 https://github.com/pydata/xarray/issues/4300#issuecomment-672084619,https://api.github.com/repos/pydata/xarray/issues/4300,672084619,MDEyOklzc3VlQ29tbWVudDY3MjA4NDYxOQ==,56925856,2020-08-11T16:49:00Z,2020-08-11T16:49:29Z,CONTRIBUTOR,"@TomNicholas I'm a bit confused about how the `fit_along` argument would work actually. If you had 2D data and wanted to fit a 1D function to one of the dimensions, wouldn't you have to either take a `mean` (or `slice`?) across the other dimension? Edit: It's been a hot day here, so apologies if this turns out to be a dumb q haha","{""total_count"": 0, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",,671609109 https://github.com/pydata/xarray/issues/4300#issuecomment-671442450,https://api.github.com/repos/pydata/xarray/issues/4300,671442450,MDEyOklzc3VlQ29tbWVudDY3MTQ0MjQ1MA==,56925856,2020-08-10T16:01:06Z,2020-08-10T16:01:06Z,CONTRIBUTOR,"This sounds very cool! :) I'm not sure that I have much to add, but given @aulemahal 's good point about the complexity of rewriting `curve_fit` from scratch, it seems that maybe a good first step would just be to wrap the existing `scipy` functionality? Alternatively, given that `xr.apply_ufunc` can already do this (though it's probably complicated), perhaps it would be good to just have an example in the documentation? ","{""total_count"": 0, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",,671609109 https://github.com/pydata/xarray/issues/4300#issuecomment-669065910,https://api.github.com/repos/pydata/xarray/issues/4300,669065910,MDEyOklzc3VlQ29tbWVudDY2OTA2NTkxMA==,31700619,2020-08-05T08:44:06Z,2020-08-05T08:44:06Z,CONTRIBUTOR,"I am also trying to get similar results of scipy curve_fit with xarray and dask. Is there a workaround I can use to fit a sinusoidal function with the current functions/methods? This is the function I use to fit a seasonal trend with scipy: ``` t = 365 def timeseries_function_season (x,a0,a1,a2): return a0+(a1*np.cos(2*np.pi/t*x)+a2*np.sin(2*np.pi/t*x)) timeseries_model_fit,pcov= curve_fit(timeseries_function_season,x,y) ```","{""total_count"": 0, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",,671609109 https://github.com/pydata/xarray/issues/4300#issuecomment-668264540,https://api.github.com/repos/pydata/xarray/issues/4300,668264540,MDEyOklzc3VlQ29tbWVudDY2ODI2NDU0MA==,20629530,2020-08-03T22:05:25Z,2020-08-03T22:05:25Z,CONTRIBUTOR,"My comments Q.1 : For now `xr.apply_ufunc` does not accept core dimensions to be chunked along, which would be kinda a sad for curve fitting. However, dask's least square method does, which is part of the reason why I used it in polyfit. On the other hand, scipy's least-squares procedure is not simple. Curve fitting is quite complex and rewriting all the code to use dask might be a project too ambitious, and surely out-of-scope for xarray... Q.3 : For simple directly declared function, inspect does a good job, but it can get tricky with wrapped functions, which might arise in more complex workflows. Could we have a `params` arg that takes in a list of names?","{""total_count"": 0, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",,671609109