Skip to content

Commit

Permalink
dev
Browse files Browse the repository at this point in the history
  • Loading branch information
davidhassell committed Aug 24, 2023
1 parent 5bd3c5b commit bff67d9
Show file tree
Hide file tree
Showing 7 changed files with 222 additions and 204 deletions.
7 changes: 4 additions & 3 deletions cf/cellconnectivity.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import cfdm

from . import mixin
from .decorators import _deprecated_kwarg_check


class CellConnectivity(mixin.PropertiesData, cfdm.CellConnectivity):
Expand Down Expand Up @@ -139,11 +138,13 @@ def identity(
if nc_only:
if strict:
raise ValueError(
"'strict' and 'nc_only' parameters cannot both be True")
"'strict' and 'nc_only' parameters cannot both be True"
)

if relaxed:
raise ValueError(
"'relaxed' and 'nc_only' parameters cannot both be True")
"'relaxed' and 'nc_only' parameters cannot both be True"
)

n = self.nc_get_variable(None)
if n is not None:
Expand Down
2 changes: 1 addition & 1 deletion cf/cfimplementation.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ def initialise_CFANetCDFArray(
PartNodeCountProperties=PartNodeCountProperties,
Data=Data,
BoundsFromNodesArray=BoundsFromNodesArray,
CellConnectivityArray= CellConnectivityArray,
CellConnectivityArray=CellConnectivityArray,
GatheredArray=GatheredArray,
NetCDFArray=NetCDFArray,
RaggedContiguousArray=RaggedContiguousArray,
Expand Down
7 changes: 6 additions & 1 deletion cf/data/array/boundsfromnodesarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@


class BoundsFromNodesArray(
MeshArrayMixin, CompressedArrayMixin, ArrayMixin, Container, cfdm.BoundsFromNodesArray
MeshArrayMixin,
CompressedArrayMixin,
ArrayMixin,
Container,
cfdm.BoundsFromNodesArray,
):
"""An underlying gathered array.
Expand Down Expand Up @@ -34,6 +38,7 @@ def __repr__(self):
"""
return super().__repr__().replace("<", "<CF ", 1)


# def to_dask_array(self, chunks="auto"):
# """Convert the data to a `dask` array.
#
Expand Down
6 changes: 5 additions & 1 deletion cf/data/array/cellconnectivityarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@


class CellConnectivityArray(
MeshArrayMixin, CompressedArrayMixin, ArrayMixin, Container, cfdm.CellConnectivityArray
MeshArrayMixin,
CompressedArrayMixin,
ArrayMixin,
Container,
cfdm.CellConnectivityArray,
):
"""An underlying gathered array.
Expand Down
56 changes: 43 additions & 13 deletions cf/data/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -795,8 +795,8 @@ def __getitem__(self, indices):
If the shape of the data is unknown then it is calculated
immediately by executing all delayed operations.
. seealso:: `__setitem__`, `__keepdims_indexing__`,
`__orthogonal_indexing__`
. seealso:: `vindex`, `__keepdims_indexing__`,
`__orthogonal_indexing__`, `__setitem__`
:Returns:
Expand Down Expand Up @@ -5205,7 +5205,38 @@ def mask(self):

return mask_data_obj

# `arctan2`, AT2 seealso
# @property
def vindex(self, *indices):
"""Vectorized indexing with broadcasting.
This is equivalent to numpy’s advanced indexing, using arrays
that are broadcast against each other. This allows for
pointwise indexing.
.. versionadded:: TODOUGRIDVER
.. seealso:: `__getitem__`
**Examples**
>>> d = cf.Data([[1, 2, 3], [4, 5, 6], [7, 8, 9]])
>>> print(d.vindex([0, 1, 2], [0, 1, 2]).array)
[1 5 9]
>>> print(d.vindex(0, [0, 0, 1]).array)
[1 1 2]
"""
new = self.copy(array=False)
dx = self.to_dask_array()
dx = dx.vindex[indices]
new._set_dask(dx)

if self.nc_hdf5_chunksizes() and new.shape != self.shape:
# Delete hdf5 chunksizes when the shape has changed.
new.nc_clear_hdf5_chunksizes()

return new

@_inplace_enabled(default=False)
def arctan(self, inplace=False):
"""Take the trigonometric inverse tangent of the data element-
Expand Down Expand Up @@ -7337,7 +7368,7 @@ def asdata(cls, d, dtype=None, copy=False):
@classmethod
def arctan2(cls, y, x):
"""Element-wise arc tangent of ``y/x`` with coorect quadrant.
The quadrant (i.e. branch) is chosen so that ``arctan2(y, x)``
is the signed angle in radians between the ray ending at the
origin and passing through the point ``(1, 0)``, and the ray
Expand All @@ -7347,11 +7378,11 @@ def arctan2(cls, y, x):
convention, this function is defined for ``x = +/-0`` and for
either or both of ``y = +/-inf`` and ``x = +/-inf`` (see Notes
for specific values).
`arctan2` is identical to the ``atan2`` function of the
underlying C library. The following special values are defined
in the C standard:
====== ====== =================
*y* *x* ``arctan2(y, x)``
====== ====== =================
Expand All @@ -7362,7 +7393,7 @@ def arctan2(cls, y, x):
+/-inf +inf +/- (pi/4)
+/-inf -inf +/- (3*pi/4)
====== ====== =================
Note that ``+0`` and ``-0`` are distinct floating point
numbers, as are ``+inf`` and ``-inf``.
Expand All @@ -7385,28 +7416,27 @@ def arctan2(cls, y, x):
TODOUGRID
"""
try:
try:
y = y.to_dask_array()
except AttributeError:
y = cls.asdata(y).to_dask_array()

try:
try:
x = x.to_dask_array()
except AttributeError:
x = cls.asdata(x).to_dask_array()

mask = da.ma.getmaskarray(y) | da.ma.getmaskarray(x)
y = da.ma.filled(y, 1)
x = da.ma.filled(x, 1)

dx = da.arctan2(y, x)
dx = da.ma.masked_array(dx, mask=mask)

return cls(dx, units=_units_radians)

@_inplace_enabled(default=False)
def compressed(self, inplace=False):

"""Return all non-masked values in a one dimensional data array.
Not to be confused with compression by convention (see the
Expand Down
7 changes: 4 additions & 3 deletions cf/domaintopology.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import cfdm

from . import mixin
from .decorators import _deprecated_kwarg_check


class DomainTopology(mixin.PropertiesData, cfdm.DomainTopology):
Expand Down Expand Up @@ -139,11 +138,13 @@ def identity(
if nc_only:
if strict:
raise ValueError(
"'strict' and 'nc_only' parameters cannot both be True")
"'strict' and 'nc_only' parameters cannot both be True"
)

if relaxed:
raise ValueError(
"'relaxed' and 'nc_only' parameters cannot both be True")
"'relaxed' and 'nc_only' parameters cannot both be True"
)

n = self.nc_get_variable(None)
if n is not None:
Expand Down
Loading

0 comments on commit bff67d9

Please sign in to comment.