예제 #1
0
import numpy as np

from xray import Variable, DataArray, Dataset, concat
import xray.ufuncs as xu
from xray.core.pycompat import suppress
from . import TestCase, requires_dask

with suppress(ImportError):
    import dask
    import dask.array as da


def _copy_at_variable_level(arg):
    """We need to copy the argument at the level of xray.Variable objects, so
    that viewing its values does not trigger lazy loading.
    """
    if isinstance(arg, Variable):
        return arg.copy(deep=False)
    elif isinstance(arg, DataArray):
        ds = arg.to_dataset(name='__copied__')
        return _copy_at_variable_level(ds)['__copied__']
    elif isinstance(arg, Dataset):
        ds = arg.copy()
        for k in list(ds):
            ds._variables[k] = ds._variables[k].copy(deep=False)
        return ds
    else:
        assert False


class DaskTestCase(TestCase):
예제 #2
0
import numpy as np

from xray import Variable, DataArray, Dataset, concat
import xray.ufuncs as xu
from xray.core.pycompat import suppress
from . import TestCase, requires_dask

with suppress(ImportError):
    import dask
    import dask.array as da


def _copy_at_variable_level(arg):
    """We need to copy the argument at the level of xray.Variable objects, so
    that viewing its values does not trigger lazy loading.
    """
    if isinstance(arg, Variable):
        return arg.copy(deep=False)
    elif isinstance(arg, DataArray):
        ds = arg.to_dataset(name='__copied__')
        return _copy_at_variable_level(ds)['__copied__']
    elif isinstance(arg, Dataset):
        ds = arg.copy()
        for k in list(ds):
            ds._variables[k] = ds._variables[k].copy(deep=False)
        return ds
    else:
        assert False


class DaskTestCase(TestCase):
예제 #3
0
 def setUp(self):
     self.testfile = 'tiny'
     self.testfilepath = os.path.expanduser(
         os.sep.join(('~', '.xray_tutorial_data', self.testfile)))
     with suppress(OSError):
         os.remove(self.testfilepath)
예제 #4
0
 def setUp(self):
     self.testfile = 'tiny'
     self.testfilepath = os.path.expanduser(os.sep.join(
         ('~', '.xray_tutorial_data', self.testfile)))
     with suppress(OSError):
         os.remove(self.testfilepath)