コード例 #1
0
def test_old_xarray(old_xarray):
    from intake_xarray.netcdf import NetCDFSource
    source = NetCDFSource(os.path.join(here, 'data', 'example_{num: d}.nc'),
                          concat_dim='num',
                          combine='nested')
    with pytest.raises(ImportError, match='open_dataset was added in 0.11.2'):
        source.to_dask()
コード例 #2
0
def test_read_glob_pattern_of_netcdf_files():
    """If xarray is old, prompt user to update to use pattern"""
    from intake_xarray.netcdf import NetCDFSource
    source = NetCDFSource(os.path.join(here, 'data', 'example_{num: d}.nc'),
                          concat_dim='num')
    d = source.to_dask()
    assert d.dims == {'lat': 5, 'lon': 10, 'level': 4, 'time': 1, 'num': 2}
    assert (d.num.data == np.array([1, 2])).all()
コード例 #3
0
def test_read_list_of_netcdf_files_with_combine_by_coords():
    from intake_xarray.netcdf import NetCDFSource
    source = NetCDFSource(
        [
            os.path.join(here, 'data', 'example_1.nc'),
            os.path.join(here, 'data', 'next_example_1.nc'),
        ],
        combine='by_coords',
    )
    d = source.to_dask()
    assert d.dims == {'lat': 5, 'lon': 10, 'level': 4, 'time': 2}
コード例 #4
0
def test_read_list_of_netcdf_files():
    from intake_xarray.netcdf import NetCDFSource
    source = NetCDFSource([
        os.path.join(here, 'data', 'example_1.nc'),
        os.path.join(here, 'data', 'example_2.nc'),
    ])
    d = source.to_dask()
    assert d.dims == {
        'lat': 5,
        'lon': 10,
        'level': 4,
        'time': 1,
        'concat_dim': 2
    }
コード例 #5
0
def test_cached_list_netcdf():
    tempd = str(tempfile.mkdtemp())
    from intake_xarray.netcdf import NetCDFSource
    source = NetCDFSource([
        'filecache://' + os.path.join(here, 'data', 'example_1.nc'),
        'filecache://' + os.path.join(here, 'data', 'example_2.nc'),
    ],
                          storage_options={
                              'cache_storage': tempd,
                              'target_protocol': 'file'
                          })
    d = source.to_dask()
    assert d.dims == {
        'lat': 5,
        'lon': 10,
        'level': 4,
        'time': 1,
        'concat_dim': 2
    }
    assert os.listdir(tempd)