def _apply_config(self, new_config: dict):
        """This method applies a config dictionary to the current config,
           overwriting values and adding new entries (if present).

        Arguments:
            config {dict} -- A dictionary of client configuration details
        """
        # Update current configuration with new configuration
        # Flatten both dictionaries to account for nested dictionary values
        flat_current_client = FlatDict(self._config['client'], delimiter='_')
        flat_current_testing = FlatDict(self._config['testing'], delimiter='_')

        flat_new_client = FlatDict(new_config.get('client', {}), delimiter='_')
        flat_new_testing = FlatDict(
            new_config.get('testing', {}), delimiter='_')
        flat_current_client.update(flat_new_client)
        flat_current_testing.update(flat_new_testing)
        # Update values in current config and unflatten
        self._config = {'client': flat_current_client.as_dict(),
                        'testing': flat_current_testing.as_dict()}
Esempio n. 2
0
    def to_dataframe(cls, network=None, phases=[], join=False, delim=' | '):
        r"""
        Convert the Network (and optionally Phase) data to Pandas DataFrames.

        Parameters
        ----------
        network: OpenPNM Network Object
            The network containing the data to be stored

        phases : list of OpenPNM Phase Objects
            The data on each supplied phase will be added to DataFrame

        join : boolean
            If ``False`` (default), two DataFrames are returned with *pore*
            data in one, and *throat* data in the other.  If ``True`` the pore
            and throat data are combined into a single DataFrame.  This can be
            problematic as it will put NaNs into all the *pore* columns which
            are shorter than the *throat* columns.

        Returns
        -------
        Pandas ``DataFrame`` object containing property and label data in each
        column.  If ``join`` was False (default) the two DataFrames are
        returned i a named tuple, or else a single DataFrame with pore and
        throat data in the same file, despite the column length being
        different.

        """
        project, network, phases = cls._parse_args(network=network,
                                                   phases=phases)

        # Initialize pore and throat data dictionary using Dict class
        pdata = Dict.to_dict(network=network,
                             phases=phases,
                             element='pore',
                             interleave=True,
                             flatten=True,
                             categorize_by=['object'])
        tdata = Dict.to_dict(network=network,
                             phases=phases,
                             element='throat',
                             interleave=True,
                             flatten=True,
                             categorize_by=['object'])
        pdata = FlatDict(pdata, delimiter=delim)
        tdata = FlatDict(tdata, delimiter=delim)

        # Scan data and convert non-1d arrays to multiple columns
        for key in list(pdata.keys()):
            if sp.shape(pdata[key]) != (network[0].Np, ):
                arr = pdata.pop(key)
                tmp = sp.split(arr, arr.shape[1], axis=1)
                cols = range(len(tmp))
                pdata.update(
                    {key + '[' + str(i) + ']': tmp[i].squeeze()
                     for i in cols})
        for key in list(tdata.keys()):
            if sp.shape(tdata[key]) != (network[0].Nt, ):
                arr = tdata.pop(key)
                tmp = sp.split(arr, arr.shape[1], axis=1)
                cols = range(len(tmp))
                tdata.update(
                    {key + '[' + str(i) + ']': tmp[i].squeeze()
                     for i in cols})

        # Convert sanitized dictionaries to DataFrames
        pdata = pd.DataFrame(sanitize_dict(pdata))
        tdata = pd.DataFrame(sanitize_dict(tdata))

        # Prepare DataFrames to be returned
        if join:
            data = tdata.join(other=pdata, how='left')
        else:
            nt = namedtuple('dataframes', ('pore', 'throat'))
            data = nt(pore=pdata, throat=tdata)

        return data