示例#1
0
文件: la.py 项目: wk1984/pyemu
    def __fromfile(self, filename):
        """a private method to deduce and load a filename into a matrix object

        Parameters:
        ----------
            filename (str) : the name of the file
        Returns:
        -------
            mat (or cov) object
        """
        assert os.path.exists(filename),"LinearAnalysis.__fromfile(): " +\
                                        "file not found:" + filename
        ext = filename.split('.')[-1].lower()
        if ext in ["jco", "jcb"]:
            self.log("loading jco: "+filename)
            m = Jco.from_binary(filename)
            self.log("loading jco: "+filename)
        elif ext in ["mat","vec"]:
            self.log("loading ascii: "+filename)
            m = Matrix.from_ascii(filename)
            self.log("loading ascii: "+filename)
        elif ext in ["cov"]:
            self.log("loading cov: "+filename)
            m = Cov.from_ascii(filename)
            self.log("loading cov: "+filename)
        elif ext in["unc"]:
            self.log("loading unc: "+filename)
            m = Cov.from_uncfile(filename)
            self.log("loading unc: "+filename)
        else:
            raise Exception("linear_analysis.__fromfile(): unrecognized" +
                            " filename extension:" + str(ext))
        return m
示例#2
0
 def __load_omitted_jco(self):
     """private: set the omitted jco attribute"""
     if self.omitted_par_arg is None:
         raise Exception("ErrVar.__load_omitted: omitted_arg is None")
     if isinstance(self.omitted_par_arg, str):
         if self.omitted_par_arg in self.jco.col_names:
             # need to access attribute directly, not view of attribute
             self.__omitted_jco = self._LinearAnalysis__jco.extract(
                 col_names=self.omitted_par_arg
             )
         else:
             # must be a filename
             self.__omitted_jco = self.__fromfile(self.omitted_par_arg)
     # if the arg is an already instantiated Matrix (or jco) object
     elif isinstance(self.omitted_par_arg, Jco) or isinstance(
         self.omitted_par_arg, Matrix
     ):
         self.__omitted_jco = Jco(
             x=self.omitted_par_arg.newx(),
             row_names=self.omitted_par_arg.row_names,
             col_names=self.omitted_par_arg.col_names,
         )
     # if it is a list, then it must be a list
     # of parameter names in self.jco
     elif isinstance(self.omitted_par_arg, list):
         for arg in self.omitted_par_arg:
             if isinstance(arg, str):
                 assert arg in self.jco.col_names, (
                     "ErrVar.__load_omitted_jco: omitted_jco "
                     + "arg str not in jco par_names: "
                     + str(arg)
                 )
         self.__omitted_jco = self._LinearAnalysis__jco.extract(
             col_names=self.omitted_par_arg
         )
示例#3
0
    def __fromfile(self, filename):
        """a private method to deduce and load a filename into a matrix object

        Parameters:
        ----------
            filename (str) : the name of the file
        Returns:
        -------
            mat (or cov) object
        """
        assert os.path.exists(filename),"LinearAnalysis.__fromfile(): " +\
                                        "file not found:" + filename
        ext = filename.split('.')[-1].lower()
        if ext in ["jco", "jcb"]:
            self.log("loading jco: " + filename)
            m = Jco.from_binary(filename)
            self.log("loading jco: " + filename)
        elif ext in ["mat", "vec"]:
            self.log("loading ascii: " + filename)
            m = Matrix.from_ascii(filename)
            self.log("loading ascii: " + filename)
        elif ext in ["cov"]:
            self.log("loading cov: " + filename)
            m = Cov.from_ascii(filename)
            self.log("loading cov: " + filename)
        elif ext in ["unc"]:
            self.log("loading unc: " + filename)
            m = Cov.from_uncfile(filename)
            self.log("loading unc: " + filename)
        else:
            raise Exception("linear_analysis.__fromfile(): unrecognized" +
                            " filename extension:" + str(ext))
        return m