-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 3ecbac2
Showing
1,225 changed files
with
302,519 additions
and
0 deletions.
There are no files selected for viewing
Empty file.
96 changes: 96 additions & 0 deletions
96
_downloads/4b858dab9366f77b3641c99adece5fd2/weather_observations.ipynb
Large diffs are not rendered by default.
Oops, something went wrong.
38 changes: 38 additions & 0 deletions
38
_downloads/75c4ab69c0f59fbb1589b03be360a485/optionsparser.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import yaml | ||
|
||
def get_parameters(config_file, required, defaults): | ||
''' | ||
Parameters: | ||
Optionfile: FileName of the yaml file containing the options | ||
required: Dict of required argument names and their object types. | ||
defaults: Dict of default parameters mapping to their default values | ||
Returns: An object with fields named according to required and optional values. | ||
''' | ||
f = open(config_file) | ||
options = yaml.safe_load(f) | ||
# create a parameters object that allows setting attributes. | ||
parameters = type('Options', (), {})() | ||
# check required arguments | ||
for arg in required: | ||
if not arg in options: | ||
raise Exception("Could not find required Argument " + arg + " aborting...") | ||
else: | ||
if not isinstance(options[arg],required[arg]): | ||
raise Exception("Expected input of type " + str(required[arg]) + " but got " + str(type(options[arg]))) | ||
print("Setting " + arg + " to " + str(options[arg])) | ||
setattr(parameters,arg,options[arg]) | ||
# check the default values. | ||
for arg in defaults: | ||
if arg in options: | ||
if not isinstance(options[arg],type(defaults[arg])): | ||
#Wrong type for the parameter | ||
raise Exception("Expected input of type " + str(type(defaults[arg])) + " but got " + str(type(options[arg]))) | ||
print("Setting " + arg + " to " + str(options[arg])) | ||
setattr(parameters,arg,options[arg]) | ||
else: | ||
print( arg + " not found in option file. Using default: " +str(defaults[arg])) | ||
setattr(parameters,arg,defaults[arg]) | ||
return parameters | ||
|
||
|
Oops, something went wrong.