write a stand alone observation summary latex table


                Parameters
                ----------
                filename : str
                    latex filename. If None, use <case>.par.tex. Default is None
                group_names: dict
                    par group names : table names for example {"w0":"well stress period 1"}.
                    Default is None

                Returns
                -------
                None

def write_obs_summary_table(self,filename=None,group_names=None):
        """write a stand alone observation summary latex table


                Parameters
                ----------
                filename : str
                    latex filename. If None, use <case>.par.tex. Default is None
                group_names: dict
                    par group names : table names for example {"w0":"well stress period 1"}.
                    Default is None

                Returns
                -------
                None
                """

        ffmt = lambda x: "{0:5G}".format(x)
        obs = self.observation_data.copy()
        obsgp = obs.groupby(obs.obgnme).groups
        cols = ["obgnme","obsval","nzcount","zcount","weight","stdev","pe"]

        labels = {"obgnme":"group","obsval":"value","nzcount":"non-zero weight",
                  "zcount":"zero weight","weight":"weight","stdev":"standard deviation",
                  "pe":"percent error"}

        obs.loc[:,"stdev"] = 1.0 / obs.weight
        obs.loc[:,"pe"] = 100.0 * (obs.stdev / obs.obsval.apply(np.abs))
        obs = obs.replace([np.inf,-np.inf],np.NaN)

        data = {c: [] for c in cols}
        for og, onames in obsgp.items():
            obs_g = obs.loc[onames, :]
            data["obgnme"].append(og)
            data["nzcount"].append(obs_g.loc[obs_g.weight > 0.0,:].shape[0])
            data["zcount"].append(obs_g.loc[obs_g.weight == 0.0,:].shape[0])
            for col in cols:
                if col in ["obgnme","nzcount","zcount"]:
                    continue

                #print(col)
                mn = obs_g.loc[:, col].min()
                mx = obs_g.loc[:, col].max()
                if np.isnan(mn) or np.isnan(mx):
                    data[col].append("NA")
                elif mn == mx:
                    data[col].append(ffmt(mn))
                else:
                    data[col].append("{0} to {1}".format(ffmt(mn), ffmt(mx)))


        obsg_df = pd.DataFrame(data=data, index=list(obsgp.keys()))
        obsg_df = obsg_df.loc[:, cols]
        if group_names is not None:
            obsg_df.loc[:, "obgnme"] = obsg_df.obgnme.apply(lambda x: group_names.pop(x, x))
        obsg_df.sort_values(by="obgnme",inplace=True,ascending=True)
        obsg_df.columns = obsg_df.columns.map(lambda x: labels[x])

        preamble = '\\documentclass{article}\n\\usepackage{booktabs}\n' + \
                   '\\usepackage{pdflscape}\n\\usepackage{longtable}\n' + \
                   '\\usepackage{booktabs}\n\\usepackage{nopageno}\n\\begin{document}\n'


        if filename == "none":
            return obsg_df

        if filename is None:
            filename = self.filename.replace(".pst", ".obs.tex")

        with open(filename, 'w') as f:

            f.write(preamble)

            f.write("\\begin{center}\nObservation Summary\n\\end{center}\n")
            f.write("\\begin{center}\n\\begin{landscape}\n")
            f.write("\\setlength{\\LTleft}{-4.0cm}\n")
            obsg_df.to_latex(f, index=False, longtable=True)
            f.write("\\end{landscape}\n")
            f.write("\\end{center}\n")
            f.write("\\end{document}\n")

        return obsg_df