Linear regression for each pixel 'slice' through a DataArray

2,151 views
Skip to first unread message

Robin Wilson

unread,
Jul 13, 2016, 7:04:29 AM7/13/16
to xarray
Hi,

I've got a DataArray with three dimensions: x, y and time. I'd like to do a linear regression for the value at each (x, y) location over time - so I get a slope and intercept value for each 'pixel' of my data. To make things more interesting, each (x, y) location has missing data at some time periods.

I can't see any built-in method, and approaches using numpy seem to suggest just looping over pixels (for example, see http://stackoverflow.com/questions/34177648/python-how-to-perform-linear-regression-of-two-numpy-3d-datasets-along-axis).

What's the best way to do this using a DataArray? Would it just involve just grabbing the values and the time index from the DataArray and then looping over these? Is there a better way?

I imagine I can't be the first person who has tried to do this in xarray - any advice would be much appreciated,

Cheers,

Robin


Ryan Abernathey

unread,
Jul 13, 2016, 11:41:44 AM7/13/16
to xar...@googlegroups.com
Robin,
I think this thread covers the issue:
-Ryan

--
You received this message because you are subscribed to the Google Groups "xarray" group.
To unsubscribe from this group and stop receiving emails from it, send an email to xarray+un...@googlegroups.com.
To post to this group, send email to xar...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/xarray/4c6379b9-d88b-45d2-a06a-550c48ec250e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Robin Wilson

unread,
Jul 13, 2016, 2:36:58 PM7/13/16
to xar...@googlegroups.com
Hi Ryan,

Thanks for the link - that's perfect! (I did do some searching of the list archives first, but unfortunately my search terms didn't turn up that thread - sorry!)

Thanks,

Robin

Aleš Kuchař

unread,
Jul 15, 2016, 6:40:49 AM7/15/16
to xarray
Hi Robin,
you can check my very preliminary example how to couple xarray package with linear regression function from statsmodels package here. It may help you somehow. 

Best,
Ales

Dne středa 13. července 2016 13:04:29 UTC+2 Robin Wilson napsal(a):

Edward

unread,
Nov 7, 2016, 7:54:20 AM11/7/16
to xarray
Thank you Ales - beauty!
Reply all
Reply to author
Forward
0 new messages