Last active
February 23, 2017 11:19
-
-
Save kuchaale/e11da8b048461280302fd9395e323162 to your computer and use it in GitHub Desktop.
My xarray utilities
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def longest_com_period_possible(xa_list): | |
"""Determine the longest common period for list of xarrays | |
Parameters | |
---------- | |
xa_list: list of xarray dataarrays | |
Returns | |
------- | |
period: slice | |
The longest common period for list of xarrays in slice form intended for .sel in xarray | |
""" | |
min_ls = [] | |
max_ls = [] | |
for xa in xa_list: | |
min_ls.append(np.min(xa.time.to_index().year)) | |
max_ls.append(np.max(xa.time.to_index().year)) | |
period = slice(str(np.max(min_ls)), str(np.min(max_ls))) | |
return period |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment