|
11 | 11 |
|
12 | 12 | .. include:: ../docs/tutorial.md |
13 | 13 | .. include:: ../docs/howto.md |
| 14 | +.. include:: ../docs/cli.md |
14 | 15 |
|
15 | | -## API Documentation |
| 16 | +# 4. API Documentation |
16 | 17 | ''' |
17 | 18 |
|
18 | 19 | __docformat__ = "restructuredtext" |
|
25 | 26 |
|
26 | 27 | import os |
27 | 28 | import numpy as np |
| 29 | +import typer |
| 30 | +from typing_extensions import Annotated |
28 | 31 | from statistics import stdev |
29 | 32 | from scipy.stats import t as tstudent |
30 | 33 | from scipy.stats import levene |
@@ -3226,9 +3229,74 @@ def __init__(self, l = [], **kwargs): |
3226 | 3229 | D4xdata.__init__(self, l = l, mass = '48', **kwargs) |
3227 | 3230 |
|
3228 | 3231 |
|
| 3232 | + |
3229 | 3233 | class _SessionPlot(): |
3230 | 3234 | ''' |
3231 | 3235 | Simple placeholder class |
3232 | 3236 | ''' |
3233 | 3237 | def __init__(self): |
3234 | 3238 | 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() |
0 commit comments