main 1.71 KB
Newer Older
BorjaEst's avatar
BorjaEst committed
1
#!/usr/bin/env python3
BorjaEst's avatar
BorjaEst committed
2
"""
BorjaEst's avatar
BorjaEst committed
3
o3skim is a tool for data pre-processing of ozone applications
BorjaEst's avatar
BorjaEst committed
4
5
6
"""
import sys
import argparse
7
import logging
BorjaEst's avatar
BorjaEst committed
8
import warnings
BorjaEst's avatar
BorjaEst committed
9
10
11

import o3skim

BorjaEst's avatar
BorjaEst committed
12
warnings.simplefilter(action='ignore', category=FutureWarning)
BorjaEst's avatar
BorjaEst committed
13

BorjaEst's avatar
BorjaEst committed
14
15
16
17

def cmdline_args():
    p = argparse.ArgumentParser(description=__doc__,
                                formatter_class=argparse.RawDescriptionHelpFormatter)
18
19
20
    # Arguments
    p.add_argument("-f", "--sources_file", type=str, default="./sources.yaml",
                   help="custom sources YAML configuration (default: %(default)s)")
BorjaEst's avatar
BorjaEst committed
21
    p.add_argument("-s", "--split_by", type=str, default=None,
BorjaEst's avatar
BorjaEst committed
22
                   choices=['year', 'decade'],
BorjaEst's avatar
BorjaEst committed
23
                   help="Period time to split output (default: %(default)s)")
24
    p.add_argument("-v", "--verbosity", type=str, default='ERROR',
BorjaEst's avatar
BorjaEst committed
25
                   choices=['DEBUG', 'INFO', 'WARNING', 'ERROR', 'CRITICAL'],
26
                   help="Sets the logging level (default: %(default)s)")
BorjaEst's avatar
BorjaEst committed
27
28
29
30
31
    return(p.parse_args())


if __name__ == '__main__':
    args = cmdline_args()
32
33

    # Set logging level
34
    logformat = '%(asctime)s %(name)-24s %(levelname)-8s %(message)s'
35
    logging.basicConfig(level=getattr(logging, args.verbosity), format=logformat)
36
37

    # Configuration load
38
    logging.info("Lookinf for config at: '%s'", args.sources_file)
39
    config = o3skim.load(args.sources_file)
40
41
42

    # Create sources
    logging.info("Loading data from './data' ")
43
    with o3skim.cd("data"):
BorjaEst's avatar
BorjaEst committed
44
        ds = {name: o3skim.Source(name, collection) for
45
46
47
48
              name, collection in config.items()}

    # Skim output
    logging.info("Skimming data to './output' ")
49
    with o3skim.cd("output"):
BorjaEst's avatar
BorjaEst committed
50
        [source.skim(groupby=args.split_by) for source in ds.values()]