Command Line Interface

Convert spectra to wavelet images.

source

main

 main (config:pathlib.Path)

Convert spectra to wavelet images using configuration from a file.

Type Details
config Path Path to the configuration file
Exported source
@call_parse
def main(
    config: Path, # Path to the configuration file
    ):
    "Convert spectra to wavelet images using configuration from a file."
    cfg = load_config(config)
    params = extract_params(cfg)
    loader = get_loader(params)
    data = loader.load_data(params['analytes'])
    create_output_files(data, params)

source

load_config

 load_config (config_path:pathlib.Path)

Load the configuration from a YAML file.

Exported source
def load_config(config_path: Path) -> dict:
    "Load the configuration from a YAML file."
    with open(config_path, 'r') as f:
        return yaml.safe_load(f)

source

extract_params

 extract_params (cfg:dict)

Extract parameters from the configuration.

Exported source
def extract_params(cfg: dict) -> dict:
    "Extract parameters from the configuration."
    return {
        'src': cfg['src'],
        'dir_out': cfg['dir_out'],
        'img_dir': cfg.get('img_dir', 'im'),
        'dataset': cfg.get('dataset', 'ossl'),
        'spectra_type': cfg.get('spectra_type', 'mir'),
        'analytes': cfg.get('analytes', 'k.ext_usda.a725_cmolc.kg'),
        'n_samples': cfg.get('n_samples'),
        'batch_size': cfg.get('batch_size', 10)
    }

source

get_loader

 get_loader (params:dict)

Get the loader from the parameters.

Exported source
def get_loader(params: dict):
    "Get the loader from the parameters."
    loader_kwargs = {'spectra_type': params['spectra_type']} if params['dataset'] == 'ossl' else {}
    return LoaderFactory.get_loader(params['src'], params['dataset'], **loader_kwargs)

source

create_output_files

 create_output_files (data, params)

Create the output files.

Exported source
def create_output_files(data, params):
    "Create the output files."
    print(f'Creating image target csv in {params["dir_out"]} ...')
    create_image_target_csv(data, 
                            n_samples=params['n_samples'], 
                            output_dir=Path(params['dir_out']))  
    
    print(f'Creating wavelet images in {Path(params["dir_out"])/params["img_dir"]} ...')
    convert_to_wavelet_images(data, 
                              output_dir=Path(params['dir_out'])/params['img_dir'], 
                              n_samples=params['n_samples'],
                              batch_size=params['batch_size'])