-
Notifications
You must be signed in to change notification settings - Fork 4
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
1 parent
7a5af23
commit 3cd0983
Showing
4 changed files
with
92 additions
and
2 deletions.
There are no files selected for viewing
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
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,20 @@ | ||
from unittest import TestCase | ||
|
||
from wrfconf import ordered_load | ||
from wrfconf.validate import validate_config | ||
|
||
|
||
class TestValidate(TestCase): | ||
def setUp(self): | ||
self.cfg = ordered_load(open('examples/run.yml')) | ||
|
||
def test_full(self): | ||
is_valid, errors = validate_config(self.cfg) | ||
self.assertTrue(is_valid) | ||
self.assertEqual(errors, []) | ||
|
||
def test_invalid(self): | ||
del self.cfg['domain']['parent_id'] | ||
is_valid, errors = validate_config(self.cfg) | ||
self.assertFalse(is_valid) | ||
self.assertEqual(len(errors), 1) |
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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
__version__ = "0.4.0" | ||
|
||
from .process import create_wps_namelist, create_wrf_namelist, process_conf_file | ||
from .process import create_wps_namelist, create_wrf_namelist, process_conf_file, ordered_load | ||
from .validate import validate_config |
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,68 @@ | ||
from marshmallow import fields, Schema, ValidationError | ||
|
||
|
||
class MetaSchema(Schema): | ||
""" | ||
Any metadata needed to document the run. | ||
""" | ||
pass | ||
|
||
|
||
class RunInfoSchema(Schema): | ||
start_date = fields.Str(required=True) | ||
run_hours = fields.Int(required=True) | ||
max_dom = fields.Int(required=True) | ||
|
||
|
||
class DomainSchema(Schema): | ||
parent_id = fields.List(fields.Int, required=True) | ||
parent_grid_ratio = fields.List(fields.Int, required=True) | ||
i_parent_start = fields.List(fields.Int, required=True) | ||
j_parent_start = fields.List(fields.Int, required=True) | ||
e_we = fields.List(fields.Int) | ||
e_sn = fields.List(fields.Int) | ||
dx = fields.List(fields.Int, required=True) | ||
dy = fields.List(fields.Int, required=True) | ||
map_proj = fields.Str(required=True) | ||
ref_lat = fields.Float(required=True) | ||
ref_lon = fields.Float(required=True) | ||
ref_x = fields.Float() | ||
ref_y = fields.Float() | ||
truelat1 = fields.Float() | ||
truelat2 = fields.Float() | ||
geog_data_res = fields.List(fields.Str) | ||
|
||
|
||
class NamelistSchema(Schema): | ||
pass | ||
|
||
|
||
class WPSSchema(Schema): | ||
pass | ||
|
||
|
||
class ConfigSchema(Schema): | ||
meta = fields.Nested(MetaSchema) | ||
run_info = fields.Nested(RunInfoSchema, required=True) | ||
domain = fields.Nested(DomainSchema, required=True) | ||
namelist = fields.Nested(NamelistSchema) | ||
wps = fields.Nested(MetaSchema) | ||
|
||
|
||
def validate_config(cfg): | ||
""" | ||
Validate a yaml configuration file | ||
There are a number of required and optional parameters. Note that this function does not check every combination of WRF parameters. | ||
:param cfg: | ||
:return: | ||
""" | ||
schema = ConfigSchema() | ||
try: | ||
schema.load(cfg) | ||
return True, [] | ||
except ValidationError as err: | ||
errors = err.messages | ||
return False, errors |