Improve `cf.Field.__getitem__` performance by not re-calculating axis cyclicity by davidhassell · Pull Request #745 · NCAS-CMS/cf-python

Expand Up @@ -441,6 +441,22 @@ def __getitem__(self, indices): for axis, size in zip(data_axes, new_data.shape): domain_axes[axis].set_size(size)
# Record which axes were cyclic before the subspace org_cyclic = [data_axes.index(axis) for axis in new.cyclic()]
# Set the subspaced data new.set_data(new_data, axes=data_axes, copy=False)
# Update axis cylcicity. Note that this can only entail # setting an originally cyclic axis to be non-cyclic. Doing # this now enables us to disable the (possibly very slow) # automatic check for cyclicity on the 'set_construct' calls # below. if org_cyclic: new_cyclic = new_data.cyclic() [new.cyclic(i, iscyclic=False) for i in org_cyclic if i not in new_cyclic]

# ------------------------------------------------------------ # Subspace constructs with data # ------------------------------------------------------------ Expand Down Expand Up @@ -507,6 +523,7 @@ def __getitem__(self, indices): key=key, axes=construct_axes, copy=False, autocyclic={"no-op": True}, )
new.set_data(new_data, axes=data_axes, copy=False) Expand Down