jpvantassel / hvsrpy

A Python package for Horizontal-to-Vertical (H/V, HVSR) Spectral Ratio Processing.
https://pypi.org/project/hvsrpy/
Other
71 stars 29 forks source link

Feature Request: Command line interface #12

Closed arkottke closed 3 years ago

arkottke commented 3 years ago

It would be nice to be able to run the program from the command line for a list of files. This is the way that I have implemented by own HVSR calculation software. The following is an example of my command line interface:

usage: H/V Calculator [-h] [--version] [-a] [-c CONFIG] [-m {both,welch,sesame,raw_only}]
                      [-p {auto,manual}]
                      [inputs [inputs ...]]

Calculator for V/H ratios from mini-seed

positional arguments:
  inputs                Input file(s) to read

optional arguments:
  -h, --help            show this help message and exit
  --version             show program's version number and exit
  -a, --all             Compute all usable
  -c CONFIG, --config CONFIG
                        Specify configuration
  -m {both,welch,sesame,raw_only}, --method {both,welch,sesame,raw_only}
                        Method for computing H/V ratio
  -p {auto,manual}, --peakselect {auto,manual}
                        Method for selecting the peak

A few things:

I think such an interface would help in bulk processing of recordings. Additionally, interactively selecting frequency ranges could be done using matplotlib GUI support.

jpvantassel commented 3 years ago

I think this is a good idea and something that should be fairly straightforward to implement. Thanks for suggesting it!

My thinking on this is to:

  1. Create a new module called cli.py.
  2. Create several functions in cli.py which perform similar functions to the example notebooks (e.g., simple_hvsrpy_interface.ipynb).
  3. Use click or some other Python package to decorate these functions and handle the CLI details.
  4. Allow the CLI to be accessed as an entry_point to the hvsrpy package.
arkottke commented 3 years ago

That's exactly what I was thinking. I have read some very good things about click. As far as configuration of the calculation, I used JSON, but it doesn't have the ability to provide comments which is a significant drawback. Two alternatives that you might consider are json5 or toml.

jpvantassel commented 3 years ago

Update: A preliminary implementation of a command line interface has been added to the dev branch with commit 8505ff. My intent is make a release candidate for v1.0.0 which includes the CLI, among other changes, in the next week or two. In the meantime the CLI is functional, although not guaranteed to be 100% debugged. Feedback now (or after the RC comes out) is appreciated.