Skip to content

Commit c5c5c5e

Browse files
committed
Merge branch 'dev' of github.com:MeteoSwiss/pyart into dev
2 parents 000367f + 8290b5f commit c5c5c5e

File tree

1 file changed

+29
-14
lines changed

1 file changed

+29
-14
lines changed

pyart/core/radar_spectra.py

Lines changed: 29 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -287,20 +287,35 @@ def add_field(self, field_name, dic, replace_existing=False):
287287
raise ValueError(err)
288288
if "data" not in dic:
289289
raise KeyError("dic must contain a 'data' key")
290-
if dic["data"].shape != (self.nrays, self.ngates, self.npulses_max):
291-
t = (
292-
self.nrays,
293-
self.ngates,
294-
self.npulses_max,
295-
dic["data"].shape[0],
296-
dic["data"].shape[1],
297-
dic["data"].shape[2],
298-
)
299-
err = (
300-
"'data' has invalid shape, "
301-
+ f"should be ({t[0]}, {t[1]}, {t[2]}) but is ({t[3]}, {t[4]}, {t[5]})"
302-
)
303-
raise ValueError(err)
290+
# Check if field is in spectral shape (self.nrays, self.ngates, self.npulses_max)
291+
if len(dic["data"]) == 3:
292+
if dic["data"].shape != (self.nrays, self.ngates, self.npulses_max):
293+
t = (
294+
self.nrays,
295+
self.ngates,
296+
self.npulses_max,
297+
dic["data"].shape[0],
298+
dic["data"].shape[1],
299+
dic["data"].shape[2],
300+
)
301+
err = (
302+
"'data' has invalid shape, "
303+
+ f"should be ({t[0]}, {t[1]}, {t[2]}) but is ({t[3]}, {t[4]}, {t[5]})"
304+
)
305+
raise ValueError(err)
306+
elif len(dic["data"]) == 2:
307+
if dic["data"].shape != (self.nrays, self.ngates):
308+
t = (
309+
self.nrays,
310+
self.ngates,
311+
dic["data"].shape[0],
312+
dic["data"].shape[1],
313+
)
314+
err = (
315+
"'data' has invalid shape, "
316+
+ f"should be ({t[0]}, {t[1]}) but is ({t[2]}, {t[3]})"
317+
)
318+
raise ValueError(err)
304319
# add the field
305320
self.fields[field_name] = dic
306321

0 commit comments

Comments
 (0)