Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(latex): support path-like, add docstrings #142

Merged
merged 3 commits into from
Feb 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,11 @@ jobs:

- name: Install executables
uses: modflowpy/install-modflow-action@v1

- name: Install nightly build
uses: modflowpy/install-modflow-action@v1
with:
repo: modflow6-nightly-build

- name: Setup GNU Fortran ${{ env.GCC_V }}
uses: awvwgk/setup-fortran@main
Expand All @@ -137,7 +142,7 @@ jobs:
run: |
pip install .
pip install ".[test]"

- name: Cache modflow6 examples
id: cache-examples
uses: actions/cache@v3
Expand All @@ -152,6 +157,9 @@ jobs:
pip install -r requirements.pip.txt
pip install -r requirements.usgs.txt

- name: Update FloPy packages
run: python -m flopy.mf6.utils.generate_classes --ref develop --no-backup

- name: Build modflow6 example models
if: steps.cache-examples.outputs.cache-hit != 'true'
working-directory: modflow6-examples/autotest
Expand Down
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

project = "modflow-devtools"
author = "MODFLOW Team"
release = '1.5.0.dev0'
release = "1.5.0.dev0"

# -- General configuration ---------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration
Expand Down
62 changes: 55 additions & 7 deletions modflow_devtools/latex.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,38 @@
import os
from os import PathLike
from pathlib import Path
from typing import Iterable, Union


def build_table(caption, fpth, arr, headings=None, col_widths=None):
def build_table(
caption: str,
fpth: Union[str, PathLike],
arr,
headings: Iterable[str] = None,
col_widths: Iterable[float] = None,
):
"""
Build a LaTeX table from the given NumPy array.

Parameters
----------
caption : str
The table's caption
fpth : str or path-like
The LaTeX file to create
arr : numpy recarray
The array
headings : iterable of str
The table headings
col_widths : iterable of float
The table's column widths
"""

fpth = Path(fpth).expanduser().absolute().with_suffix(".tex")

if headings is None:
headings = arr.dtype.names
ncols = len(arr.dtype.names)
if not fpth.endswith(".tex"):
fpth += ".tex"
label = "tab:{}".format(os.path.basename(fpth).replace(".tex", ""))
label = "tab:{}".format(fpth.stem)

line = get_header(caption, label, headings, col_widths=col_widths)

Expand All @@ -29,8 +54,32 @@ def build_table(caption, fpth, arr, headings=None, col_widths=None):


def get_header(
caption, label, headings, col_widths=None, center=True, firsthead=False
caption: str,
label: str,
headings: Iterable[str],
col_widths: Iterable[float] = None,
center: bool = True,
firsthead: bool = False,
):
"""
Build a LaTeX table header.

Parameters
----------
caption : str
The table's caption
label : str
The table's label
headings : iterable of str
The table's heading
col_widths : iterable of float
The table's column widths
center : bool
Whether to center-align the table text
firsthead : bool
Whether to add first header
"""

ncol = len(headings)
if col_widths is None:
dx = 0.8 / float(ncol)
Expand Down Expand Up @@ -85,7 +134,6 @@ def exp_format(v):
s = f"{v:.2e}"
s = s.replace("e-0", "e-")
s = s.replace("e+0", "e+")
# s = s.replace("e", " \\times 10^{") + "}$"
return s


Expand Down
Loading