[docs]classTHREDDSMergedSource:"""Merges multiple datasets into a single datasets. This source takes a THREDDS URL and a path to descend down, and calls the combine function on all of the datasets found. Parameters ---------- url : str Location of server path : str, list of str Subcats to follow; include glob characters (*, ?) in here for matching. driver : str Select driver to access data. Choose from 'netcdf' and 'opendap'. xarray_kwargs: dict kwargs to be passed to xr.open_dataset concat_kwargs: dict kwargs to be passed to xr.concat() filled by files opened by xr.open_dataset previously metadata : dict or None To associate with this source. Examples -------- >>> import intake >>> cat_url = 'https://psl.noaa.gov/thredds/catalog.xml' >>> paths = ['Datasets', 'ncep.reanalysis.dailyavgs', 'surface', 'air.sig995.194*.nc'] >>> src = intake.open_thredds_merged(cat_url, paths) >>> src sources: thredds_merged: args: path: - Datasets - ncep.reanalysis.dailyavgs - surface - air*sig995*194*.nc url: https://psl.noaa.gov/thredds/catalog.xml description: '' driver: intake_thredds.source.THREDDSMergedSource metadata: {} """def__init__(self,url,path,driver='opendap',xarray_kwargs=None,concat_kwargs=None,metadata=None,):xarray_kwargs=xarray_kwargsor{}self.metadata=metadataor{}self.urlpath=urlif'simplecache::'inurl:self.metadata.update({'fsspec_pre_url':'simplecache::'})ifisinstance(path,str):path=[path]ifnotisinstance(path,list):raiseValueError(f'path must be list of str, found {type(path)}')ifnotall(isinstance(item,str)foriteminpath):raiseValueError('path must be list of str')self.path=pathself.driver=driverself.xarray_kwargs=xarray_kwargsself.concat_kwargs=concat_kwargsdefread(self,xarray_kwargs=None):importxarrayasxrfromtqdmimporttqdmcat=ThreddsCatalog(self.urlpath,driver=self.driver,metadata=self.metadata)foriinrange(len(self.path)):part=self.path[i]if'*'notinpartand'?'notinpart:cat=cat[part].read(make=self.driver[-3:])else:breakpath=self.path[i:]data=[ds(**self.xarray_kwargs).read()fordsintqdm(_match(cat,path),desc='Dataset(s)',ncols=79)]ifself.concat_kwargs:returnxr.concat(data,**self.concat_kwargs)else:returnxr.combine_by_coords(data,combine_attrs='override')to_dask=read