Commit 9c9dadfe authored by PIOLLE's avatar PIOLLE
Browse files

added feature object instanciation

parent 6b74f390
# intake-xarray
[![Build Status](https://travis-ci.org/intake/intake-xarray.svg?branch=master)](https://travis-ci.org/intake/intake-xarray)
Intake-xarray: xarray Plugin for [Intake](https://github.com/intake/intake)
See [Intake docs](https://intake.readthedocs.io/en/latest/overview.html) for a general introduction and usage
of Intake and the [intake-xarray docs](https://intake-xarray.readthedocs.io/) for details specific to the
data drivers included in this package.
In `intake-cerbere`, there are plugins provided for reading data into [cerbere](http://gitlab.ifremer.fr/cerbere/cerbere.git)
containers:
- cerbere
and it provides the ability to read xarray data from an Intake server.
### Installation
The conda install instructions are:
```
conda install -c conda-forge intake-cerbere
```
To install optional dependencies:
```
conda install -c conda-forge pydap rasterio
```
plugins:
source:
- module: intake_cerbere
sources:
esgf:
description: CREATE sample
driver: cdataset
#cache:
# - argkey: urlpath
# regex: ''
# type: file
args:
urlpath: '/home/jfpiolle/git/cerbere/tests/data/GHRSSTNCDataset/20190719000110-MAR-L2P_GHRSST-SSTskin-SLSTRA-20190719021531-v02.0-fv01.0.nc'
chunks: {}
plugin: NCDataset
cerbere_kwargs:
slstr:
description: SLSTR sample
driver: cfeature
#cache:
# - argkey: urlpath
# regex: ''
# type: file
args:
urlpath: '/home/jfpiolle/git/cerbere/tests/data/GHRSSTNCDataset/20190719000110-MAR-L2P_GHRSST-SSTskin-SLSTRA-20190719021531-v02.0-fv01.0.nc'
chunks: {}
feature: Swath
plugin: GHRSSTNCDataset
cerbere_kwargs:
from ._version import get_versions
__version__ = get_versions()['version']
del get_versions
import intake # Import this first to avoid circular imports during discovery.
from intake.container import register_container
from .cdataset import CDatasetSource
"from .feature import CFeatureSource
from .cfeature import CFeatureSource
intake.register_driver('cerbere-dataset', CDatasetSource)
intake.register_driver('cerbere-feature', CFeatureSource)
intake.register_driver('cerbere', CDatasetSource)
register_container('cerbere-dataset', CDatasetSource)
from ._version import get_versions
__version__ = get_versions()['version']
del get_versions
from . import __version__
from intake.source.base import DataSource, Schema
import fsspec
from distutils.version import LooseVersion
from intake.source.utils import reverse_format
class CDataset(DataSource):
class CDatasetSource(DataSource):
"""Cerbere Dataset """
version = __version__
container = 'cerbere-dataset'
partition_access = True
name = 'netcdf'
name = 'cdataset'
def __init__(self, urlpath, chunks=None, plugin='Dataset',
cerbere_kwargs=None, metadata=None,
......@@ -22,7 +21,7 @@ class CDataset(DataSource):
self.storage_options = storage_options or {}
self.cerbere_kwargs = cerbere_kwargs or {}
self._ds = None
super(DataSource, self).__init__(metadata=metadata, **kwargs)
super(CDatasetSource, self).__init__(metadata=metadata, **kwargs)
def _open_dataset(self):
import cerbere
......@@ -47,9 +46,9 @@ class CDataset(DataSource):
metadata = {
'dims': dict(self._ds.dims),
'data_vars': {k: list(self._ds[k].coords)
for k in self._ds.data_vars.keys()},
'coords': tuple(self._ds.coords.keys()),
'data_vars': {k: list(self._ds.get_field_sizes(k))
for k in self._ds.fieldnames},
'coords': tuple(self._ds.coords),
}
#if getattr(self, 'on_server', False):
# metadata['internal'] = serialize_zarr_ds(self._ds)
......
import fsspec
from . import __version__
from .cdataset import CDatasetSource
class CFeatureSource(CDatasetSource):
"""Cerbere Dataset """
version = __version__
container = 'cerbere-feature'
partition_access = True
name = 'cfeature'
def __init__(self, urlpath, feature, **kwargs):
self.feature = feature
super(CFeatureSource, self).__init__(urlpath, **kwargs)
def _open_dataset(self):
import cerbere
url = self.urlpath
kwargs = self.cerbere_kwargs
_open_as_feature = cerbere.open_as_feature
url = fsspec.open_local(url, **self.storage_options)
self._ds = _open_as_feature(
self.feature, url, plugin=self.plugin, chunks=self.chunks, **kwargs
)
......@@ -24,7 +24,8 @@ setup(
packages=find_packages(),
entry_points={
'intake.drivers': [
'cerbere = intake_cerbere.cdataset:CDataset',
'cdataset = intake_cerbere.cdataset:CDatasetSource',
'cfeature = intake_cerbere.cfeature:CFeatureSource',
]
},
package_data={'': ['*.csv', '*.yml', '*.html']},
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment