简体   繁体   中英

Add parameters to Python Intake LocalCatalogEntry

I'm trying to build a LocalCatalogEntry for Python's Intake package (as part of a larger catalog, which might have multiple entries, one of which I'm trying to create here). However, I can't seem to figure out how to feed it user parameters to describe group variable names (from within an hdf5 file) without getting an error.

from intake.catalog.local import LocalCatalogEntry
import intake_xarray

LocalCatalogEntry(name='is2_local', 
                   description= '', 
                   driver=intake_xarray.netcdf.NetCDFSource, 
                   args= {'urlpath': '/full/path/to/data/file/ATL06-20181214041627-Sample.h5', 
                            'path_as_pattern': 'ATL{product:2}-{datetime:%Y%m%d%H%M%S}-Sample.h5', 
                            'xarray_kwargs': {'engine': 'h5netcdf', 
                                              'group': '/{{laser}}/land_ice_segments'}},
                    parameters= [{'name': 'laser',
                              'description': 'Laser Beam Number', 
                              'type': 'str', 
                              'default': 'gt1l', 
                              'allowed': ['gt1l', 'gt1r', 'gt2l', 'gt2r', 'gt3l', 'gt3r']}]
)

results in an AttributeError: 'dict' object has no attribute 'describe' . I've tried all sorts of permutations and dug through the source code/docs, and can't figure out how I'm supposed to enter this information for it to be a valid input. Am I trying to input the user parameters incorrectly?

You were close! When instantiating directly like this, you need to explicitly create the UserParameter, not just pass a dict:

from intake.catalog.local import LocalCatalogEntry, UserParameter
import intake_xarray

LocalCatalogEntry(
    name='is2_local',
    description= '',
    driver=intake_xarray.netcdf.NetCDFSource,
    args= {'urlpath': '/full/path/to/data/file/ATL06-20181214041627-Sample.h5',
           'path_as_pattern': 'ATL{product:2}-{datetime:%Y%m%d%H%M%S}-Sample.h5',
           'xarray_kwargs': {'engine': 'h5netcdf',
           'group': '/{{laser}}/land_ice_segments'}},
    parameters= [UserParameter(**{
        'name': 'laser',
        'description': 'Laser Beam Number',
        'type': 'str',
        'default': 'gt1l',
        'allowed': ['gt1l', 'gt1r', 'gt2l', 'gt2r', 'gt3l', 'gt3r']})]
)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM