Produce NetCDF global attributes as specified by the callbacks.
Type
Default
Details
dfs
dict
Dictionary of NetCDF group DataFrames
cbs
list
[]
Callbacks
logs
list
[]
List of preprocessing steps taken
Exported source
class GlobAttrsFeeder:"Produce NetCDF global attributes as specified by the callbacks."def__init__(self, dfs:dict, # Dictionary of NetCDF group DataFrames cbs:list=[], # Callbacks logs:list=[] # List of preprocessing steps taken ): fc.store_attr()self.attrs = {}def callback(self): run_cbs(self.cbs, self)def__call__(self):self.callback()returnself.attrs
class TimeRangeCB(Callback):"Compute time values range"def__init__(self, cfg): fc.store_attr()def__call__(self, obj): time = pd.concat(obj.dfs)['time'] start, end = [num2date(t, units=self.cfg['units']['time']).isoformat() for t in (time.min(), time.max())] obj.attrs.update({'time_coverage_start': start,'time_coverage_end': end})
# TBD: put it in callback moduleclass ZoteroCB(Callback):"Retrieve Zotero metadata."def__init__(self, itemId, cfg): fc.store_attr()def__call__(self, obj): item = ZoteroItem(self.itemId, self.cfg['zotero'])if item.exist(): for attr in ['title', 'summary', 'creator_name']: obj.attrs[attr] =getattr(item, attr)()
from marisco.configs import cfgGlobAttrsFeeder(None, cbs=[ ZoteroCB('26VMZZ2Q', cfg=cfg()) ])()
{'title': 'Environmental database - Helsinki Commission Monitoring of Radioactive Substances',
'summary': 'MORS Environment database has been used to collate data resulting from monitoring of environmental radioactivity in the Baltic Sea based on HELCOM Recommendation 26/3.\n\nThe database is structured according to HELCOM Guidelines on Monitoring of Radioactive Substances (https://www.helcom.fi/wp-content/uploads/2019/08/Guidelines-for-Monitoring-of-Radioactive-Substances.pdf), which specifies reporting format, database structure, data types and obligatory parameters used for reporting data under Recommendation 26/3.\n\nThe database is updated and quality assured annually by HELCOM MORS EG.',
'creator_name': '[{"creatorType": "author", "name": "HELCOM MORS"}]'}