ncfunc 0.2.1__tar.gz → 0.2.3__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {ncfunc-0.2.1 → ncfunc-0.2.3}/PKG-INFO +1 -1
- {ncfunc-0.2.1 → ncfunc-0.2.3}/pyproject.toml +1 -1
- {ncfunc-0.2.1 → ncfunc-0.2.3}/pyproject.toml.orig +1 -1
- {ncfunc-0.2.1 → ncfunc-0.2.3}/src/ncfunc/__init__.py +4 -0
- {ncfunc-0.2.1 → ncfunc-0.2.3}/src/ncfunc/core.py +30 -3
- {ncfunc-0.2.1 → ncfunc-0.2.3}/README.md +0 -0
- {ncfunc-0.2.1 → ncfunc-0.2.3}/src/ncfunc/read_mf.py +0 -0
|
@@ -5,11 +5,13 @@ from .core import (
|
|
|
5
5
|
attr_val,
|
|
6
6
|
create,
|
|
7
7
|
dim_names,
|
|
8
|
+
get_always_flush,
|
|
8
9
|
ndim,
|
|
9
10
|
read,
|
|
10
11
|
read_time,
|
|
11
12
|
read_within,
|
|
12
13
|
save,
|
|
14
|
+
set_always_flush,
|
|
13
15
|
shape,
|
|
14
16
|
var_names,
|
|
15
17
|
var_names_include,
|
|
@@ -25,12 +27,14 @@ __all__ = [
|
|
|
25
27
|
"attr_val",
|
|
26
28
|
"create",
|
|
27
29
|
"dim_names",
|
|
30
|
+
"get_always_flush",
|
|
28
31
|
"ndim",
|
|
29
32
|
"read",
|
|
30
33
|
"read_mf_within",
|
|
31
34
|
"read_time",
|
|
32
35
|
"read_within",
|
|
33
36
|
"save",
|
|
37
|
+
"set_always_flush",
|
|
34
38
|
"shape",
|
|
35
39
|
"var_names",
|
|
36
40
|
"var_names_include",
|
|
@@ -42,13 +42,14 @@ class DatasetMeta:
|
|
|
42
42
|
|
|
43
43
|
instances are cheap snapshots built without reading any data values.
|
|
44
44
|
a module-level registry keeps the most recently used entries (up to
|
|
45
|
-
MAX_CACHE) keyed by resolved path; use
|
|
46
|
-
|
|
45
|
+
MAX_CACHE) keyed by resolved path; use ALWAYS_FLUSH=True to reuse or
|
|
46
|
+
False to avoid them
|
|
47
47
|
"""
|
|
48
48
|
|
|
49
49
|
variables: dict[str, VariableMeta]
|
|
50
50
|
attributes: dict[str, Any]
|
|
51
51
|
cached_registry: ClassVar[dict[str, DatasetMeta]] = {}
|
|
52
|
+
_always_flush: ClassVar[bool] = False
|
|
52
53
|
|
|
53
54
|
def __init__(self, path: PathLike) -> None:
|
|
54
55
|
"""
|
|
@@ -106,6 +107,9 @@ class DatasetMeta:
|
|
|
106
107
|
raises KeyError if cache_only=True and the path is not cached,
|
|
107
108
|
FileNotFoundError if the path does not exist
|
|
108
109
|
"""
|
|
110
|
+
if get_always_flush():
|
|
111
|
+
return DatasetMeta(path)
|
|
112
|
+
|
|
109
113
|
path = Path(path)
|
|
110
114
|
key = DatasetMeta._to_cache_key(path)
|
|
111
115
|
ds = DatasetMeta.cached_registry.get(key)
|
|
@@ -123,6 +127,22 @@ class DatasetMeta:
|
|
|
123
127
|
ds._read(path)
|
|
124
128
|
return ds
|
|
125
129
|
|
|
130
|
+
@staticmethod
|
|
131
|
+
def set_always_flush(stat: bool) -> None:
|
|
132
|
+
DatasetMeta._always_flush = stat
|
|
133
|
+
|
|
134
|
+
@staticmethod
|
|
135
|
+
def get_always_flush() -> bool:
|
|
136
|
+
return DatasetMeta._always_flush
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
def set_always_flush(stat: bool) -> None:
|
|
140
|
+
DatasetMeta.set_always_flush(stat)
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+
def get_always_flush() -> bool:
|
|
144
|
+
return DatasetMeta.get_always_flush()
|
|
145
|
+
|
|
126
146
|
|
|
127
147
|
# -------------- helpers ---------------
|
|
128
148
|
def _err_ctx(path: PathLike, var_name: str | None = None) -> str:
|
|
@@ -966,7 +986,7 @@ def save(
|
|
|
966
986
|
msg = f"cannot cast data of '{name}' to a numpy array"
|
|
967
987
|
raise ValueError(msg) from e
|
|
968
988
|
|
|
969
|
-
# ---- data check
|
|
989
|
+
# ---- data check
|
|
970
990
|
for i, (name, value) in enumerate(arrays.items()):
|
|
971
991
|
if (
|
|
972
992
|
(len(arrays) == 1 and i == 0) # the only entry (variable == dimension)
|
|
@@ -982,6 +1002,13 @@ def save(
|
|
|
982
1002
|
f"I'm not going to help you write an empty data of shape={value.shape} to {name=}"
|
|
983
1003
|
)
|
|
984
1004
|
|
|
1005
|
+
if len(arrays) > 1:
|
|
1006
|
+
shapes = tuple(v.shape for v in arrays.values())
|
|
1007
|
+
var_shape = shapes[0]
|
|
1008
|
+
dim_shape = tuple(s[0] for s in shapes[1:])
|
|
1009
|
+
if var_shape != dim_shape:
|
|
1010
|
+
raise ValueError(f"shapes differ: {var_shape=} {dim_shape=}")
|
|
1011
|
+
|
|
985
1012
|
# ---- assign parameters to create and write functions
|
|
986
1013
|
names = tuple(data.keys())
|
|
987
1014
|
|
|
File without changes
|
|
File without changes
|