Skip to content

Commit

Permalink
numpy to np
Browse files Browse the repository at this point in the history
  • Loading branch information
davidhassell committed Jan 8, 2024
1 parent 21e50b2 commit 82634e3
Show file tree
Hide file tree
Showing 13 changed files with 145 additions and 152 deletions.
22 changes: 11 additions & 11 deletions cfdm/test/setup_create_field.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import os
import unittest

import numpy
import numpy as np

faulthandler.enable() # to debug seg faults and timeouts

Expand Down Expand Up @@ -39,11 +39,11 @@ def setUp(self):
def test_create_field(self):
"""Test ab initio creation of a first variation of field."""
# Dimension coordinates
dim1 = cfdm.DimensionCoordinate(data=cfdm.Data(numpy.arange(10.0)))
dim1 = cfdm.DimensionCoordinate(data=cfdm.Data(np.arange(10.0)))
dim1.set_property("standard_name", "grid_latitude")
dim1.set_property("units", "degrees")

data = numpy.arange(9.0) + 20
data = np.arange(9.0) + 20
data[-1] = 34
dim0 = cfdm.DimensionCoordinate(data=cfdm.Data(data))
dim0.set_property("standard_name", "grid_longitude")
Expand All @@ -52,7 +52,7 @@ def test_create_field(self):

array = dim0.data.array

array = numpy.array([array - 0.5, array + 0.5]).transpose((1, 0))
array = np.array([array - 0.5, array + 0.5]).transpose((1, 0))
array[-2, 1] = 30
array[-1, :] = [30, 36]
dim0.set_bounds(cfdm.Bounds(data=cfdm.Data(array)))
Expand All @@ -77,18 +77,18 @@ def test_create_field(self):
bk.set_bounds(cfdm.Bounds(data=cfdm.Data([[14, 26.0]])))

aux2 = cfdm.AuxiliaryCoordinate(
data=cfdm.Data(numpy.arange(-45, 45, dtype="int32").reshape(10, 9))
data=cfdm.Data(np.arange(-45, 45, dtype="int32").reshape(10, 9))
)
aux2.set_property("units", "degree_N")
aux2.set_property("standard_name", "latitude")

aux3 = cfdm.AuxiliaryCoordinate(
data=cfdm.Data(numpy.arange(60, 150, dtype="int32").reshape(9, 10))
data=cfdm.Data(np.arange(60, 150, dtype="int32").reshape(9, 10))
)
aux3.set_property("standard_name", "longitude")
aux3.set_property("units", "degreeE")

array = numpy.ma.array(
array = np.ma.array(
[
"alpha",
"beta",
Expand All @@ -102,20 +102,20 @@ def test_create_field(self):
"kappa",
],
)
array[0] = numpy.ma.masked
array[0] = np.ma.masked
aux4 = cfdm.AuxiliaryCoordinate(data=cfdm.Data(array))
aux4.set_property("long_name", "greek_letters")

# Cell measures
msr0 = cfdm.CellMeasure(
data=cfdm.Data(1 + numpy.arange(90.0).reshape(9, 10) * 1234)
data=cfdm.Data(1 + np.arange(90.0).reshape(9, 10) * 1234)
)
msr0.set_measure("area")
msr0.set_property("units", "km2")
msr0.nc_set_variable("areacella")

# Data
data = cfdm.Data(numpy.arange(90.0).reshape(10, 9))
data = cfdm.Data(np.arange(90.0).reshape(10, 9))

properties = {"units": "m s-1"}

Expand Down Expand Up @@ -201,7 +201,7 @@ def test_create_field(self):
anc.set_property("foo", "bar")
f.set_construct(anc, axes=[axisY])

f.set_property("flag_values", numpy.array([1, 2, 4], "int32"))
f.set_property("flag_values", np.array([1, 2, 4], "int32"))
f.set_property("flag_meanings", "a bb ccc")
f.set_property("flag_masks", [2, 1, 0])

Expand Down
22 changes: 11 additions & 11 deletions cfdm/test/setup_create_field_2.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import os
import unittest

import numpy
import numpy as np

faulthandler.enable() # to debug seg faults and timeouts

Expand Down Expand Up @@ -35,19 +35,19 @@ def setUp(self):
def test_create_field_2(self):
"""Test ab initio creation of a second variation of field."""
# Dimension coordinates
dim1 = cfdm.DimensionCoordinate(data=cfdm.Data(numpy.arange(10.0)))
dim1 = cfdm.DimensionCoordinate(data=cfdm.Data(np.arange(10.0)))
dim1.set_property("standard_name", "projection_y_coordinate")
dim1.set_property("units", "m")

data = numpy.arange(9.0) + 20
data = np.arange(9.0) + 20
data[-1] = 34
dim0 = cfdm.DimensionCoordinate(data=cfdm.Data(data))
dim0.set_property("standard_name", "projection_x_coordinate")
dim0.set_property("units", "m")

array = dim0.data.array

array = numpy.array([array - 0.5, array + 0.5]).transpose((1, 0))
array = np.array([array - 0.5, array + 0.5]).transpose((1, 0))
array[-2, 1] = 30
array[-1, :] = [30, 36]
dim0.set_bounds(cfdm.Bounds(data=cfdm.Data(array)))
Expand All @@ -62,18 +62,18 @@ def test_create_field_2(self):

# Auxiliary coordinates
aux2 = cfdm.AuxiliaryCoordinate(
data=cfdm.Data(numpy.arange(-45, 45, dtype="int32").reshape(10, 9))
data=cfdm.Data(np.arange(-45, 45, dtype="int32").reshape(10, 9))
)
aux2.set_property("units", "degree_N")
aux2.set_property("standard_name", "latitude")

aux3 = cfdm.AuxiliaryCoordinate(
data=cfdm.Data(numpy.arange(60, 150, dtype="int32").reshape(9, 10))
data=cfdm.Data(np.arange(60, 150, dtype="int32").reshape(9, 10))
)
aux3.set_property("standard_name", "longitude")
aux3.set_property("units", "degreeE")

array = numpy.ma.array(
array = np.ma.array(
[
"alpha",
"beta",
Expand All @@ -87,7 +87,7 @@ def test_create_field_2(self):
"kappa",
],
)
array[0] = numpy.ma.masked
array[0] = np.ma.masked
aux4 = cfdm.AuxiliaryCoordinate(data=cfdm.Data(array))
aux4.set_property("standard_name", "greek_letters")

Expand All @@ -101,13 +101,13 @@ def test_create_field_2(self):

# Cell measures
msr0 = cfdm.CellMeasure(
data=cfdm.Data(1 + numpy.arange(90.0).reshape(9, 10) * 1234)
data=cfdm.Data(1 + np.arange(90.0).reshape(9, 10) * 1234)
)
msr0.set_measure("area")
msr0.set_property("units", "km2")

# Data
data = cfdm.Data(numpy.arange(90.0).reshape(10, 9))
data = cfdm.Data(np.arange(90.0).reshape(10, 9))

properties = {"units": "m s-1"}

Expand Down Expand Up @@ -219,7 +219,7 @@ def test_create_field_2(self):
anc.standard_name = "ancillaryC"
f.set_construct(anc, axes=[axisY])

f.set_property("flag_values", numpy.array([1, 2, 4], "int32"))
f.set_property("flag_values", np.array([1, 2, 4], "int32"))
f.set_property("flag_meanings", "a bb ccc")
f.set_property("flag_masks", [2, 1, 0])

Expand Down
24 changes: 12 additions & 12 deletions cfdm/test/setup_create_field_3.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import os
import unittest

import numpy
import numpy as np

faulthandler.enable() # to debug seg faults and timeouts

Expand Down Expand Up @@ -36,20 +36,20 @@ def setUp(self):
def test_create_field_3(self):
"""Test ab initio creation of a third variation of field."""
# Dimension coordinates
data = numpy.arange(9.0) + 20
data = np.arange(9.0) + 20
data[-1] = 34
dim0 = cfdm.DimensionCoordinate(data=cfdm.Data(data))
dim0.set_property("standard_name", "grid_longitude")
dim0.set_property("units", "degrees")

array = dim0.data.array

array = numpy.array([array - 0.5, array + 0.5]).transpose((1, 0))
array = np.array([array - 0.5, array + 0.5]).transpose((1, 0))
array[-2, 1] = 30
array[-1, :] = [30, 36]
dim0.set_bounds(cfdm.Bounds(data=cfdm.Data(array)))

dim1 = cfdm.DimensionCoordinate(data=cfdm.Data(numpy.arange(10.0)))
dim1 = cfdm.DimensionCoordinate(data=cfdm.Data(np.arange(10.0)))
dim1.set_property("standard_name", "grid_latitude")
dim1.set_property("units", "degrees")

Expand All @@ -62,7 +62,7 @@ def test_create_field_3(self):
)
dim2.set_property("computed_standard_name", "altitude")

dim3 = cfdm.DimensionCoordinate(data=cfdm.Data(numpy.array([15.0])))
dim3 = cfdm.DimensionCoordinate(data=cfdm.Data(np.array([15.0])))
dim3.set_property("standard_name", "time")
dim3.set_property("units", "days since 2004-06-01")

Expand All @@ -79,18 +79,18 @@ def test_create_field_3(self):
bk.set_bounds(cfdm.Bounds(data=cfdm.Data([[14, 26.0]])))

aux2 = cfdm.AuxiliaryCoordinate(
data=cfdm.Data(numpy.arange(-45, 45, dtype="int32").reshape(10, 9))
data=cfdm.Data(np.arange(-45, 45, dtype="int32").reshape(10, 9))
)
aux2.set_property("units", "degree_N")
aux2.set_property("standard_name", "latitude")

aux3 = cfdm.AuxiliaryCoordinate(
data=cfdm.Data(numpy.arange(60, 150, dtype="int32").reshape(9, 10))
data=cfdm.Data(np.arange(60, 150, dtype="int32").reshape(9, 10))
)
aux3.set_property("standard_name", "longitude")
aux3.set_property("units", "degreeE")

array = numpy.ma.array(
array = np.ma.array(
[
"alpha",
"beta",
Expand All @@ -104,19 +104,19 @@ def test_create_field_3(self):
"kappa",
],
)
array[0] = numpy.ma.masked
array[0] = np.ma.masked
aux4 = cfdm.AuxiliaryCoordinate(data=cfdm.Data(array))
aux4.set_property("standard_name", "greek_letters")

# Cell measures
msr0 = cfdm.CellMeasure(
data=cfdm.Data(1 + numpy.arange(90.0).reshape(9, 10) * 1234)
data=cfdm.Data(1 + np.arange(90.0).reshape(9, 10) * 1234)
)
msr0.set_measure("area")
msr0.set_property("units", "km2")

# Data
data = cfdm.Data(numpy.arange(90.0).reshape(10, 9))
data = cfdm.Data(np.arange(90.0).reshape(10, 9))

properties = {"units": "m s-1"}

Expand Down Expand Up @@ -219,7 +219,7 @@ def test_create_field_3(self):
anc.standard_name = "ancillaryC"
f.set_construct(anc, axes=[axisY])

f.set_property("flag_values", numpy.array([1, 2, 4], "int32"))
f.set_property("flag_values", np.array([1, 2, 4], "int32"))
f.set_property("flag_meanings", "a bb ccc")
f.set_property("flag_masks", [2, 1, 0])

Expand Down
12 changes: 6 additions & 6 deletions cfdm/test/test_AuxiliaryCoordinate.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import os
import unittest

import numpy
import numpy as np

faulthandler.enable() # to debug seg faults and timeouts

Expand All @@ -19,7 +19,7 @@ class AuxiliaryCoordinateTest(unittest.TestCase):

aux1 = cfdm.AuxiliaryCoordinate()
aux1.standard_name = "latitude"
a = numpy.array(
a = np.array(
[
-30,
-23.5,
Expand All @@ -38,7 +38,7 @@ class AuxiliaryCoordinateTest(unittest.TestCase):
)
aux1.set_data(cfdm.Data(a, "degrees_north"))
bounds = cfdm.Bounds()
b = numpy.empty(a.shape + (2,))
b = np.empty(a.shape + (2,))
b[:, 0] = a - 0.1
b[:, 1] = a + 0.1
bounds.set_data(cfdm.Data(b))
Expand Down Expand Up @@ -115,7 +115,7 @@ def test_AuxiliaryCoordinate_transpose(self):
x = f.auxiliary_coordinates("longitude").value()

bounds = cfdm.Bounds(
data=cfdm.Data(numpy.arange(9 * 10 * 4).reshape(9, 10, 4))
data=cfdm.Data(np.arange(9 * 10 * 4).reshape(9, 10, 4))
)
x.set_bounds(bounds)

Expand All @@ -136,7 +136,7 @@ def test_AuxiliaryCoordinate_squeeze(self):
x = f.auxiliary_coordinates("longitude").value()

bounds = cfdm.Bounds(
data=cfdm.Data(numpy.arange(9 * 10 * 4).reshape(9, 10, 4))
data=cfdm.Data(np.arange(9 * 10 * 4).reshape(9, 10, 4))
)
x.set_bounds(bounds)
x.insert_dimension(1, inplace=True)
Expand All @@ -157,7 +157,7 @@ def test_AuxiliaryCoordinate_interior_ring(self):
"""Test the interior ring access AuxiliaryCoordinate methods."""
c = cfdm.AuxiliaryCoordinate()

i = cfdm.InteriorRing(data=cfdm.Data(numpy.arange(10).reshape(5, 2)))
i = cfdm.InteriorRing(data=cfdm.Data(np.arange(10).reshape(5, 2)))

c.set_interior_ring(i)
self.assertTrue(c.has_interior_ring())
Expand Down
Loading

0 comments on commit 82634e3

Please sign in to comment.