Closed mmcs-work closed 7 months ago
Thanks for opening your first issue here at xarray! Be sure to follow the issue template! If you have an idea for a solution, we would really welcome a Pull Request with proposed changes. See the Contributing Guide for more. It may take us a while to respond here, but we really value your contribution. Contributors like you help make xarray better. Thank you!
What is your issue?
Is there a way to efficiently find the median around each time step, considering only dates within +/- 1 month, using xarray without resorting to for loops?
Details: (MCVE) I have a dataset consisting of 5 random time steps from January 1, 2024, to December 31, 2024. Each time step has a random date, and subsequent time steps may have dates that vary significantly. For example, if one time step is on February 15, 2024, the next ones can be on March 20, 2024, March 21, 2024, June 17, 2024, etc.
I would like to calculate the median for each time step while considering only the data within a window of +/- 1 month around each time step's date. The number of dates within this window can vary depending on the specific time step. A naive implementation using for loops is slow.
I would like to achieve the same result as shown below without using for loops, leveraging xarray's capabilities for efficient data manipulation:
Here is one example run output:
Note: Rolling was not used since the time steps are not uniform. Resampling does not sample along each point - rather it's operated on the entire series - so that also doesn't help (unless there are some points that I am missing here).