Skip to content

Commit 9e82064

Browse files
committed
Add CLI
1 parent 5fb1e7b commit 9e82064

20 files changed

+8719
-8441
lines changed

D47crunch/__init__.py

Lines changed: 69 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@
1111
1212
.. include:: ../docs/tutorial.md
1313
.. include:: ../docs/howto.md
14+
.. include:: ../docs/cli.md
1415
15-
## API Documentation
16+
# 4. API Documentation
1617
'''
1718

1819
__docformat__ = "restructuredtext"
@@ -25,6 +26,8 @@
2526

2627
import os
2728
import numpy as np
29+
import typer
30+
from typing_extensions import Annotated
2831
from statistics import stdev
2932
from scipy.stats import t as tstudent
3033
from scipy.stats import levene
@@ -3226,9 +3229,74 @@ def __init__(self, l = [], **kwargs):
32263229
D4xdata.__init__(self, l = l, mass = '48', **kwargs)
32273230

32283231

3232+
32293233
class _SessionPlot():
32303234
'''
32313235
Simple placeholder class
32323236
'''
32333237
def __init__(self):
32343238
pass
3239+
3240+
_app = typer.Typer(
3241+
add_completion = False,
3242+
context_settings={'help_option_names': ['-h', '--help']},
3243+
rich_markup_mode = 'rich',
3244+
)
3245+
3246+
@_app.command()
3247+
def _cli(
3248+
rawdata: Annotated[str, typer.Argument(help = "Specify the path of a rawdata input file")],
3249+
exclude: Annotated[str, typer.Option('--exclude', '-e', help = 'The path of a file specifying UIDs and/or Samples to exclude')] = 'none',
3250+
anchors: Annotated[str, typer.Option('--anchors', '-a', help = 'The path of a file specifying custom anchors')] = 'none',
3251+
output_dir: Annotated[str, typer.Option('--output-dir', '-o', help = 'Specify the output directory')] = 'output',
3252+
):
3253+
"""
3254+
Process raw D47 data and return standardized results.
3255+
"""
3256+
3257+
data = D47data()
3258+
data.read(rawdata)
3259+
3260+
if exclude != 'none':
3261+
exclude = read_csv(exclude)
3262+
exclude_uid = {r['UID'] for r in exclude if 'UID' in r}
3263+
exclude_sample = {r['Sample'] for r in exclude if 'Sample' in r}
3264+
else:
3265+
exclude_uid = []
3266+
exclude_sample = []
3267+
3268+
data = D47data([r for r in data if r['UID'] not in exclude_uid and r['Sample'] not in exclude_sample])
3269+
3270+
if anchors != 'none':
3271+
anchors = read_csv(anchors)
3272+
data.Nominal_d13C_VPDB = {
3273+
_['Sample']: _['d13C_VPDB']
3274+
for _ in anchors
3275+
if 'd13C_VPDB' in _
3276+
}
3277+
data.Nominal_d18O_VPDB = {
3278+
_['Sample']: _['d18O_VPDB']
3279+
for _ in anchors
3280+
if 'd18O_VPDB' in _
3281+
}
3282+
data.Nominal_D4x = {
3283+
_['Sample']: _['D47']
3284+
for _ in anchors
3285+
if 'D47' in _
3286+
}
3287+
3288+
data.refresh()
3289+
data.wg()
3290+
data.crunch()
3291+
data.standardize()
3292+
data.summary(dir = output_dir)
3293+
data.table_of_samples(dir = output_dir)
3294+
data.table_of_sessions(dir = output_dir)
3295+
data.plot_sessions(dir = output_dir)
3296+
data.plot_residuals(dir = output_dir, filename = 'D47_residuals.pdf', kde = True)
3297+
data.table_of_analyses(dir = output_dir)
3298+
data.plot_distribution_of_analyses(dir = output_dir)
3299+
data.plot_bulk_compositions(dir = output_dir + '/bulk_compositions')
3300+
3301+
def __cli():
3302+
_app()

changelog.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
# Changelog
22

3-
### New feature
3+
### Command-line interface (CLI)
4+
* Rejoice, you no longer need to know Python: it is now possible to process a multi-session Δ47 dataset with custom anchors and custom UID/sample exclusion list by simply calling `D47crunch -a anchors.csv -e exclude.csv -o outdir rawdata.csv`.
5+
6+
### New features
47
* Add `yspan` option to `D4xdata.plot_residuals()`
58
* Added `shuffle` option to `virtual_data()`.
69
* Added `filetype` option to `D4xdata.plot_sessions()`.

code_examples/virtual_data/output.txt

Lines changed: 57 additions & 57 deletions
Large diffs are not rendered by default.

docs/D47_plot_Session_01.png

-1 Bytes
Loading

docs/D47_plot_Session_02.png

3 Bytes
Loading

docs/D47_plot_Session_03.png

0 Bytes
Loading

docs/D47_plot_Session_04.png

-5 Bytes
Loading

docs/D47_plot_Session_05.png

-2 Bytes
Loading

docs/D47_plot_Session_06.png

1 Byte
Loading

docs/D47_plot_Session_07.png

0 Bytes
Loading

0 commit comments

Comments
 (0)