Skip to content

Commit

Permalink
"deactivate" vertical axis in Grid for now
Browse files Browse the repository at this point in the history
While the vertical axis in `Grid` is perfectly functional, it should not be exposed through the API until 3D components are effectively supported (i.e. until contributors are able to tell the framework if they are expecting 2D fields or 3D fields or both).

Rather than deleting the functionality, comments have been used wherever needed to prevent users from creating a 3D `Grid`.  That involves:
- removing the parameters in instantiation methods,
- removing references to these parameters in docstrings, and
- removing Z related properties from API reference (even though these still exist, and in fact are still accessible but will return `None`).
  • Loading branch information
Thibault Hallouin committed Nov 15, 2021
1 parent da413f5 commit 6aca7f2
Show file tree
Hide file tree
Showing 14 changed files with 569 additions and 366 deletions.
784 changes: 523 additions & 261 deletions cm4twc/space.py

Large diffs are not rendered by default.

7 changes: 0 additions & 7 deletions docs/_doc_src/api/attributes/cm4twc.BritishNationalGrid.Z.rst

This file was deleted.

This file was deleted.

This file was deleted.

7 changes: 0 additions & 7 deletions docs/_doc_src/api/attributes/cm4twc.LatLonGrid.Z.rst

This file was deleted.

7 changes: 0 additions & 7 deletions docs/_doc_src/api/attributes/cm4twc.LatLonGrid.Z_bounds.rst

This file was deleted.

7 changes: 0 additions & 7 deletions docs/_doc_src/api/attributes/cm4twc.LatLonGrid.Z_name.rst

This file was deleted.

7 changes: 0 additions & 7 deletions docs/_doc_src/api/attributes/cm4twc.RotatedLatLonGrid.Z.rst

This file was deleted.

This file was deleted.

This file was deleted.

6 changes: 3 additions & 3 deletions docs/_doc_src/api/classes/cm4twc.BritishNationalGrid.rst
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,13 @@ Attributes
~cm4twc.BritishNationalGrid.axes
~cm4twc.BritishNationalGrid.X
~cm4twc.BritishNationalGrid.Y
~cm4twc.BritishNationalGrid.Z
.. ~cm4twc.BritishNationalGrid.Z
~cm4twc.BritishNationalGrid.X_bounds
~cm4twc.BritishNationalGrid.Y_bounds
~cm4twc.BritishNationalGrid.Z_bounds
.. ~cm4twc.BritishNationalGrid.Z_bounds
~cm4twc.BritishNationalGrid.X_name
~cm4twc.BritishNationalGrid.Y_name
~cm4twc.BritishNationalGrid.Z_name
.. ~cm4twc.BritishNationalGrid.Z_name
~cm4twc.BritishNationalGrid.land_sea_mask
~cm4twc.BritishNationalGrid.flow_direction
~cm4twc.BritishNationalGrid.cell_area
6 changes: 3 additions & 3 deletions docs/_doc_src/api/classes/cm4twc.LatLonGrid.rst
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,13 @@ Attributes
~cm4twc.LatLonGrid.axes
~cm4twc.LatLonGrid.X
~cm4twc.LatLonGrid.Y
~cm4twc.LatLonGrid.Z
.. ~cm4twc.LatLonGrid.Z
~cm4twc.LatLonGrid.X_bounds
~cm4twc.LatLonGrid.Y_bounds
~cm4twc.LatLonGrid.Z_bounds
.. ~cm4twc.LatLonGrid.Z_bounds
~cm4twc.LatLonGrid.X_name
~cm4twc.LatLonGrid.Y_name
~cm4twc.LatLonGrid.Z_name
.. ~cm4twc.LatLonGrid.Z_name
~cm4twc.LatLonGrid.land_sea_mask
~cm4twc.LatLonGrid.flow_direction
~cm4twc.LatLonGrid.cell_area
6 changes: 3 additions & 3 deletions docs/_doc_src/api/classes/cm4twc.RotatedLatLonGrid.rst
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,13 @@ Attributes
~cm4twc.RotatedLatLonGrid.axes
~cm4twc.RotatedLatLonGrid.X
~cm4twc.RotatedLatLonGrid.Y
~cm4twc.RotatedLatLonGrid.Z
.. ~cm4twc.RotatedLatLonGrid.Z
~cm4twc.RotatedLatLonGrid.X_bounds
~cm4twc.RotatedLatLonGrid.Y_bounds
~cm4twc.RotatedLatLonGrid.Z_bounds
.. ~cm4twc.RotatedLatLonGrid.Z_bounds
~cm4twc.RotatedLatLonGrid.X_name
~cm4twc.RotatedLatLonGrid.Y_name
~cm4twc.RotatedLatLonGrid.Z_name
.. ~cm4twc.RotatedLatLonGrid.Z_name
~cm4twc.RotatedLatLonGrid.land_sea_mask
~cm4twc.RotatedLatLonGrid.flow_direction
~cm4twc.RotatedLatLonGrid.cell_area
70 changes: 37 additions & 33 deletions tests/test_space.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ def test_init_variants(self):
longitude=np.array([-1.5, -0.5, 0.5]),
latitude_bounds=np.array([[51, 52], [52, 53], [53, 54], [54, 55]]),
longitude_bounds=[[-2, -1], [-1, 0], [0, 1]],
altitude=[2],
altitude_bounds=[0, 4]
# altitude=[2],
# altitude_bounds=[0, 4]
)

# create a spacedomain using constructor method based on parameters
Expand All @@ -63,22 +63,22 @@ def test_init_variants(self):
latitude_resolution=1,
longitude_extent=(-2, 1),
longitude_resolution=1,
altitude_extent=(0, 4),
altitude_resolution=4
# altitude_extent=(0, 4),
# altitude_resolution=4
)

self.assertEqual(sd1, sd2)

# create a spacedomain using constructor method based on field
dataset = get_dummy_dataset('surfacelayer', 'daily', '1deg')
field = dataset[list(dataset.keys())[0]].field
sd3 = cm4twc.LatLonGrid.from_field(field)

# check that they are not equal
# (because field from dummy data has no Z coordinate)
self.assertNotEqual(sd1, sd3)
# check that they are equal if Z axis is ignored
self.assertTrue(sd1.is_space_equal_to(sd3.to_field(), ignore_z=True))
# # create a spacedomain using constructor method based on field
# dataset = get_dummy_dataset('surfacelayer', 'daily', '1deg')
# field = dataset[list(dataset.keys())[0]].field
# sd3 = cm4twc.LatLonGrid.from_field(field)
#
# # check that they are not equal
# # (because field from dummy data has no Z coordinate)
# self.assertNotEqual(sd1, sd3)
# # check that they are equal if Z axis is ignored
# self.assertTrue(sd1.is_space_equal_to(sd3.to_field(), ignore_z=True))


class TestGridComparison(unittest.TestCase):
Expand Down Expand Up @@ -135,9 +135,11 @@ def test_different_resolutions(self):
with self.subTest(spacedomain=cls_name):
# create a simple spacedomain
params = {
"_".join([self.axis_name[cls_name][axis], prop]): val
"_".join([self.axis_name[cls_name][axis], prop]):
self.extent_resolution[cls_name][prop][axis]
for prop in ['extent', 'resolution']
for axis, val in self.extent_resolution[cls_name][prop].items()
# for axis in ['X', 'Y', 'Z']
for axis in ['X', 'Y']
}

extras = self.extras.get(cls_name, {})
Expand All @@ -160,9 +162,11 @@ def test_different_regions(self):
with self.subTest(spacedomain=cls_name):
# create a simple spacedomain
params = {
"_".join([self.axis_name[cls_name][axis], prop]): val
"_".join([self.axis_name[cls_name][axis], prop]):
self.extent_resolution[cls_name][prop][axis]
for prop in ['extent', 'resolution']
for axis, val in self.extent_resolution[cls_name][prop].items()
# for axis in ['X', 'Y', 'Z']
for axis in ['X', 'Y']
}

extras = self.extras.get(cls_name, {})
Expand All @@ -179,21 +183,21 @@ def test_different_regions(self):
# check that these are not equal
self.assertNotEqual(sd1, sd2)

# create another spacedomain with a smaller Z axis extent
params3 = deepcopy(params)
params3["{}_resolution".format(self.axis_name[cls_name]['Z'])] = (
params3["{}_resolution".format(self.axis_name[cls_name]['Z'])] / 2
)
params3["{}_extent".format(self.axis_name[cls_name]['Z'])][1] -= (
params3["{}_resolution".format(self.axis_name[cls_name]['Z'])]
)
sd3 = spacedomain.from_extent_and_resolution(**params3, **extras)

# check that they are not equal
# (because of different on Z axis)
self.assertNotEqual(sd1, sd3)
# check that they are equal if Z axis is ignored
self.assertTrue(sd1.is_space_equal_to(sd3.to_field(), ignore_z=True))
# # create another spacedomain with a smaller Z axis extent
# params3 = deepcopy(params)
# params3["{}_resolution".format(self.axis_name[cls_name]['Z'])] = (
# params3["{}_resolution".format(self.axis_name[cls_name]['Z'])] / 2
# )
# params3["{}_extent".format(self.axis_name[cls_name]['Z'])][1] -= (
# params3["{}_resolution".format(self.axis_name[cls_name]['Z'])]
# )
# sd3 = spacedomain.from_extent_and_resolution(**params3, **extras)
#
# # check that they are not equal
# # (because of different on Z axis)
# self.assertNotEqual(sd1, sd3)
# # check that they are equal if Z axis is ignored
# self.assertTrue(sd1.is_space_equal_to(sd3.to_field(), ignore_z=True))


if __name__ == '__main__':
Expand Down

0 comments on commit 6aca7f2

Please sign in to comment.