Skip to content

Commit 0dc3c20

Browse files
committed
Move _DATATYPES_TO_FILL_VALUES back to particlefile.py
1 parent 7bb4f89 commit 0dc3c20

File tree

2 files changed

+21
-23
lines changed

2 files changed

+21
-23
lines changed

parcels/_constants.py

Lines changed: 0 additions & 16 deletions
This file was deleted.

parcels/particlefile.py

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
from zarr.storage import DirectoryStore
1515

1616
import parcels
17-
from parcels._constants import DATATYPES_TO_FILL_VALUES
1817
from parcels.particle import _SAME_AS_FIELDSET_TIME_INTERVAL, ParticleClass
1918
from parcels.tools._helpers import timedelta_to_float
2019

@@ -25,6 +24,21 @@
2524

2625
__all__ = ["ParticleFile"]
2726

27+
_DATATYPES_TO_FILL_VALUES = {
28+
np.dtype(np.float16): np.nan,
29+
np.dtype(np.float32): np.nan,
30+
np.dtype(np.float64): np.nan,
31+
np.dtype(np.bool_): np.iinfo(np.int8).max,
32+
np.dtype(np.int8): np.iinfo(np.int8).max,
33+
np.dtype(np.int16): np.iinfo(np.int16).max,
34+
np.dtype(np.int32): np.iinfo(np.int32).max,
35+
np.dtype(np.int64): np.iinfo(np.int64).max,
36+
np.dtype(np.uint8): np.iinfo(np.uint8).max,
37+
np.dtype(np.uint16): np.iinfo(np.uint16).max,
38+
np.dtype(np.uint32): np.iinfo(np.uint32).max,
39+
np.dtype(np.uint64): np.iinfo(np.uint64).max,
40+
}
41+
2842

2943
class ParticleFile:
3044
"""Initialise trajectory output.
@@ -109,16 +123,16 @@ def _convert_varout_name(self, var):
109123

110124
def _extend_zarr_dims(self, Z, store, dtype, axis):
111125
if axis == 1:
112-
a = np.full((Z.shape[0], self.chunks[1]), DATATYPES_TO_FILL_VALUES[dtype], dtype=dtype)
126+
a = np.full((Z.shape[0], self.chunks[1]), _DATATYPES_TO_FILL_VALUES[dtype], dtype=dtype)
113127
obs = zarr.group(store=store, overwrite=False)["obs"]
114128
if len(obs) == Z.shape[1]:
115129
obs.append(np.arange(self.chunks[1]) + obs[-1] + 1)
116130
else:
117131
extra_trajs = self._maxids - Z.shape[0]
118132
if len(Z.shape) == 2:
119-
a = np.full((extra_trajs, Z.shape[1]), DATATYPES_TO_FILL_VALUES[dtype], dtype=dtype)
133+
a = np.full((extra_trajs, Z.shape[1]), _DATATYPES_TO_FILL_VALUES[dtype], dtype=dtype)
120134
else:
121-
a = np.full((extra_trajs,), DATATYPES_TO_FILL_VALUES[dtype], dtype=dtype)
135+
a = np.full((extra_trajs,), _DATATYPES_TO_FILL_VALUES[dtype], dtype=dtype)
122136
Z.append(a, axis=axis)
123137
zarr.consolidate_metadata(store)
124138

@@ -194,13 +208,13 @@ def _write_particle_data(self, *, particle_data, pclass, time_interval, time, in
194208
if var.to_write == "once":
195209
data = np.full(
196210
(arrsize[0],),
197-
DATATYPES_TO_FILL_VALUES[dtype],
211+
_DATATYPES_TO_FILL_VALUES[dtype],
198212
dtype=dtype,
199213
)
200214
data[ids_once] = particle_data[var.name][indices_to_write_once]
201215
dims = ["trajectory"]
202216
else:
203-
data = np.full(arrsize, DATATYPES_TO_FILL_VALUES[dtype], dtype=dtype)
217+
data = np.full(arrsize, _DATATYPES_TO_FILL_VALUES[dtype], dtype=dtype)
204218
data[ids, 0] = particle_data[var.name][indices_to_write]
205219
dims = ["trajectory", "obs"]
206220
ds[varout] = xr.DataArray(data=data, dims=dims, attrs=attrs[var.name])
@@ -269,7 +283,7 @@ def _create_variables_attribute_dict(particle: ParticleClass, time_interval: Tim
269283
for var in vars:
270284
fill_value = {}
271285
if var.dtype is not _SAME_AS_FIELDSET_TIME_INTERVAL.VALUE:
272-
fill_value = {"_FillValue": DATATYPES_TO_FILL_VALUES[var.dtype]}
286+
fill_value = {"_FillValue": _DATATYPES_TO_FILL_VALUES[var.dtype]}
273287

274288
attrs[var.name] = {**var.attrs, **fill_value}
275289

0 commit comments

Comments
 (0)