[docs]defproject_to_dict(project,categorize_by=['name'],flatten=False,element=None,delim=' | '):r""" Returns a single dictionary object containing data from the given OpenPNM project, with the keys organized differently depending on optional arguments. Parameters ---------- project : list An OpenPNM project object categorize_by : str or list[str] Indicates how the dictionaries should be organized. The list can contain any, all or none of the following strings: **'object'** : If specified the dictionary keys will be stored under a general level corresponding to their type (e.g. 'network/net_01/pore.all'). **'name'** : If specified, then the data arrays are additionally categorized by their name. This is enabled by default. **'data'** : If specified the data arrays are additionally categorized by ``label`` and ``property`` to separate *boolean* from *numeric* data. **'element'** : If specified the data arrays are additionally categorized by ``pore`` and ``throat``, meaning that the propnames are no longer prepended by a 'pore.' or 'throat.' Returns ------- A dictionary with the data stored in a hierarchical data structure, the actual format of which depends on the arguments to the function. """network=project.networkphases=project.phasesalgs=project.algorithmsifflatten:d={}else:d=NestedDict(delimiter=delim)defbuild_path(obj,key):propname=keyname=''prefix=''datatype=''arr=obj[key]if'object'incategorize_by:ifhasattr(obj,'coords'):prefix='network'+delimelse:prefix='phase'+delimif'element'incategorize_by:propname=key.replace('.',delim)if'data'incategorize_by:ifarr.dtype==bool:datatype='labels'+delimelse:datatype='properties'+delimif'name'incategorize_by:name=obj.name+delimpath=prefix+name+datatype+propnamereturnpathforkeyinnetwork.props(element=element)+network.labels(element=element):path=build_path(obj=network,key=key)d[path]=network[key]forphaseinphases:forkeyinphase.props(element=element)+phase.labels(element=element):path=build_path(obj=phase,key=key)d[path]=phase[key]foralginalgs:try:# 'quantity' is missing for multiphysics algorithmkey=alg.settings['quantity']exceptAttributeError:break# only for transient algstransient=is_transient(alg)path=build_path(alg,key)iftransient:times=alg.soln[key].tfori,tinenumerate(times):d[path+'#'+nbr_to_str(t)]=alg.soln[key][:,i]else:d[path]=alg.soln[key]returnd