示例#1
0
    def _write_basic_table(tablestring, filename):
        csv = os.path.join('output', 'csv', filename + '.csv')
        tex = os.path.join('output', 'tex', 'ISR', filename + '.tex')
        utils.makeTablesFromCSVStrings(tablestring, csvpath=csv)
        utils.csvToTex(csv, tex, pcols=0)
        with open(tex, 'r') as texfile:
            texstring = texfile.read()

        texstring = texstring.replace(r"\toprule", r"\midrule")
        texstring = texstring.replace(r"\bottomrule", r"\midrule")
        texstring = utils.sanitizeTex(texstring).replace(" nan ", " -- ")
        with open(tex, 'w') as texfile:
            texfile.write(texstring)
示例#2
0
    def wq_table(self, writeToFiles=True):
        """ Assembles a summary tables of WQ concentrations and loads

        Parameters
        ----------
        writeToFiles : bool, optional
            Determines if .csv and .tex representations of the output
            will be written.

        Writes
        ------
        Optionally writes .csv and .tex files of the table.

        Returns
        -------
        wqtable : pandas.DataFrame
            A concise DataFrame with water quality concetrations and loads.

        """

        if self.wqdata is not None:
            wqtable = (
                self.wqdata
                    .query("parameter != 'Escherichia coli'")
                    .merge(self.wqstd, on='parameter', suffixes=('', '_y'))
                    .rename(columns={'parameter': 'Parameter'})
            )

            wqtable['Effluent EMC'] = wqtable.apply(
                lambda r: self._res_with_units(r['concentration'], r['units']),
                axis=1
            )

            wqtable['Detection Limit'] = wqtable.apply(
                lambda r: self._res_with_units(r['detectionlimit'], r['units']),
                axis=1
            )

            wqtable['Effluent Load'] = wqtable.apply(
                lambda r: self._res_with_units(r['load_outflow'], r['load_units']),
                axis=1
            )

            wqtable['WQ Guideline'] = wqtable.apply(
                lambda r: self._res_with_units(r['upper_limit'], r['units']),
                axis=1
            )

            #wqtable = wqtable.rename(columns=lambda c: c.replace('_', ' ').title())
            cols_to_keep = [
                'Parameter',
                'WQ Guideline',
                'Detection Limit',
                'Effluent EMC',
                'Effluent Load'
            ]
            wqtable = wqtable[cols_to_keep].drop_duplicates()

            if writeToFiles:  # pragma: no cover
                csvpath = os.path.join('output', 'csv', self.wq_tex_table + '.csv')
                texpath = os.path.join('output', 'tex', 'ISR', self.wq_tex_table + '.tex')

                wqtable.to_csv(csvpath, na_rep='--', index=False)
                utils.csvToTex(csvpath, texpath, pcols=25, replacestats=False)

            return wqtable