File tree Expand file tree Collapse file tree 2 files changed +9
-7
lines changed
Expand file tree Collapse file tree 2 files changed +9
-7
lines changed Original file line number Diff line number Diff line change @@ -473,7 +473,7 @@ def test_jsonschema():
473473 nc_input .packages .append (NetCDFPackageCfg ("npf" , "npf" ))
474474 nc_input .packages .append (NetCDFPackageCfg ("welg_0" , "welg" ))
475475
476- schema = nc_input .jsonschema
476+ schema = nc_input .jsonschema ()
477477 assert isinstance (schema , dict )
478478 Draft7Validator .check_schema (schema ) # raises if not valid
479479 validator = Draft7Validator (schema )
Original file line number Diff line number Diff line change 11from dataclasses import dataclass , field
22from typing import Any
33
4+ import jsonschema
45import numpy as np
56import xarray as xr
67
@@ -69,12 +70,12 @@ class NetCDFModelInput:
6970 dims : list [int ] = field (default_factory = list )
7071 packages : list [NetCDFPackageCfg ] = field (default_factory = list )
7172
72- @property
73- def jsonschema (self ) :
73+ @staticmethod
74+ def jsonschema () -> jsonschema :
7475 return NetCDFModel .model_json_schema ()
7576
7677 @property
77- def meta (self ):
78+ def meta (self ) -> dict [ Any , Any ] :
7879 self ._meta : dict [str , Any ] = {}
7980 self ._meta ["attrs" ] = {}
8081 self ._meta ["attrs" ]["modflow_model" ] = f"{ self .type } 6: { self .name } "
@@ -111,7 +112,7 @@ def meta(self):
111112 validate (self ._meta , self .dims [1 :])
112113 return self ._meta
113114
114- def to_xarray (self ):
115+ def to_xarray (self ) -> xr . Dataset :
115116 dimmap = {
116117 "time" : 0 ,
117118 "z" : 1 ,
@@ -127,11 +128,12 @@ def to_xarray(self):
127128 ds .attrs [a ] = meta ["attrs" ][a ]
128129
129130 for p in meta ["variables" ]:
131+ dtype : np .dtype [np .float64 ] | np .dtype [np .int64 ] | np .dtype [np .int32 ]
130132 varname = p ["varname" ]
131133 if p ["numeric_type" ] == "f8" :
132- dtype = np .float64
134+ dtype = np .dtype ( np . float64 )
133135 elif p ["numeric_type" ] == "i8" :
134- dtype = np .int64
136+ dtype = np .dtype ( np . int32 )
135137 dims = [self .dims [dimmap [dim ]] for dim in p ["shape" ]]
136138 data = np .full (
137139 dims ,
You can’t perform that action at this time.
0 commit comments