Skip to content

Commit 221fe33

Browse files
committed
deploy: 3aab539
0 parents  commit 221fe33

File tree

1,532 files changed

+369226
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,532 files changed

+369226
-0
lines changed

.nojekyll

Whitespace-only changes.

_downloads/4b858dab9366f77b3641c99adece5fd2/weather_observations.ipynb

Lines changed: 96 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import yaml
2+
3+
def get_parameters(config_file, required, defaults):
4+
'''
5+
Parameters:
6+
Optionfile: FileName of the yaml file containing the options
7+
required: Dict of required argument names and their object types.
8+
defaults: Dict of default parameters mapping to their default values
9+
10+
Returns: An object with fields named according to required and optional values.
11+
'''
12+
f = open(config_file)
13+
options = yaml.safe_load(f)
14+
# create a parameters object that allows setting attributes.
15+
parameters = type('Options', (), {})()
16+
# check required arguments
17+
for arg in required:
18+
if not arg in options:
19+
raise Exception("Could not find required Argument " + arg + " aborting...")
20+
else:
21+
if not isinstance(options[arg],required[arg]):
22+
raise Exception("Expected input of type " + str(required[arg]) + " but got " + str(type(options[arg])))
23+
print("Setting " + arg + " to " + str(options[arg]))
24+
setattr(parameters,arg,options[arg])
25+
# check the default values.
26+
for arg in defaults:
27+
if arg in options:
28+
if not isinstance(options[arg],type(defaults[arg])):
29+
#Wrong type for the parameter
30+
raise Exception("Expected input of type " + str(type(defaults[arg])) + " but got " + str(type(options[arg])))
31+
print("Setting " + arg + " to " + str(options[arg]))
32+
setattr(parameters,arg,options[arg])
33+
else:
34+
print( arg + " not found in option file. Using default: " +str(defaults[arg]))
35+
setattr(parameters,arg,defaults[arg])
36+
return parameters
37+
38+

0 commit comments

Comments
 (0)