Skip to content

Instantly share code, notes, and snippets.

@kuchaale
Last active February 23, 2017 11:19
Show Gist options
  • Save kuchaale/e11da8b048461280302fd9395e323162 to your computer and use it in GitHub Desktop.
Save kuchaale/e11da8b048461280302fd9395e323162 to your computer and use it in GitHub Desktop.
My xarray utilities
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