Skip to content

Commit d7d35e2

Browse files
committed
dev
1 parent cdefcef commit d7d35e2

File tree

1 file changed

+51
-32
lines changed

1 file changed

+51
-32
lines changed

cf/field.py

Lines changed: 51 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import logging
22
from collections import namedtuple
3+
from dataclasses import dataclass
34
from functools import reduce
45
from operator import mul as operator_mul
56
from os import sep
@@ -190,9 +191,24 @@
190191
"__ge__",
191192
)
192193

193-
_xxx = namedtuple(
194-
"data_dimension", ["size", "axis", "keys", "coords", "coord_type", "scalar"]
195-
)
194+
#_xxx = namedtuple(
195+
# "data_dimension", ["size", "axis", "keys", "coords", "coord_type", "scalar#"]
196+
#)
197+
198+
@dataclass()
199+
class _data_dimension:
200+
"""TODO
201+
202+
.. versionaddedd:: NEXTVERSION
203+
204+
"""
205+
size: int = -1
206+
axis: str = ""
207+
keys: tuple = ()
208+
coords: tuple = ()
209+
coord_type: tuple = ()
210+
axis_in_data_axes: bool = True
211+
196212

197213
# _empty_set = set()
198214

@@ -989,37 +1005,37 @@ def _binary_operation(self, other, method):
9891005
coord = None
9901006
coord_type = None
9911007

992-
key, coord = f.dimension_coordinate(
1008+
key, dim_coord = f.dimension_coordinate(
9931009
item=True, default=(None, None), filter_by_axis=(axis,)
9941010
)
995-
if coord is not None:
1011+
if dim_coord is not None:
9961012
# This axis of the domain has a dimension
9971013
# coordinate
998-
identity = coord.identity(strict=True, default=None)
1014+
identity = dim_coord.identity(strict=True, default=None)
9991015
if identity is None:
10001016
# Dimension coordinate has no identity, but it
10011017
# may have a recognised axis.
10021018
for ctype in ("T", "X", "Y", "Z"):
1003-
if getattr(coord, ctype, False):
1019+
if getattr(dim_coord, ctype, False):
10041020
identity = ctype
10051021
break
10061022

10071023
if identity is None and relaxed_identities:
1008-
identity = coord.identity(relaxed=True, default=None)
1024+
identity = dim_coord.identity(relaxed=True, default=None)
10091025

10101026
keys = (key,)
1011-
coords = (coord,)
1027+
coords = (dim_coord,)
10121028
else:
10131029
discrete_axis = f.has_property('featureType') or f.domain_topologies(todict=True)
10141030
if discrete_axis:
10151031
x = {}
1016-
for key, coord in f.auxiliary_coordinates(
1032+
for key, aux_coord in f.auxiliary_coordinates(
10171033
filter_by_axis=(axis,),
10181034
axis_mode="exact", todict=True
10191035
).items():
1020-
identity = coord.identity(strict=True, default=None)
1036+
identity = aux_coord.identity(strict=True, default=None)
10211037
if identity is None and relaxed_identities:
1022-
identity = coord.identity(
1038+
identity = aux_coord.identity(
10231039
relaxed=True, default=None
10241040
)
10251041
if identity is not None:
@@ -1028,27 +1044,28 @@ def _binary_operation(self, other, method):
10281044
if x:
10291045
# E.g. {2:3, 4:6, 1:7} -> (1, 2, 4), (7, 3, 6)
10301046
identity, keys = tuple(zip(*sorted(x.items())))
1031-
coords = tuple(f.auxiliary_coordinate(key) for key in keys)
1047+
coords = tuple(f.auxiliary_coordinate(key)
1048+
for key in keys)
10321049
else:
10331050
identity = None
10341051
keys = None
10351052
coords = None
10361053
else:
1037-
key, coord = f.auxiliary_coordinate(
1054+
key, aux_coord = f.auxiliary_coordinate(
10381055
item=True,
10391056
default=(None, None),
10401057
filter_by_axis=(axis,),
10411058
axis_mode="exact",
10421059
)
1043-
if coord is not None:
1044-
# This axis of the domain does not have a
1045-
# dimension coordinate but it does have
1046-
# exactly one 1-d auxiliary coordinate, so
1047-
# that will do.
1048-
coords = (coord,)
1049-
identity = coord.identity(strict=True, default=None)
1060+
if aux_coord is not None:
1061+
# This non-discrete axis of the domain
1062+
# does not have a dimension coordinate but
1063+
# it does have exactly one 1-d auxiliary
1064+
# coordinate, so that will do.
1065+
coords = (aux_coord,)
1066+
identity = aux_coord.identity(strict=True, default=None)
10501067
if identity is None and relaxed_identities:
1051-
identity = coord.identity(
1068+
identity = aux_coord.identity(
10521069
relaxed=True, default=None
10531070
)
10541071

@@ -1058,35 +1075,37 @@ def _binary_operation(self, other, method):
10581075
else:
10591076
coord_type = coords[0].construct_type
10601077

1061-
out[identity] = _xxx(
1078+
out[identity] = _data_dimension(
10621079
size=f.domain_axis(axis).get_size(),
10631080
axis=axis,
10641081
keys=keys,
10651082
coords=coords,
10661083
coord_type=coord_type,
1067-
scalar=(axis not in data_axes),
1084+
axis_in_data_axes=axis in data_axes,
10681085
)
10691086

10701087
for identity, y in tuple(out1.items()):
1071-
asdas = True
1072-
if y.scalar and identity in out0 and isinstance(identity, str):
1088+
missing_axis_inserted = False
1089+
if not y.axis_in_data_axes and identity in out0 and isinstance(identity, str):
10731090
a = out0[identity]
10741091
if a.size > 1:
1092+
# Put missing axis into data axes
10751093
field1.insert_dimension(y.axis, position=0, inplace=True)
1076-
asdas = False
1094+
missing_axis_inserted = True
10771095

1078-
if y.scalar and asdas:
1096+
if not missing_axis_inserted and not y.axis_in_data_axes:
10791097
del out1[identity]
10801098

10811099
for identity, a in tuple(out0.items()):
1082-
asdas = True
1083-
if a.scalar and identity in out1 and isinstance(identity, str):
1100+
missing_axis_inserted = False
1101+
if not a.axis_in_data_axes and identity in out1 and isinstance(identity, str):
10841102
y = out1[identity]
10851103
if y.size > 1:
1104+
# Put missing axis into data axes
10861105
field0.insert_dimension(a.axis, position=0, inplace=True)
1087-
asdas = False
1106+
missing_axis_inserted = True
10881107

1089-
if a.scalar and asdas:
1108+
if not missing_axis_inserted and not a.axis_in_data_axes:
10901109
del out0[identity]
10911110

10921111
squeeze1 = []

0 commit comments

Comments
 (0)