You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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:
needs triageIssue that has not been reviewed by xarray team member
1 participant
Converted from issue
This discussion was converted from issue #8832 on March 15, 2024 10:09.
Heading
Bold
Italic
Quote
Code
Link
Numbered list
Unordered list
Task list
Attach files
Mention
Reference
Menu
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
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:
Possible solution (inefficient?):
Feel free to suggest any other modification or improvements. (maybe cupy-xarray would be better suited for this?)
Beta Was this translation helpful? Give feedback.
All reactions