1
1
import logging
2
2
from collections import namedtuple
3
+ from dataclasses import dataclass
3
4
from functools import reduce
4
5
from operator import mul as operator_mul
5
6
from os import sep
190
191
"__ge__",
191
192
)
192
193
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
+
196
212
197
213
# _empty_set = set()
198
214
@@ -989,37 +1005,37 @@ def _binary_operation(self, other, method):
989
1005
coord = None
990
1006
coord_type = None
991
1007
992
- key, coord = f.dimension_coordinate(
1008
+ key, dim_coord = f.dimension_coordinate(
993
1009
item=True, default=(None, None), filter_by_axis=(axis,)
994
1010
)
995
- if coord is not None:
1011
+ if dim_coord is not None:
996
1012
# This axis of the domain has a dimension
997
1013
# coordinate
998
- identity = coord .identity(strict=True, default=None)
1014
+ identity = dim_coord .identity(strict=True, default=None)
999
1015
if identity is None:
1000
1016
# Dimension coordinate has no identity, but it
1001
1017
# may have a recognised axis.
1002
1018
for ctype in ("T", "X", "Y", "Z"):
1003
- if getattr(coord , ctype, False):
1019
+ if getattr(dim_coord , ctype, False):
1004
1020
identity = ctype
1005
1021
break
1006
1022
1007
1023
if identity is None and relaxed_identities:
1008
- identity = coord .identity(relaxed=True, default=None)
1024
+ identity = dim_coord .identity(relaxed=True, default=None)
1009
1025
1010
1026
keys = (key,)
1011
- coords = (coord ,)
1027
+ coords = (dim_coord ,)
1012
1028
else:
1013
1029
discrete_axis = f.has_property('featureType') or f.domain_topologies(todict=True)
1014
1030
if discrete_axis:
1015
1031
x = {}
1016
- for key, coord in f.auxiliary_coordinates(
1032
+ for key, aux_coord in f.auxiliary_coordinates(
1017
1033
filter_by_axis=(axis,),
1018
1034
axis_mode="exact", todict=True
1019
1035
).items():
1020
- identity = coord .identity(strict=True, default=None)
1036
+ identity = aux_coord .identity(strict=True, default=None)
1021
1037
if identity is None and relaxed_identities:
1022
- identity = coord .identity(
1038
+ identity = aux_coord .identity(
1023
1039
relaxed=True, default=None
1024
1040
)
1025
1041
if identity is not None:
@@ -1028,27 +1044,28 @@ def _binary_operation(self, other, method):
1028
1044
if x:
1029
1045
# E.g. {2:3, 4:6, 1:7} -> (1, 2, 4), (7, 3, 6)
1030
1046
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)
1032
1049
else:
1033
1050
identity = None
1034
1051
keys = None
1035
1052
coords = None
1036
1053
else:
1037
- key, coord = f.auxiliary_coordinate(
1054
+ key, aux_coord = f.auxiliary_coordinate(
1038
1055
item=True,
1039
1056
default=(None, None),
1040
1057
filter_by_axis=(axis,),
1041
1058
axis_mode="exact",
1042
1059
)
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)
1050
1067
if identity is None and relaxed_identities:
1051
- identity = coord .identity(
1068
+ identity = aux_coord .identity(
1052
1069
relaxed=True, default=None
1053
1070
)
1054
1071
@@ -1058,35 +1075,37 @@ def _binary_operation(self, other, method):
1058
1075
else:
1059
1076
coord_type = coords[0].construct_type
1060
1077
1061
- out[identity] = _xxx (
1078
+ out[identity] = _data_dimension (
1062
1079
size=f.domain_axis(axis).get_size(),
1063
1080
axis=axis,
1064
1081
keys=keys,
1065
1082
coords=coords,
1066
1083
coord_type=coord_type,
1067
- scalar=( axis not in data_axes) ,
1084
+ axis_in_data_axes= axis in data_axes,
1068
1085
)
1069
1086
1070
1087
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):
1073
1090
a = out0[identity]
1074
1091
if a.size > 1:
1092
+ # Put missing axis into data axes
1075
1093
field1.insert_dimension(y.axis, position=0, inplace=True)
1076
- asdas = False
1094
+ missing_axis_inserted = True
1077
1095
1078
- if y.scalar and asdas :
1096
+ if not missing_axis_inserted and not y.axis_in_data_axes :
1079
1097
del out1[identity]
1080
1098
1081
1099
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):
1084
1102
y = out1[identity]
1085
1103
if y.size > 1:
1104
+ # Put missing axis into data axes
1086
1105
field0.insert_dimension(a.axis, position=0, inplace=True)
1087
- asdas = False
1106
+ missing_axis_inserted = True
1088
1107
1089
- if a.scalar and asdas :
1108
+ if not missing_axis_inserted and not a.axis_in_data_axes :
1090
1109
del out0[identity]
1091
1110
1092
1111
squeeze1 = []
0 commit comments