def __load_predictions(self):
        """private method set the predictions attribute from:
                mixed list of row names, matrix files and ndarrays
                a single row name
                an ascii file
            can be none if only interested in parameters.

        """
        if self.prediction_arg is None:
            self.__predictions = None
            return
        self.log("loading forecasts")
        if not isinstance(self.prediction_arg, list):
            self.prediction_arg = [self.prediction_arg]

        row_names = []
        vecs = []
        mat = None
        for arg in self.prediction_arg:
            if isinstance(arg, Matrix):
                # a vector
                if arg.shape[1] == 1:
                    vecs.append(arg)
                else:
                    if self.jco is not None:
                        assert arg.shape[0] == self.jco.shape[1],\
                        "linear_analysis.__load_predictions(): " +\
                        "multi-prediction matrix(npar,npred) not aligned " +\
                        "with jco(nobs,npar): " + str(arg.shape) +\
                        ' ' + str(self.jco.shape)
                        #for pred_name in arg.row_names:
                        #    vecs.append(arg.extract(row_names=pred_name).T)
                    mat = arg
            elif isinstance(arg, str):
                if arg.lower() in self.jco.row_names:
                    row_names.append(arg.lower())
                else:
                    try:
                        pred_mat = self.__fromfile(arg,astype=Matrix)
                    except Exception as e:
                        raise Exception("forecast argument: "+arg+" not found in " +\
                                        "jco row names and could not be " +\
                                        "loaded from a file.")
                    # vector
                    if pred_mat.shape[1] == 1:
                        vecs.append(pred_mat)
                    else:
                        #for pred_name in pred_mat.row_names:
                        #    vecs.append(pred_mat.get(row_names=pred_name))
                        if mat is None:
                            mat = pred_mat
                        else:
                            mat = mat.extend((pred_mat))
            elif isinstance(arg, np.ndarray):
                self.logger.warn("linear_analysis.__load_predictions(): " +
                                "instantiating prediction matrix from " +
                                "ndarray, can't verify alignment")
                self.logger.warn("linear_analysis.__load_predictions(): " +
                                 "instantiating prediction matrix from " +
                                 "ndarray, generating generic prediction names")

                pred_names = ["pred_{0}".format(i+1) for i in range(arg.shape[0])]

                if self.jco:
                    names = self.jco.col_names
                elif self.parcov:
                    names = self.parcov.col_names
                else:
                    raise Exception("linear_analysis.__load_predictions(): " +
                                    "ndarray passed for predicitons " +
                                    "requires jco or parcov to get " +
                                    "parameter names")
                if mat is None:
                    mat = Matrix(x=arg,row_names=pred_names,col_names=names).T
                else:
                    mat = mat.extend(Matrix(x=arg,row_names=pred_names,col_names=names).T)
                #for pred_name in pred_names:
                #    vecs.append(pred_matrix.get(row_names=pred_name).T)
            else:
                raise Exception("unrecognized predictions argument: " +
                                str(arg))
        # turn vecs into a pyemu.Matrix

        if len(vecs) > 0:
            xs = vecs[0].x
            for vec in vecs[1:]:
                xs = xs.extend(vec.x)
            names = [vec.col_names[0] for vec in vecs]
            if mat is None:
                mat = Matrix(x=xs,row_names=vecs[0].row_names,
                             col_names=names)
            else:
                mat = mat.extend(Matrix(x = np.array(xs),
                                        row_names=vecs[0].row_names,
                                        col_names=names))

        if len(row_names) > 0:
            extract = self.jco.extract(row_names=row_names).T
            if mat is None:
                mat = extract
            else:
                mat = mat.extend(extract)
            #for row_name in row_names:
            #    vecs.append(extract.get(row_names=row_name).T)
            # call obscov to load __obscov so that __obscov
            # (priavte) can be manipulated
            self.__obscov.drop(row_names, axis=0)
        self.__predictions = mat
        try:
            fnames = [fname for fname in self.forecast_names if fname in self.pst.nnz_obs_names]
        except:
            fnames = []
        if len(fnames) > 0:
            self.logger.warn("forecasts with non-zero weight in pst: {0}...".format(','.join(fnames)) +
                             "\n -> re-setting these forecast weights to zero...")
            self.pst.observation_data.loc[fnames,"weight"] = 0.0
        self.log("loading forecasts")
        self.logger.statement("forecast names: {0}".format(','.join(mat.col_names)))
        return self.__predictions
def __load_predictions ( self ) : if self . prediction_arg is None : self . __predictions = None return self . log ( "loading forecasts" ) if not isinstance ( self . prediction_arg , list ) : self . prediction_arg = [ self . prediction_arg ] row_names = [ ] vecs = [ ] mat = None for arg in self . prediction_arg : if isinstance ( arg , Matrix ) : if arg . shape [ 1 ] == 1 : vecs . append ( arg ) else : if self . jco is not None : assert arg . shape [ 0 ] == self . jco . shape [ 1 ] , "linear_analysis.__load_predictions(): " + "multi-prediction matrix(npar,npred) not aligned " + "with jco(nobs,npar): " + str ( arg . shape ) + ' ' + str ( self . jco . shape ) mat = arg elif isinstance ( arg , str ) : if arg . lower ( ) in self . jco . row_names : row_names . append ( arg . lower ( ) ) else : try : pred_mat = self . __fromfile ( arg , astype = Matrix ) except Exception as e : raise Exception ( "forecast argument: " + arg + " not found in " + "jco row names and could not be " + "loaded from a file." ) if pred_mat . shape [ 1 ] == 1 : vecs . append ( pred_mat ) else : if mat is None : mat = pred_mat else : mat = mat . extend ( ( pred_mat ) ) elif isinstance ( arg , np . ndarray ) : self . logger . warn ( "linear_analysis.__load_predictions(): " + "instantiating prediction matrix from " + "ndarray, can't verify alignment" ) self . logger . warn ( "linear_analysis.__load_predictions(): " + "instantiating prediction matrix from " + "ndarray, generating generic prediction names" ) pred_names = [ "pred_{0}" . format ( i + 1 ) for i in range ( arg . shape [ 0 ] ) ] if self . jco : names = self . jco . col_names elif self . parcov : names = self . parcov . col_names else : raise Exception ( "linear_analysis.__load_predictions(): " + "ndarray passed for predicitons " + "requires jco or parcov to get " + "parameter names" ) if mat is None : mat = Matrix ( x = arg , row_names = pred_names , col_names = names ) . T else : mat = mat . extend ( Matrix ( x = arg , row_names = pred_names , col_names = names ) . T ) else : raise Exception ( "unrecognized predictions argument: " + str ( arg ) ) if len ( vecs ) > 0 : xs = vecs [ 0 ] . x for vec in vecs [ 1 : ] : xs = xs . extend ( vec . x ) names = [ vec . col_names [ 0 ] for vec in vecs ] if mat is None : mat = Matrix ( x = xs , row_names = vecs [ 0 ] . row_names , col_names = names ) else : mat = mat . extend ( Matrix ( x = np . array ( xs ) , row_names = vecs [ 0 ] . row_names , col_names = names ) ) if len ( row_names ) > 0 : extract = self . jco . extract ( row_names = row_names ) . T if mat is None : mat = extract else : mat = mat . extend ( extract ) self . __obscov . drop ( row_names , axis = 0 ) self . __predictions = mat try : fnames = [ fname for fname in self . forecast_names if fname in self . pst . nnz_obs_names ] except : fnames = [ ] if len ( fnames ) > 0 : self . logger . warn ( "forecasts with non-zero weight in pst: {0}..." . format ( ',' . join ( fnames ) ) + "\n -> re-setting these forecast weights to zero..." ) self . pst . observation_data . loc [ fnames , "weight" ] = 0.0 self . log ( "loading forecasts" ) self . logger . statement ( "forecast names: {0}" . format ( ',' . join ( mat . col_names ) ) ) return self . __predictions
private method set the predictions attribute from:
                mixed list of row names, matrix files and ndarrays
                a single row name
                an ascii file
            can be none if only interested in parameters.