-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathramsin_model_validator.py
More file actions
217 lines (181 loc) · 6.69 KB
/
Copy pathramsin_model_validator.py
File metadata and controls
217 lines (181 loc) · 6.69 KB
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
from __future__ import annotations
import ramsin_model
from pydantic import BaseSettings, validator
from ramsin_model_config import RamsinConfig
from datetime import date
class ModelAdvRamsin(ramsin_model.ModelAdvRamsin):
pass
class ModelGrids(ramsin_model.ModelGrids):
@validator("expnme")
def expnme_length_gte_1(cls, v):
if len(v) == 0:
raise ValueError("Length must be greater or equal to 1")
return v
@validator('runtype')
def runtype_valid_values(cls, v):
choices = ['MAKESFC', 'MAKEVFILE', 'INITIAL', 'HISTORY', 'MEMORY']
if v not in choices:
raise ValueError(f"Value must be one of {choices}")
return v
@validator("timeunit")
def timeunit_valid_values(cls, v):
choices = ['h', 'm', 's']
if v not in choices:
raise ValueError(f"Value must be one of {choices}")
return v
@validator('timmax', 'imonth1', 'idate1', 'iyear1', 'nnxp', 'nnyp', 'nnzp', 'nzg',
'nzs', 'deltax', 'deltay')
def positive_value(cls, v):
if v <= 0:
raise ValueError('Value must be positive')
return v
@validator('iyear1')
def check_valid_date(cls, v, values):
try:
exp_date = date.fromisoformat(f"{v:04}-{values['imonth1']:02}-{values['idate1']:02}")
except ValueError as e:
raise ValueError(e)
return v
@validator("dtlong")
def dtlong_gte_1(cls, v):
if v < 1.0:
raise ValueError("Value must be greater or equal to 1")
return v
@validator("zz")
def zz_length_eq_nnzp(cls, v, values):
if values["deltaz"] == 0. and len(v) != values["nnzp"]:
raise ValueError("Length must be equal to nnzp")
return v
class CcattInfo(ramsin_model.CcattInfo):
@validator("ccatt", "chem_assim", "aerosol", "aer_assim")
def ccattinfo_on_off_valid_values(cls, v):
choices = [0, 1]
if v not in choices:
raise ValueError(f"Value must be one of {choices}")
return v
@validator("chemistry")
def chemistry_valid_values(cls, v):
choices = [-1, 0, 1, 2, 3, 4]
if v not in choices:
raise ValueError(f"Value must be one of {choices}")
return v
class ModelFileInfo(ramsin_model.ModelFileInfo):
@validator("ioutput")
def ioutput_valid_values(cls, v):
choices = [0, 1, 2, 10]
if v not in choices:
raise ValueError(f"Value must be one of {choices}")
return v
class ModelOptions(ramsin_model.ModelOptions):
@validator("ilwrtyp")
def ilwrtyp_valid_values(cls, v):
choices = [0, 1, 2, 3, 4, 5, 6]
if v not in choices:
raise ValueError(f"Value must be one of {choices}")
return v
@validator("nnqparm")
def nnqparm_valid_values(cls, v):
choices = [0, 1, 2, 3, 4, 5, 6, 7, 8]
if v not in choices:
raise ValueError(f"Value must be one of {choices}")
return v
@validator("closure_type")
def closure_type_valid_values(cls, v):
choices = ['PB', 'EN', 'GR', 'LO', 'MC', 'SC', 'AS']
if v not in choices:
raise ValueError(f"Value must be one of {choices}")
return v
@validator("nnshcu")
def nnshcu_valid_values(cls, v):
choices = [0, 1, 2, 3]
if v not in choices:
raise ValueError(f"Value must be one of {choices}")
return v
@validator("isfcl")
def isfcl_valid_values(cls, v):
choices = [0, 1, 2, 3, 4, 5]
if v not in choices:
raise ValueError(f"Value must be one of {choices}")
return v
@validator("isfcl_ocean")
def isfcl_ocean_valid_values(cls, v):
choices = [0, 1]
if v not in choices:
raise ValueError(f"Value must be one of {choices}")
return v
@validator("soil_moist_fail")
def soil_moist_fail_valid_values(cls, v):
choices = ['s', 'h', 'l']
if v not in choices:
raise ValueError(f"Value must be one of {choices}")
return v
@validator("mcphys_type")
def mcphys_type_valid_values(cls, v):
choices = [0, 1, 2, 3, 4, 5, 6, 7]
if v not in choices:
raise ValueError(f"Value must be one of {choices}")
return v
class IsanControl(ramsin_model.IsanControl):
@validator("isan_inc")
def isan_inc_positive(cls, v):
if v <= 0:
raise ValueError(f"Value must be positive")
return v
class IsanIsentropic(ramsin_model.IsanIsentropic):
@validator("icfiletype")
def icfiletype_valid_values(cls, v):
choices = [0, 1, 2, 3, 4]
if v not in choices:
raise ValueError(f"Value must be one of {choices}")
return v
class Post(ramsin_model.Post):
@validator("vp")
def vp_length_eq_nvp(cls, v, values):
if len(v) != int(values["nvp"]):
raise ValueError("Length must be equal to nvp")
return v
class RamsinBasic(BaseSettings):
class Config(RamsinConfig):
pass
model_adv_ramsin: ModelAdvRamsin
model_grids: ModelGrids
ccatt_info: CcattInfo
model_file_info: ModelFileInfo
model_options: ModelOptions
isan_control: IsanControl
isan_isentropic: IsanIsentropic
post: Post
@validator("model_file_info")
def frqanl_multiple_of_dtlong(cls, v, values):
if (
values.get("model_grids") is not None
and values["model_grids"].dtlong is not None
and (v.frqanl % values["model_grids"].dtlong) != 0.0
):
raise ValueError('frqanl must be a multiple of dtlong')
return v
@validator("ccatt_info")
def chem_timestep_multiple_of_dtlong(cls, v, values):
if (
v.ccatt == 1
and values.get("model_grids") is not None
and values["model_grids"].dtlong is not None
and ((v.chem_timestep % values["model_grids"].dtlong) != 0.0
or (v.chem_timestep / values["model_grids"].dtlong) > 4)
):
raise ValueError(
'chem_timestep must be a multiple of dtlong and 4 times at most')
return v
@validator("ccatt_info")
def aer_timestep_multiple_of_dtlong(cls, v, values):
if (
v.ccatt == 1
and v.aerosol == 1
and values.get("model_grids") is not None
and values["model_grids"].dtlong is not None
and ((v.aer_timestep % values["model_grids"].dtlong) != 0.0
or (v.aer_timestep / values["model_grids"].dtlong) > 4)
):
raise ValueError(
'aer_timestep must be a multiple of dtlong and 4 times at most')
return v