File size: 1,072 Bytes
f01d5df
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import sys
import argparse
import omegaconf
from datetime import datetime
from wildfire_occurrence.model.config import Config


# -------------------------------------------------------------------------
# read_config
# -------------------------------------------------------------------------
def read_config(filename: str, config_class=Config):
    """
    Read configuration filename and initiate objects
    """
    # Configuration file initialization
    schema = omegaconf.OmegaConf.structured(config_class)
    conf = omegaconf.OmegaConf.load(filename)
    try:
        conf = omegaconf.OmegaConf.merge(schema, conf)
    except BaseException as err:
        sys.exit(f"ERROR: {err}")
    return conf


# -------------------------------------------------------------------------
# validate_date
# -------------------------------------------------------------------------
def valid_date(s):
    try:
        return datetime.strptime(s, "%Y-%m-%d")
    except ValueError:
        msg = "not a valid date: {0!r}".format(s)
        raise argparse.ArgumentTypeError(msg)