Skip to content

Commit

Permalink
xr open mfdataset wrapper added
Browse files Browse the repository at this point in the history
  • Loading branch information
bnb32 committed Sep 17, 2024
1 parent 711c471 commit dd6250a
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion sup3r/utilities/utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import random
import string
import time
from warnings import warn

import numpy as np
import pandas as pd
Expand Down Expand Up @@ -53,7 +54,16 @@ def xr_open_mfdataset(files, **kwargs):
"""Wrapper for xr.open_mfdataset with default opening options."""
default_kwargs = {'engine': 'netcdf4'}
default_kwargs.update(kwargs)
return xr.open_mfdataset(files, **default_kwargs)
try:
return xr.open_mfdataset(files, **default_kwargs)
except Exception as e:
msg = 'Could not use xr.open_mfdataset to open %s. '
if len(files) == 1:
raise RuntimeError(msg % files) from e
msg += 'Trying to open them separately and merge. %s'
logger.warning(msg, files, e)
warn(msg % (files, e))
return merge_datasets(files, **default_kwargs)


def safe_cast(o):
Expand Down

0 comments on commit dd6250a

Please sign in to comment.