コード例 #1
0
    def _load_dictionary(self, dictionary):
        """Load data from dictionary

        Parameters
        ----------
        dict : dictionary
            A dictionary containing at least the following items:
            _id_name : string
                _id_name of the original parameter, used to create the
                dictionary. Has to match with the self._id_name
            _whitelist : dictionary
                a dictionary, which keys are used as keywords to match with the
                parameter attributes.  For more information see
                :meth:`hyperspy.misc.export_dictionary.load_from_dictionary`
            * any field from _whitelist.keys() *
        Returns
        -------
        id_value : int
            the ID value of the original parameter, to be later used for setting
            up the correct twins

        """
        if dictionary['_id_name'] == self._id_name:
            load_from_dictionary(self, dictionary)
            return dictionary['self']
        else:
            raise ValueError(
                "_id_name of parameter and dictionary do not match, \nparameter._id_name = %s\
                    \ndictionary['_id_name'] = %s" %
                (self._id_name, dictionary['_id_name']))
コード例 #2
0
ファイル: component.py プロジェクト: woozey/hyperspy
    def _load_dictionary(self, dictionary):
        """Load data from dictionary

        Parameters
        ----------
        dict : dictionary
            A dictionary containing at least the following items:
            _id_name : string
                _id_name of the original parameter, used to create the
                dictionary. Has to match with the self._id_name
            _whitelist : dictionary
                a dictionary, which keys are used as keywords to match with the
                parameter attributes.  For more information see
                :meth:`hyperspy.misc.export_dictionary.load_from_dictionary`
            * any field from _whitelist.keys() *
        Returns
        -------
        id_value : int
            the ID value of the original parameter, to be later used for setting
            up the correct twins

        """
        if dictionary['_id_name'] == self._id_name:
            load_from_dictionary(self, dictionary)
            return dictionary['self']
        else:
            raise ValueError("_id_name of parameter and dictionary do not match, \nparameter._id_name = %s\
                    \ndictionary['_id_name'] = %s" % (self._id_name, dictionary['_id_name']))
コード例 #3
0
    def _load_dictionary(self, dic):
        """
        Load data from dictionary.

        Parameters
        ----------
        dict : dict
            A dictionary containing at least the following fields:

            * _id_name: _id_name of the original parameter, used to create the
              dictionary. Has to match with the self._id_name
            * parameters: a list of dictionaries, one per parameter of the
              component (see
              :py:meth:`~hyperspy.component.Parameter.as_dictionary`
              documentation for more details)
            * _whitelist: a dictionary, which keys are used as keywords to
              match with the parameter attributes. For more information see
              :py:func:`~hyperspy.misc.export_dictionary.load_from_dictionary`
            * any field from _whitelist.keys()

        Returns
        -------
        twin_dict : dict
            Dictionary of 'id' values from input dictionary as keys with all of
            the parameters of the component, to be later used for setting up
            correct twins.
        """

        if dic['_id_name'] == self._id_name:
            if (self._id_name == "Polynomial"
                    and Version(hyperspy.__version__) >= Version("2.0")):
                # in HyperSpy 2.0 the polynomial definition changed
                from hyperspy._components.polynomial import convert_to_polynomial
                dic = convert_to_polynomial(dic)
            load_from_dictionary(self, dic)
            id_dict = {}
            for p in dic['parameters']:
                idname = p['_id_name']
                if hasattr(self, idname):
                    par = getattr(self, idname)
                    t_id = par._load_dictionary(p)
                    id_dict[t_id] = par
                else:
                    raise ValueError(
                        "_id_name of parameters in component and dictionary do not match"
                    )
            return id_dict
        else:
            raise ValueError(
                "_id_name of component and dictionary do not match, \ncomponent._id_name = %s\
                    \ndictionary['_id_name'] = %s" %
                (self._id_name, dic['_id_name']))
コード例 #4
0
ファイル: component.py プロジェクト: temcode/hyperspy
    def _load_dictionary(self, dic):
        """Load data from dictionary.

        Parameters
        ----------
        dict : dictionary
            A dictionary containing following items:
            _id_name : string
                _id_name of the original component, used to create the
                dictionary. Has to match with the self._id_name
            parameters : list
                A list of dictionaries, one per parameter of the component (see
                parameter.as_dictionary() documentation for more)
            _whitelist : dictionary
                a dictionary, which keys are used as keywords to match with the
                component attributes.  For more information see
                :meth:`hyperspy.misc.export_dictionary.load_from_dictionary`
            * any field from _whitelist.keys() *

        Returns
        -------
        twin_dict : dictionary
            Dictionary of 'id' values from input dictionary as keys with all of
            the parameters of the component, to be later used for setting up
            correct twins.

        """
        if dic['_id_name'] == self._id_name:
            id_dict = {}
            for p in dic['parameters']:
                idname = p['_id_name']
                if hasattr(self, idname):
                    par = getattr(self, idname)
                    t_id = par._load_dictionary(p)
                    id_dict[t_id] = par
                else:
                    raise ValueError(
                        "_id_name of parameters in component and dictionary do not match"
                    )
            load_from_dictionary(self, dic)
            return id_dict
        else:
            raise ValueError(
                "_id_name of component and dictionary do not match, \ncomponent._id_name = %s\
                    \ndictionary['_id_name'] = %s" %
                (self._id_name, dic['_id_name']))
コード例 #5
0
ファイル: component.py プロジェクト: jerevon/hyperspy
    def _load_dictionary(self, dic):
        """Load data from dictionary.

        Parameters
        ----------
        dict : dictionary
            A dictionary containing following items:
            _id_name : string
                _id_name of the original component, used to create the
                dictionary. Has to match with the self._id_name
            parameters : list
                A list of dictionaries, one per parameter of the component (see
                parameter.as_dictionary() documentation for more)
            _whitelist : dictionary
                a dictionary, which keys are used as keywords to match with the
                component attributes.  For more information see
                :meth:`hyperspy.misc.export_dictionary.load_from_dictionary`
            * any field from _whitelist.keys() *

        Returns
        -------
        twin_dict : dictionary
            Dictionary of 'id' values from input dictionary as keys with all of
            the parameters of the component, to be later used for setting up
            correct twins.

        """
        if dic['_id_name'] == self._id_name:
            id_dict = {}
            for p in dic['parameters']:
                idname = p['_id_name']
                if hasattr(self, idname):
                    par = getattr(self, idname)
                    t_id = par._load_dictionary(p)
                    id_dict[t_id] = par
                else:
                    raise ValueError(
                        "_id_name of parameters in component and dictionary do not match")
            load_from_dictionary(self, dic)
            return id_dict
        else:
            raise ValueError( "_id_name of component and dictionary do not match, \ncomponent._id_name = %s\
                    \ndictionary['_id_name'] = %s" % (self._id_name, dic['_id_name']))
コード例 #6
0
ファイル: hartree_slater_gos.py プロジェクト: bm424/hyperspy
 def _load_dictionary(self, dictionary):
     load_from_dictionary(self, dictionary)
     self.energy_axis = self.rel_energy_axis + self.onset_energy