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

added feature object instanciation

parent 6b74f390
# intake-xarray
[![Build Status](](
Intake-xarray: xarray Plugin for [Intake](
See [Intake docs]( for a general introduction and usage
of Intake and the [intake-xarray docs]( for details specific to the
data drivers included in this package.
In `intake-cerbere`, there are plugins provided for reading data into [cerbere](
- 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
- module: intake_cerbere
description: CREATE sample
driver: cdataset
# - argkey: urlpath
# regex: ''
# type: file
urlpath: '/home/jfpiolle/git/cerbere/tests/data/GHRSSTNCDataset/'
chunks: {}
plugin: NCDataset
description: SLSTR sample
driver: cfeature
# - argkey: urlpath
# regex: ''
# type: file
urlpath: '/home/jfpiolle/git/cerbere/tests/data/GHRSSTNCDataset/'
chunks: {}
feature: Swath
plugin: GHRSSTNCDataset
from ._version import get_versions
__version__ = get_versions()['version']
del get_versions
import intake # Import this first to avoid circular imports during discovery. import intake # Import this first to avoid circular imports during discovery.
from intake.container import register_container from intake.container import register_container
from .cdataset import CDatasetSource 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) 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 from intake.source.base import DataSource, Schema
import fsspec import fsspec
from distutils.version import LooseVersion
from intake.source.utils import reverse_format
class CDataset(DataSource): class CDatasetSource(DataSource):
"""Cerbere Dataset """ """Cerbere Dataset """
version = __version__ version = __version__
container = 'cerbere-dataset' container = 'cerbere-dataset'
partition_access = True partition_access = True
name = 'netcdf' name = 'cdataset'
def __init__(self, urlpath, chunks=None, plugin='Dataset', def __init__(self, urlpath, chunks=None, plugin='Dataset',
cerbere_kwargs=None, metadata=None, cerbere_kwargs=None, metadata=None,
...@@ -22,7 +21,7 @@ class CDataset(DataSource): ...@@ -22,7 +21,7 @@ class CDataset(DataSource):
self.storage_options = storage_options or {} self.storage_options = storage_options or {}
self.cerbere_kwargs = cerbere_kwargs or {} self.cerbere_kwargs = cerbere_kwargs or {}
self._ds = None self._ds = None
super(DataSource, self).__init__(metadata=metadata, **kwargs) super(CDatasetSource, self).__init__(metadata=metadata, **kwargs)
def _open_dataset(self): def _open_dataset(self):
import cerbere import cerbere
...@@ -47,9 +46,9 @@ class CDataset(DataSource): ...@@ -47,9 +46,9 @@ class CDataset(DataSource):
metadata = { metadata = {
'dims': dict(self._ds.dims), 'dims': dict(self._ds.dims),
'data_vars': {k: list(self._ds[k].coords) 'data_vars': {k: list(self._ds.get_field_sizes(k))
for k in self._ds.data_vars.keys()}, for k in self._ds.fieldnames},
'coords': tuple(self._ds.coords.keys()), 'coords': tuple(self._ds.coords),
} }
#if getattr(self, 'on_server', False): #if getattr(self, 'on_server', False):
# metadata['internal'] = serialize_zarr_ds(self._ds) # 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( ...@@ -24,7 +24,8 @@ setup(
packages=find_packages(), packages=find_packages(),
entry_points={ entry_points={
'intake.drivers': [ 'intake.drivers': [
'cerbere = intake_cerbere.cdataset:CDataset', 'cdataset = intake_cerbere.cdataset:CDatasetSource',
'cfeature = intake_cerbere.cfeature:CFeatureSource',
] ]
}, },
package_data={'': ['*.csv', '*.yml', '*.html']}, 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