Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

convert docs print statements #4209

Merged
merged 1 commit into from
Jun 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions lib/iris/fileformats/um/_optimal_array_structuring.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,11 @@ def optimal_array_structure(ordering_elements, actual_values_elements=None):
>>> dims_shape, dim_names, arrays_and_dims = \
... optdims.optimal_array_structure(elements_structure,
... elements_values)
>>> print dims_shape
>>> print(dims_shape)
(2, 3)
>>> print dim_names
>>> print(dim_names)
set(['a', 'b'])
>>> print arrays_and_dims
>>> print(arrays_and_dims)
{'a': (array([10, 12]), (0,)), 'c': (array([[9, 3, 5],
[2, 7, 1]]), (0, 1)), 'b': (array([15, 16, 17]), (1,))}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def setUp(self):
# Snapshot result, printed with ...
# >>> np.set_printoptions(linewidth=180,
# formatter={'float':lambda x:'{:-09.3f}'.format(x)})
# >>> print repr(coord.points)
# >>> print(repr(coord.points))
self.basic_derived_result = np.array(
[
[
Expand Down
88 changes: 60 additions & 28 deletions lib/iris/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -1583,25 +1583,41 @@ def promote_aux_coord_to_dim_coord(cube, name_or_coord):
:attr:`var_name` of an instance of an instance of
:class:`iris.coords.AuxCoord`.

For example::
For example,

.. testsetup:: promote

import iris
from iris.coord_categorisation import add_year
from iris.util import demote_dim_coord_to_aux_coord, promote_aux_coord_to_dim_coord
cube = iris.load_cube(iris.sample_data_path("E1_north_america.nc"))
cube.remove_coord("forecast_reference_time")
cube.remove_coord("height")
cube.attributes = {}
cube.cell_methods = ()
add_year(cube, "time")

.. doctest:: promote

>>> print cube
air_temperature / (K) (time: 12; latitude: 73; longitude: 96)
>>> print(cube)
air_temperature / (K) (time: 240; latitude: 37; longitude: 49)
Dimension coordinates:
time x - -
latitude - x -
longitude - - x
time x - -
latitude - x -
longitude - - x
Auxiliary coordinates:
year x - -
>>> promote_aux_coord_to_dim_coord(cube, 'year')
>>> print cube
air_temperature / (K) (year: 12; latitude: 73; longitude: 96)
forecast_period x - -
year x - -
>>> promote_aux_coord_to_dim_coord(cube, "year")
>>> print(cube)
air_temperature / (K) (year: 240; latitude: 37; longitude: 49)
Dimension coordinates:
year x - -
latitude - x -
longitude - - x
year x - -
latitude - x -
longitude - - x
Auxiliary coordinates:
time x - -
forecast_period x - -
time x - -

"""
from iris.coords import Coord, DimCoord
Expand Down Expand Up @@ -1693,25 +1709,41 @@ def demote_dim_coord_to_aux_coord(cube, name_or_coord):
:attr:`var_name` of an instance of an instance of
:class:`iris.coords.DimCoord`.

For example::
For example,

.. testsetup:: demote

import iris
from iris.coord_categorisation import add_year
from iris.util import demote_dim_coord_to_aux_coord, promote_aux_coord_to_dim_coord
cube = iris.load_cube(iris.sample_data_path("E1_north_america.nc"))
cube.remove_coord("forecast_reference_time")
cube.remove_coord("height")
cube.attributes = {}
cube.cell_methods = ()
add_year(cube, "time")

.. doctest:: demote

>>> print cube
air_temperature / (K) (time: 12; latitude: 73; longitude: 96)
>>> print(cube)
air_temperature / (K) (time: 240; latitude: 37; longitude: 49)
Dimension coordinates:
time x - -
latitude - x -
longitude - - x
time x - -
latitude - x -
longitude - - x
Auxiliary coordinates:
year x - -
>>> demote_dim_coord_to_aux_coord(cube, 'time')
>>> print cube
air_temperature / (K) (-- : 12; latitude: 73; longitude: 96)
forecast_period x - -
year x - -
>>> demote_dim_coord_to_aux_coord(cube, "time")
>>> print(cube)
air_temperature / (K) (-- : 240; latitude: 37; longitude: 49)
Dimension coordinates:
latitude - x -
longitude - - x
latitude - x -
longitude - - x
Auxiliary coordinates:
time x - -
year x - -
forecast_period x - -
time x - -
year x - -

"""
from iris.coords import Coord
Expand Down