jordancaraballo commited on
Commit
f01d5df
1 Parent(s): a710522

Adding common library file

Browse files
Files changed (1) hide show
  1. wildfire_occurrence/model/common.py +33 -0
wildfire_occurrence/model/common.py ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import sys
2
+ import argparse
3
+ import omegaconf
4
+ from datetime import datetime
5
+ from wildfire_occurrence.model.config import Config
6
+
7
+
8
+ # -------------------------------------------------------------------------
9
+ # read_config
10
+ # -------------------------------------------------------------------------
11
+ def read_config(filename: str, config_class=Config):
12
+ """
13
+ Read configuration filename and initiate objects
14
+ """
15
+ # Configuration file initialization
16
+ schema = omegaconf.OmegaConf.structured(config_class)
17
+ conf = omegaconf.OmegaConf.load(filename)
18
+ try:
19
+ conf = omegaconf.OmegaConf.merge(schema, conf)
20
+ except BaseException as err:
21
+ sys.exit(f"ERROR: {err}")
22
+ return conf
23
+
24
+
25
+ # -------------------------------------------------------------------------
26
+ # validate_date
27
+ # -------------------------------------------------------------------------
28
+ def valid_date(s):
29
+ try:
30
+ return datetime.strptime(s, "%Y-%m-%d")
31
+ except ValueError:
32
+ msg = "not a valid date: {0!r}".format(s)
33
+ raise argparse.ArgumentTypeError(msg)