pubfigure 1.0.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- pubfigure-1.0.0/LICENSE +21 -0
- pubfigure-1.0.0/PKG-INFO +121 -0
- pubfigure-1.0.0/README.md +65 -0
- pubfigure-1.0.0/pyproject.toml +61 -0
- pubfigure-1.0.0/setup.cfg +4 -0
- pubfigure-1.0.0/src/pubfigure/__init__.py +38 -0
- pubfigure-1.0.0/src/pubfigure/cli.py +139 -0
- pubfigure-1.0.0/src/pubfigure/fitting.py +416 -0
- pubfigure-1.0.0/src/pubfigure/plotting.py +409 -0
- pubfigure-1.0.0/src/pubfigure/presets.py +119 -0
- pubfigure-1.0.0/src/pubfigure/stats.py +469 -0
- pubfigure-1.0.0/src/pubfigure.egg-info/PKG-INFO +121 -0
- pubfigure-1.0.0/src/pubfigure.egg-info/SOURCES.txt +16 -0
- pubfigure-1.0.0/src/pubfigure.egg-info/dependency_links.txt +1 -0
- pubfigure-1.0.0/src/pubfigure.egg-info/entry_points.txt +2 -0
- pubfigure-1.0.0/src/pubfigure.egg-info/requires.txt +10 -0
- pubfigure-1.0.0/src/pubfigure.egg-info/top_level.txt +1 -0
- pubfigure-1.0.0/tests/test_pubfigure.py +106 -0
pubfigure-1.0.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 YFind Digital Studio (youxunzhangjim-netizen)
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
pubfigure-1.0.0/PKG-INFO
ADDED
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
Metadata-Version: 2.2
|
|
2
|
+
Name: pubfigure
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: 42 journal-compliant scientific figure presets (Nature/Science/Cell to Elsevier/Springer/AIP/IOP/ASME/APA 7th/MDPI/Thesis), weighted nonlinear curve fitting, error propagation, and auto-stacked hypothesis brackets for Matplotlib.
|
|
5
|
+
Author-email: YFind Digital Studio <youxunzhangjim@gmail.com>
|
|
6
|
+
License: MIT License
|
|
7
|
+
|
|
8
|
+
Copyright (c) 2026 YFind Digital Studio (youxunzhangjim-netizen)
|
|
9
|
+
|
|
10
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
11
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
12
|
+
in the Software without restriction, including without limitation the rights
|
|
13
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
14
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
15
|
+
furnished to do so, subject to the following conditions:
|
|
16
|
+
|
|
17
|
+
The above copyright notice and this permission notice shall be included in all
|
|
18
|
+
copies or substantial portions of the Software.
|
|
19
|
+
|
|
20
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
21
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
22
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
23
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
24
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
25
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
26
|
+
SOFTWARE.
|
|
27
|
+
|
|
28
|
+
Project-URL: Homepage, https://pubfigure.youxunzhangjim.workers.dev/
|
|
29
|
+
Project-URL: Repository, https://github.com/youxunzhangjim-netizen/PubFigure
|
|
30
|
+
Project-URL: Issues, https://github.com/youxunzhangjim-netizen/PubFigure/issues
|
|
31
|
+
Project-URL: Documentation, https://github.com/youxunzhangjim-netizen/PubFigure/tree/main/python
|
|
32
|
+
Keywords: scientific-plotting,matplotlib,publication-figures,curve-fitting,levenberg-marquardt,biostatistics,error-propagation,nature,ieee,aps
|
|
33
|
+
Classifier: Development Status :: 4 - Beta
|
|
34
|
+
Classifier: Intended Audience :: Science/Research
|
|
35
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
36
|
+
Classifier: Operating System :: OS Independent
|
|
37
|
+
Classifier: Programming Language :: Python :: 3
|
|
38
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
39
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
40
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
41
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
42
|
+
Classifier: Topic :: Scientific/Engineering :: Visualization
|
|
43
|
+
Classifier: Topic :: Scientific/Engineering :: Bio-Informatics
|
|
44
|
+
Classifier: Topic :: Scientific/Engineering :: Physics
|
|
45
|
+
Requires-Python: >=3.10
|
|
46
|
+
Description-Content-Type: text/markdown
|
|
47
|
+
License-File: LICENSE
|
|
48
|
+
Requires-Dist: numpy>=1.24
|
|
49
|
+
Requires-Dist: matplotlib>=3.7
|
|
50
|
+
Provides-Extra: scipy
|
|
51
|
+
Requires-Dist: scipy>=1.10; extra == "scipy"
|
|
52
|
+
Provides-Extra: dev
|
|
53
|
+
Requires-Dist: pytest>=7.4; extra == "dev"
|
|
54
|
+
Requires-Dist: build>=1.2; extra == "dev"
|
|
55
|
+
Requires-Dist: twine>=5.0; extra == "dev"
|
|
56
|
+
|
|
57
|
+
# `pubfigure` — Python SDK & CLI for Publication-Ready Scientific Figures
|
|
58
|
+
|
|
59
|
+
`pubfigure` wraps `matplotlib` + `numpy` with **42 international publication specifications** — spanning flagship journals (*Nature*, *Science*, *Cell*, *NEJM/Lancet*, *JAMA/BMJ*, *APS PRL*, *IEEE*, *NeurIPS*, *AER*), mainstream Q1–Q3 society/publisher journals (*Elsevier 90/140 mm*, *Springer*, *AIP APL/JAP*, *IOP*, *Optica*, *ACS AMI/ES&T*, *ASME*, *ASCE*, *APA 7th*, *SAGE*, *Taylor & Francis*, *Oxford OUP*, *Wiley*), open-access workhorses (*Scientific Reports/BMC*, *MDPI*, *Frontiers*, *PLOS ONE/eLife*, *IEEE Access*), and **A4 MS/PhD Theses & Conference Posters** — plus **weighted Levenberg–Marquardt curve fitting** (10 presets + custom formula `f(x)` with zero `eval()`), **Gaussian error propagation**, and **auto-stacked non-overlapping significance brackets**.
|
|
60
|
+
|
|
61
|
+
## Install
|
|
62
|
+
|
|
63
|
+
```bash
|
|
64
|
+
pip install pubfigure
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
Or install editable from a local checkout:
|
|
68
|
+
|
|
69
|
+
```bash
|
|
70
|
+
cd python
|
|
71
|
+
pip install -e .
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
## 5-Line Python Quickstart
|
|
75
|
+
|
|
76
|
+
```python
|
|
77
|
+
import pubfigure as pf
|
|
78
|
+
|
|
79
|
+
fig = pf.Figure(journal="nature-single", palette="npg-nature")
|
|
80
|
+
fit = fig[0].fit(
|
|
81
|
+
x=[0.01, 0.03, 0.1, 0.3, 1.0, 3.0, 10.0, 30.0],
|
|
82
|
+
y=[99.2, 97.5, 91.8, 76.4, 49.8, 25.6, 12.4, 8.1],
|
|
83
|
+
yerr=[2.1, 2.4, 2.8, 3.2, 3.0, 2.5, 1.9, 1.6],
|
|
84
|
+
preset="hill_4pl",
|
|
85
|
+
log_x=True,
|
|
86
|
+
label="Kinase Inhibitor",
|
|
87
|
+
)
|
|
88
|
+
fig[0].set_labels(title="Dose-Response Curve", xlabel="Conc. (µM)", ylabel="Viability (%)")
|
|
89
|
+
fig.save("fig1_nature_89mm.pdf")
|
|
90
|
+
fig.save_workspace("fig1_workspace.json") # Opens directly in PubFigure Web UI!
|
|
91
|
+
print(fit.methods_sentence)
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
## Grouped BioStats + Non-Overlapping Brackets (`*`, `**`, `***`)
|
|
95
|
+
|
|
96
|
+
```python
|
|
97
|
+
import pubfigure as pf
|
|
98
|
+
|
|
99
|
+
fig = pf.Figure(journal="cell-single", palette="okabe-ito")
|
|
100
|
+
report = fig[0].grouped_bar_jitter(
|
|
101
|
+
{
|
|
102
|
+
"Vehicle": [101.4, 97.8, 103.1, 99.5, 96.2],
|
|
103
|
+
"Drug_1uM": [88.2, 84.6, 91.0, 82.9, 86.4],
|
|
104
|
+
"Combo": [28.1, 32.5, 24.9, 30.2, 26.8],
|
|
105
|
+
},
|
|
106
|
+
test="welch_t",
|
|
107
|
+
correction="holm",
|
|
108
|
+
)
|
|
109
|
+
fig[0].set_labels(title="Cell Viability", xlabel="Arm", ylabel="% Vehicle")
|
|
110
|
+
fig.save("cell_viability.svg")
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
## Uncertainty Propagation & Replicate Aggregation
|
|
114
|
+
|
|
115
|
+
```python
|
|
116
|
+
import pubfigure as pf
|
|
117
|
+
|
|
118
|
+
# Multi-variable Gaussian error propagation: P = V^2 / R
|
|
119
|
+
prop = pf.propagate_uncertainty("V^2 / R", {"V": (10.0, 0.2), "R": (5.0, 0.1)})
|
|
120
|
+
print(prop.value, prop.sigma_total, prop.variance_shares)
|
|
121
|
+
```
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
# `pubfigure` — Python SDK & CLI for Publication-Ready Scientific Figures
|
|
2
|
+
|
|
3
|
+
`pubfigure` wraps `matplotlib` + `numpy` with **42 international publication specifications** — spanning flagship journals (*Nature*, *Science*, *Cell*, *NEJM/Lancet*, *JAMA/BMJ*, *APS PRL*, *IEEE*, *NeurIPS*, *AER*), mainstream Q1–Q3 society/publisher journals (*Elsevier 90/140 mm*, *Springer*, *AIP APL/JAP*, *IOP*, *Optica*, *ACS AMI/ES&T*, *ASME*, *ASCE*, *APA 7th*, *SAGE*, *Taylor & Francis*, *Oxford OUP*, *Wiley*), open-access workhorses (*Scientific Reports/BMC*, *MDPI*, *Frontiers*, *PLOS ONE/eLife*, *IEEE Access*), and **A4 MS/PhD Theses & Conference Posters** — plus **weighted Levenberg–Marquardt curve fitting** (10 presets + custom formula `f(x)` with zero `eval()`), **Gaussian error propagation**, and **auto-stacked non-overlapping significance brackets**.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
pip install pubfigure
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
Or install editable from a local checkout:
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
cd python
|
|
15
|
+
pip install -e .
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
## 5-Line Python Quickstart
|
|
19
|
+
|
|
20
|
+
```python
|
|
21
|
+
import pubfigure as pf
|
|
22
|
+
|
|
23
|
+
fig = pf.Figure(journal="nature-single", palette="npg-nature")
|
|
24
|
+
fit = fig[0].fit(
|
|
25
|
+
x=[0.01, 0.03, 0.1, 0.3, 1.0, 3.0, 10.0, 30.0],
|
|
26
|
+
y=[99.2, 97.5, 91.8, 76.4, 49.8, 25.6, 12.4, 8.1],
|
|
27
|
+
yerr=[2.1, 2.4, 2.8, 3.2, 3.0, 2.5, 1.9, 1.6],
|
|
28
|
+
preset="hill_4pl",
|
|
29
|
+
log_x=True,
|
|
30
|
+
label="Kinase Inhibitor",
|
|
31
|
+
)
|
|
32
|
+
fig[0].set_labels(title="Dose-Response Curve", xlabel="Conc. (µM)", ylabel="Viability (%)")
|
|
33
|
+
fig.save("fig1_nature_89mm.pdf")
|
|
34
|
+
fig.save_workspace("fig1_workspace.json") # Opens directly in PubFigure Web UI!
|
|
35
|
+
print(fit.methods_sentence)
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
## Grouped BioStats + Non-Overlapping Brackets (`*`, `**`, `***`)
|
|
39
|
+
|
|
40
|
+
```python
|
|
41
|
+
import pubfigure as pf
|
|
42
|
+
|
|
43
|
+
fig = pf.Figure(journal="cell-single", palette="okabe-ito")
|
|
44
|
+
report = fig[0].grouped_bar_jitter(
|
|
45
|
+
{
|
|
46
|
+
"Vehicle": [101.4, 97.8, 103.1, 99.5, 96.2],
|
|
47
|
+
"Drug_1uM": [88.2, 84.6, 91.0, 82.9, 86.4],
|
|
48
|
+
"Combo": [28.1, 32.5, 24.9, 30.2, 26.8],
|
|
49
|
+
},
|
|
50
|
+
test="welch_t",
|
|
51
|
+
correction="holm",
|
|
52
|
+
)
|
|
53
|
+
fig[0].set_labels(title="Cell Viability", xlabel="Arm", ylabel="% Vehicle")
|
|
54
|
+
fig.save("cell_viability.svg")
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
## Uncertainty Propagation & Replicate Aggregation
|
|
58
|
+
|
|
59
|
+
```python
|
|
60
|
+
import pubfigure as pf
|
|
61
|
+
|
|
62
|
+
# Multi-variable Gaussian error propagation: P = V^2 / R
|
|
63
|
+
prop = pf.propagate_uncertainty("V^2 / R", {"V": (10.0, 0.2), "R": (5.0, 0.1)})
|
|
64
|
+
print(prop.value, prop.sigma_total, prop.variance_shares)
|
|
65
|
+
```
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=68,<77"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "pubfigure"
|
|
7
|
+
version = "1.0.0"
|
|
8
|
+
description = "42 journal-compliant scientific figure presets (Nature/Science/Cell to Elsevier/Springer/AIP/IOP/ASME/APA 7th/MDPI/Thesis), weighted nonlinear curve fitting, error propagation, and auto-stacked hypothesis brackets for Matplotlib."
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.10"
|
|
11
|
+
license = { file = "LICENSE" }
|
|
12
|
+
authors = [{ name = "YFind Digital Studio", email = "youxunzhangjim@gmail.com" }]
|
|
13
|
+
keywords = [
|
|
14
|
+
"scientific-plotting",
|
|
15
|
+
"matplotlib",
|
|
16
|
+
"publication-figures",
|
|
17
|
+
"curve-fitting",
|
|
18
|
+
"levenberg-marquardt",
|
|
19
|
+
"biostatistics",
|
|
20
|
+
"error-propagation",
|
|
21
|
+
"nature",
|
|
22
|
+
"ieee",
|
|
23
|
+
"aps",
|
|
24
|
+
]
|
|
25
|
+
classifiers = [
|
|
26
|
+
"Development Status :: 4 - Beta",
|
|
27
|
+
"Intended Audience :: Science/Research",
|
|
28
|
+
"License :: OSI Approved :: MIT License",
|
|
29
|
+
"Operating System :: OS Independent",
|
|
30
|
+
"Programming Language :: Python :: 3",
|
|
31
|
+
"Programming Language :: Python :: 3.10",
|
|
32
|
+
"Programming Language :: Python :: 3.11",
|
|
33
|
+
"Programming Language :: Python :: 3.12",
|
|
34
|
+
"Programming Language :: Python :: 3.13",
|
|
35
|
+
"Topic :: Scientific/Engineering :: Visualization",
|
|
36
|
+
"Topic :: Scientific/Engineering :: Bio-Informatics",
|
|
37
|
+
"Topic :: Scientific/Engineering :: Physics",
|
|
38
|
+
]
|
|
39
|
+
dependencies = [
|
|
40
|
+
"numpy>=1.24",
|
|
41
|
+
"matplotlib>=3.7",
|
|
42
|
+
]
|
|
43
|
+
|
|
44
|
+
[project.optional-dependencies]
|
|
45
|
+
scipy = ["scipy>=1.10"]
|
|
46
|
+
dev = ["pytest>=7.4", "build>=1.2", "twine>=5.0"]
|
|
47
|
+
|
|
48
|
+
[project.urls]
|
|
49
|
+
Homepage = "https://pubfigure.youxunzhangjim.workers.dev/"
|
|
50
|
+
Repository = "https://github.com/youxunzhangjim-netizen/PubFigure"
|
|
51
|
+
Issues = "https://github.com/youxunzhangjim-netizen/PubFigure/issues"
|
|
52
|
+
Documentation = "https://github.com/youxunzhangjim-netizen/PubFigure/tree/main/python"
|
|
53
|
+
|
|
54
|
+
[project.scripts]
|
|
55
|
+
pubfigure-py = "pubfigure.cli:main"
|
|
56
|
+
|
|
57
|
+
[tool.setuptools]
|
|
58
|
+
package-dir = { "" = "src" }
|
|
59
|
+
|
|
60
|
+
[tool.setuptools.packages.find]
|
|
61
|
+
where = ["src"]
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"""PubFigure Python SDK — Journal-compliant Matplotlib figures, nonlinear curve fitting & error propagation."""
|
|
2
|
+
|
|
3
|
+
from .fitting import FIT_PRESETS, FitResult, ParameterEstimate, eval_safe_formula, fit_curve
|
|
4
|
+
from .plotting import Figure, PanelBuilder
|
|
5
|
+
from .presets import COLOR_PALETTES, JOURNAL_PRESETS, JournalSpec, format_panel_badge, get_rcparams
|
|
6
|
+
from .stats import (
|
|
7
|
+
GroupedStatsResult,
|
|
8
|
+
PairwiseBracket,
|
|
9
|
+
UncertaintyPropagationResult,
|
|
10
|
+
aggregate_replicates,
|
|
11
|
+
grouped_hypothesis_test,
|
|
12
|
+
kruskal_wallis_test,
|
|
13
|
+
propagate_uncertainty,
|
|
14
|
+
)
|
|
15
|
+
|
|
16
|
+
__version__ = "1.0.0"
|
|
17
|
+
|
|
18
|
+
__all__ = [
|
|
19
|
+
"COLOR_PALETTES",
|
|
20
|
+
"FIT_PRESETS",
|
|
21
|
+
"Figure",
|
|
22
|
+
"FitResult",
|
|
23
|
+
"GroupedStatsResult",
|
|
24
|
+
"JOURNAL_PRESETS",
|
|
25
|
+
"JournalSpec",
|
|
26
|
+
"PairwiseBracket",
|
|
27
|
+
"PanelBuilder",
|
|
28
|
+
"ParameterEstimate",
|
|
29
|
+
"UncertaintyPropagationResult",
|
|
30
|
+
"aggregate_replicates",
|
|
31
|
+
"eval_safe_formula",
|
|
32
|
+
"fit_curve",
|
|
33
|
+
"format_panel_badge",
|
|
34
|
+
"get_rcparams",
|
|
35
|
+
"grouped_hypothesis_test",
|
|
36
|
+
"kruskal_wallis_test",
|
|
37
|
+
"propagate_uncertainty",
|
|
38
|
+
]
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
"""Command-line interface (`pubfigure-py`) for Python scripts and automated pipelines."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
import argparse
|
|
5
|
+
import csv
|
|
6
|
+
import json
|
|
7
|
+
from pathlib import Path
|
|
8
|
+
import sys
|
|
9
|
+
from typing import Dict, List
|
|
10
|
+
import matplotlib
|
|
11
|
+
|
|
12
|
+
matplotlib.use("Agg")
|
|
13
|
+
|
|
14
|
+
from .fitting import FIT_PRESETS, fit_curve
|
|
15
|
+
from .plotting import Figure
|
|
16
|
+
from .presets import JOURNAL_PRESETS
|
|
17
|
+
from .stats import grouped_hypothesis_test
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def _read_csv_rows(path: Path) -> List[List[str]]:
|
|
21
|
+
with path.open("r", encoding="utf-8-sig", newline="") as f:
|
|
22
|
+
return [row for row in csv.reader(f) if any(cell.strip() for cell in row)]
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def main(argv: List[str] | None = None) -> int:
|
|
26
|
+
parser = argparse.ArgumentParser(
|
|
27
|
+
prog="pubfigure-py",
|
|
28
|
+
description="PubFigure Python CLI — Journal-calibrated Matplotlib figures, nonlinear curve fitting & stats.",
|
|
29
|
+
)
|
|
30
|
+
sub = parser.add_subparsers(dest="cmd")
|
|
31
|
+
|
|
32
|
+
sub.add_parser("presets", help="List 14 journal presets and 10 nonlinear curve fit models")
|
|
33
|
+
|
|
34
|
+
p_fit = sub.add_parser("fit", help="Fit preset or custom analytical formula to XY CSV")
|
|
35
|
+
p_fit.add_argument("csv_file", type=Path)
|
|
36
|
+
p_fit.add_argument("--preset", default="exp_decay")
|
|
37
|
+
p_fit.add_argument("--formula", default=None)
|
|
38
|
+
p_fit.add_argument("--json", action="store_true")
|
|
39
|
+
|
|
40
|
+
p_stats = sub.add_parser("stats", help="Run grouped hypothesis suite + Holm brackets on CSV")
|
|
41
|
+
p_stats.add_argument("csv_file", type=Path)
|
|
42
|
+
p_stats.add_argument("--test", default="welch_t", choices=["welch_t", "student_t", "mann_whitney"])
|
|
43
|
+
p_stats.add_argument("--correction", default="holm", choices=["holm", "bonferroni", "none"])
|
|
44
|
+
p_stats.add_argument("--json", action="store_true")
|
|
45
|
+
|
|
46
|
+
p_render = sub.add_parser("render", help="Render CSV or workspace.json to PDF/SVG/PNG via Matplotlib")
|
|
47
|
+
p_render.add_argument("input_file", type=Path)
|
|
48
|
+
p_render.add_argument("-o", "--output", type=Path, required=True, help="Output .pdf, .svg, or .png path")
|
|
49
|
+
p_render.add_argument("--journal", default="nature-single")
|
|
50
|
+
p_render.add_argument("--fit", default=None)
|
|
51
|
+
p_render.add_argument("--formula", default=None)
|
|
52
|
+
p_render.add_argument("--title", default="")
|
|
53
|
+
p_render.add_argument("--xlabel", default="X")
|
|
54
|
+
p_render.add_argument("--ylabel", default="Y")
|
|
55
|
+
|
|
56
|
+
args = parser.parse_args(argv)
|
|
57
|
+
if not args.cmd:
|
|
58
|
+
parser.print_help()
|
|
59
|
+
return 0
|
|
60
|
+
|
|
61
|
+
if args.cmd == "presets":
|
|
62
|
+
for jid, j in JOURNAL_PRESETS.items():
|
|
63
|
+
print(f"{jid:16s} {j.single_col_mm:5.1f}mm / {j.double_col_mm:5.1f}mm {j.name}")
|
|
64
|
+
print("\nFit Presets:")
|
|
65
|
+
for fid, expr in FIT_PRESETS.items():
|
|
66
|
+
print(f" {fid:18s} y = {expr}")
|
|
67
|
+
return 0
|
|
68
|
+
|
|
69
|
+
if args.cmd == "fit":
|
|
70
|
+
rows = _read_csv_rows(args.csv_file)
|
|
71
|
+
headers = rows[0]
|
|
72
|
+
xs = [float(r[0]) for r in rows[1:]]
|
|
73
|
+
ys = [float(r[1]) for r in rows[1:]]
|
|
74
|
+
yerr = [float(r[2]) for r in rows[1:]] if len(headers) >= 3 and "err" in headers[2].lower() else None
|
|
75
|
+
res = fit_curve(xs, ys, yerr=yerr, preset=args.preset, formula=args.formula)
|
|
76
|
+
if args.json:
|
|
77
|
+
print(
|
|
78
|
+
json.dumps(
|
|
79
|
+
{
|
|
80
|
+
"formula": res.formula,
|
|
81
|
+
"r_squared": res.r_squared,
|
|
82
|
+
"rmse": res.rmse,
|
|
83
|
+
"parameters": [p.__dict__ for p in res.parameters],
|
|
84
|
+
"methods": res.methods_sentence,
|
|
85
|
+
},
|
|
86
|
+
indent=2,
|
|
87
|
+
)
|
|
88
|
+
)
|
|
89
|
+
else:
|
|
90
|
+
print(f"Model: y = {res.formula} | R² = {res.r_squared:.5f} | RMSE = {res.rmse:.4g}")
|
|
91
|
+
for p in res.parameters:
|
|
92
|
+
print(f" {p.name:10s} = {p.value:.5g} ± {p.std_error:.3g} (95% CI [{p.ci95_low:.4g}, {p.ci95_high:.4g}])")
|
|
93
|
+
print(res.methods_sentence)
|
|
94
|
+
return 0
|
|
95
|
+
|
|
96
|
+
if args.cmd == "stats":
|
|
97
|
+
rows = _read_csv_rows(args.csv_file)
|
|
98
|
+
headers = rows[0]
|
|
99
|
+
groups: Dict[str, List[float]] = {h: [] for h in headers}
|
|
100
|
+
for r in rows[1:]:
|
|
101
|
+
for idx, h in enumerate(headers):
|
|
102
|
+
if idx < len(r) and r[idx].strip():
|
|
103
|
+
groups[h].append(float(r[idx]))
|
|
104
|
+
rep = grouped_hypothesis_test(groups, test=args.test, correction=args.correction)
|
|
105
|
+
if args.json:
|
|
106
|
+
print(json.dumps({"methods": rep.methods_sentence, "comparisons": [c.__dict__ for c in rep.comparisons]}, indent=2))
|
|
107
|
+
else:
|
|
108
|
+
for c in rep.comparisons:
|
|
109
|
+
print(f"{c.group_a} vs {c.group_b}: adj. p = {c.adj_p:.4g} ({c.stars})")
|
|
110
|
+
print(rep.methods_sentence)
|
|
111
|
+
return 0
|
|
112
|
+
|
|
113
|
+
if args.cmd == "render":
|
|
114
|
+
inp: Path = args.input_file
|
|
115
|
+
if inp.suffix.lower() == ".json":
|
|
116
|
+
fig = Figure.from_workspace(inp)
|
|
117
|
+
else:
|
|
118
|
+
rows = _read_csv_rows(inp)
|
|
119
|
+
headers = rows[0]
|
|
120
|
+
fig = Figure(journal=args.journal)
|
|
121
|
+
ax = fig[0]
|
|
122
|
+
ax.set_labels(title=args.title, xlabel=args.xlabel, ylabel=args.ylabel)
|
|
123
|
+
xs = [float(r[0]) for r in rows[1:]]
|
|
124
|
+
ys = [float(r[1]) for r in rows[1:]]
|
|
125
|
+
yerr = [float(r[2]) for r in rows[1:]] if len(headers) >= 3 and "err" in headers[2].lower() else None
|
|
126
|
+
if args.fit or args.formula:
|
|
127
|
+
ax.fit(xs, ys, yerr=yerr, preset=args.fit or "custom", formula=args.formula, label=headers[1])
|
|
128
|
+
else:
|
|
129
|
+
ax.errorbar_series(xs, ys, yerr=yerr, label=headers[1])
|
|
130
|
+
fig.save(args.output)
|
|
131
|
+
fig.close()
|
|
132
|
+
print(f"Saved publication figure -> {args.output}")
|
|
133
|
+
return 0
|
|
134
|
+
|
|
135
|
+
return 0
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
if __name__ == "__main__":
|
|
139
|
+
sys.exit(main())
|