Command line tools#

How to use PyOPIA on the command line.

This is useful for routine tasks, such as processing larger datasets.

The functions available are contained within the pyopia.cli module.

Get help#

To get a print a basic outline of available commands and what they do:

pyopia --help

You can load this documentation on readthedocs py typing: pyopia docs into the command line

                                                                                                                   
 Usage: root [OPTIONS] COMMAND [ARGS]...                                                                           
                                                                                                                   
╭─ Options ───────────────────────────────────────────────────────────────────────────────────────────────────────╮
 --install-completion          Install completion for the current shell.                                         
 --show-completion             Show completion for the current shell, to copy it or customize the installation.  
 --help                        Show this message and exit.                                                       
╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
╭─ Commands ──────────────────────────────────────────────────────────────────────────────────────────────────────╮
 docs             Open browser at PyOPIA's readthedocs page                                                      
 generate-config  Put an example config.toml file in the current directory                                       
 merge-mfdata     Combine a multi-file directory of STATS.nc files into a single '-STATS.nc' file that can then  
                  be loaded with {func}`pyopia.io.load_stats`                                                    
 modify-config    Modify a existing config.toml file and write a new one to disc                                 
 process          Run a PyOPIA processing pipeline based on given a config.toml                                  
╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯

Generate a config file for runnning a processing pipeline#

pyopia generate-config

Will put an example config.toml file in the current directory. Some elements of the pipelines are instrument specific, so either silcam or holo must be specified. In future, we will add a generic pipline that uses a an imread function that can load most image types - for the moment though, you will need to setup your own pipeline config if you are not using a silcam or holo pipeline.

Generate a config for a silcam pipeline:

pyopia generate-config silcam 'rawdatapath/*.silc' 'modelpath/keras_model.keras' 'proc_folder_path' 'testdata'

Generate a config for a holo pipeline:

pyopia generate-config holo 'rawdatapath/*.pgm' 'modelpath/keras_model.keras' 'proc_folder_path' 'testdata'

See pyopia.cli.generate_config() for more details

                                                                                                                   
 Usage: root generate-config [OPTIONS] INSTRUMENT RAW_FILES MODEL_PATH OUTFOLDER                                   
                             OUTPUT_PREFIX                                                                         
                                                                                                                   
 Put an example config.toml file in the current directory                                                          
 Parameters ---------- instrument : str     either `silcam`, `holo` or `uvp` raw_files : str     raw_files         
 model_path : str     model_path outfolder : str     outfolder output_prefix : str     output_prefix               
                                                                                                                   
╭─ Arguments ─────────────────────────────────────────────────────────────────────────────────────────────────────╮
 *    instrument         TEXT  [default: None] [required]                                                        
 *    raw_files          TEXT  [default: None] [required]                                                        
 *    model_path         TEXT  [default: None] [required]                                                        
 *    outfolder          TEXT  [default: None] [required]                                                        
 *    output_prefix      TEXT  [default: None] [required]                                                        
╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
╭─ Options ───────────────────────────────────────────────────────────────────────────────────────────────────────╮
 --help          Show this message and exit.                                                                     
╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯

Modify an existing config#

pyopia modify-config

allows for programatically adjusting config settings if, for example, batch-processing different datasets that require a diferrent ‘raw_files’ location or other modify configuration.

See pyopia.cli.modify_config() for more details

                                                                                                                   
 Usage: root modify-config [OPTIONS] EXISTING_FILENAME MODIFIED_FILENAME                                           
                                                                                                                   
 Modify a existing config.toml file and write a new one to disc                                                    
 Parameters ---------- existing_filename : str     e.g. config.toml modified_filename : str     e.g.               
 config_new.toml raw_files : str, optional     modify the raw file input in the `[general]` settings, by default   
 None step_name : str, optional     the name of the step to modify e.g. `segmentation`, by default None modify_arg 
 : str, optional     the name of the step to modify e.g. `threshold`.     existing arguments will be overwritten,  
 non-existent arguments will be created, by default None modify_value : str or floar, optional     new value to    
 attach to the 'modify_arg' setting e.g. 0.85.     Accepts either string or float input, by default None           
                                                                                                                   
╭─ Arguments ─────────────────────────────────────────────────────────────────────────────────────────────────────╮
 *    existing_filename      TEXT  [default: None] [required]                                                    
 *    modified_filename      TEXT  [default: None] [required]                                                    
╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
╭─ Options ───────────────────────────────────────────────────────────────────────────────────────────────────────╮
 --raw-files           TEXT  [default: None]                                                                     
 --step-name           TEXT  [default: None]                                                                     
 --modify-arg          TEXT  [default: None]                                                                     
 --modify-value        TEXT  [default: None]                                                                     
 --help                      Show this message and exit.                                                         
╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯

PyOPIA process#

To run a processing pipeline on a dataset using the settings in a config.toml file:

pyopia process config.toml

See pyopia.cli.process() for more details

Please have a look at the page about analysing Big datasets if you have a lot of images and/or a lot of particles.

                                                                                                                   
 Usage: root process [OPTIONS] CONFIG_FILENAME                                                                     
                                                                                                                   
 Run a PyOPIA processing pipeline based on given a config.toml                                                     
 Parameters ---------- config_filename : str     config filename numchunks : int, optional     split the dataset   
 into chucks, and process in parallell, by default 1                                                               
                                                                                                                   
╭─ Arguments ─────────────────────────────────────────────────────────────────────────────────────────────────────╮
 *    config_filename      TEXT  [default: None] [required]                                                      
╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
╭─ Options ───────────────────────────────────────────────────────────────────────────────────────────────────────╮
 --num-chunks        INTEGER  [default: 1]                                                                       
 --help                       Show this message and exit.                                                        
╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯