Skip to content

Commit 92d8dc2

Browse files
mjrenomjreno
authored andcommitted
jsonschema as staticmethod
1 parent 920d9a1 commit 92d8dc2

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

autotest/test_netcdf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff 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)

modflow_devtools/netcdf.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from dataclasses import dataclass, field
22
from typing import Any
33

4+
import jsonschema
45
import numpy as np
56
import 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,

0 commit comments

Comments
 (0)