Skip to content
Closed
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
22 changes: 12 additions & 10 deletions .cirrus.yml
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ linux_minimal_task:
PY_VER: 3.6
env:
PY_VER: 3.7
env:
PY_VER: 3.8
name: "${CIRRUS_OS}: py${PY_VER} tests (minimal)"
container:
image: gcc:latest
Expand All @@ -107,7 +109,7 @@ linux_minimal_task:
tests_script:
- echo "[Resources]" > ${SITE_CFG}
- echo "doc_dir = ${CIRRUS_WORKING_DIR}/docs" >> ${SITE_CFG}
- nox --session tests
- nox --session tests -- --verbose


#
Expand All @@ -119,6 +121,8 @@ linux_task:
PY_VER: 3.6
env:
PY_VER: 3.7
env:
PY_VER: 3.8
name: "${CIRRUS_OS}: py${PY_VER} tests (full)"
container:
image: gcc:latest
Expand All @@ -137,7 +141,7 @@ linux_task:
- echo "[Resources]" > ${SITE_CFG}
- echo "test_data_dir = ${IRIS_TEST_DATA_DIR}/test_data" >> ${SITE_CFG}
- echo "doc_dir = ${CIRRUS_WORKING_DIR}/docs" >> ${SITE_CFG}
- nox --session tests
- nox --session tests -- --verbose


#
Expand All @@ -146,9 +150,7 @@ linux_task:
gallery_task:
matrix:
env:
PY_VER: 3.6
env:
PY_VER: 3.7
PY_VER: 3.8
name: "${CIRRUS_OS}: py${PY_VER} doc tests (gallery)"
container:
image: gcc:latest
Expand All @@ -167,7 +169,7 @@ gallery_task:
- echo "[Resources]" > ${SITE_CFG}
- echo "test_data_dir = ${IRIS_TEST_DATA_DIR}/test_data" >> ${SITE_CFG}
- echo "doc_dir = ${CIRRUS_WORKING_DIR}/docs" >> ${SITE_CFG}
- nox --session gallery
- nox --session gallery -- --verbose


#
Expand All @@ -176,7 +178,7 @@ gallery_task:
doctest_task:
matrix:
env:
PY_VER: 3.7
PY_VER: 3.8
name: "${CIRRUS_OS}: py${PY_VER} doc tests"
container:
image: gcc:latest
Expand All @@ -201,7 +203,7 @@ doctest_task:
- mkdir -p ${MPL_RC_DIR}
- echo "backend : agg" > ${MPL_RC_FILE}
- echo "image.cmap : viridis" >> ${MPL_RC_FILE}
- nox --session doctest
- nox --session doctest -- --verbose


#
Expand All @@ -210,7 +212,7 @@ doctest_task:
link_task:
matrix:
env:
PY_VER: 3.7
PY_VER: 3.8
name: "${CIRRUS_OS}: py${PY_VER} doc link check"
container:
image: gcc:latest
Expand All @@ -224,4 +226,4 @@ link_task:
- mkdir -p ${MPL_RC_DIR}
- echo "backend : agg" > ${MPL_RC_FILE}
- echo "image.cmap : viridis" >> ${MPL_RC_FILE}
- nox --session linkcheck
- nox --session linkcheck -- --verbose
134 changes: 59 additions & 75 deletions docs/gallery_code/meteorology/plot_COP_maps.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,34 +38,32 @@ def cop_metadata_callback(cube, field, filename):
filename.
"""

# Extract the experiment name (such as a1b or e1) from the filename (in
# this case it is just the parent folder's name)
containing_folder = os.path.dirname(filename)
experiment_label = os.path.basename(containing_folder)
# Extract the experiment name (such as A1B or E1) from the filename (in
# this case it is just the start of the file name, before the first ".").
fname = os.path.basename(filename) # filename without path.
experiment_label = fname.split(".")[0]

# Create a coordinate with the experiment label in it
# Create a coordinate with the experiment label in it...
exp_coord = coords.AuxCoord(
experiment_label, long_name="Experiment", units="no_unit"
)

# and add it to the cube
# ...and add it to the cube.
cube.add_aux_coord(exp_coord)


def main():
# Load e1 and a1 using the callback to update the metadata
e1 = iris.load_cube(
iris.sample_data_path("E1.2098.pp"), callback=cop_metadata_callback
)
a1b = iris.load_cube(
iris.sample_data_path("A1B.2098.pp"), callback=cop_metadata_callback
)
# Load E1 and A1B scenarios using the callback to update the metadata.
scenario_files = [
iris.sample_data_path(fname) for fname in ["E1.2098.pp", "A1B.2098.pp"]
]
scenarios = iris.load(scenario_files, callback=cop_metadata_callback)

# Load the global average data and add an 'Experiment' coord it
global_avg = iris.load_cube(iris.sample_data_path("pre-industrial.pp"))
# Load the preindustrial reference data.
preindustrial = iris.load_cube(iris.sample_data_path("pre-industrial.pp"))

# Define evenly spaced contour levels: -2.5, -1.5, ... 15.5, 16.5 with the
# specific colours
# specific colours.
levels = np.arange(20) - 2.5
red = (
np.array(
Expand Down Expand Up @@ -147,81 +145,67 @@ def main():
)

# Put those colours into an array which can be passed to contourf as the
# specific colours for each level
colors = np.array([red, green, blue]).T
# specific colours for each level.
colors = np.stack([red, green, blue], axis=1)

# Subtract the global
# Make a wider than normal figure to house two maps side-by-side.
fig, ax_array = plt.subplots(1, 2, figsize=(12, 5))

# Iterate over each latitude longitude slice for both e1 and a1b scenarios
# simultaneously
for e1_slice, a1b_slice in zip(
e1.slices(["latitude", "longitude"]),
a1b.slices(["latitude", "longitude"]),
# Loop over our scenarios to make a plot for each.
for ax, experiment, label in zip(
ax_array, ["E1", "A1B"], ["E1", "A1B-Image"]
):

time_coord = a1b_slice.coord("time")

# Calculate the difference from the mean
delta_e1 = e1_slice - global_avg
delta_a1b = a1b_slice - global_avg

# Make a wider than normal figure to house two maps side-by-side
fig = plt.figure(figsize=(12, 5))

# Get the time datetime from the coordinate
time = time_coord.units.num2date(time_coord.points[0])
# Set a title for the entire figure, giving the time in a nice format
# of "MonthName Year". Also, set the y value for the title so that it
# is not tight to the top of the plot.
fig.suptitle(
"Annual Temperature Predictions for " + time.strftime("%Y"),
y=0.9,
fontsize=18,
exp_cube = scenarios.extract_cube(
iris.Constraint(Experiment=experiment)
)
time_coord = exp_cube.coord("time")

# Add the first subplot showing the E1 scenario
plt.subplot(121)
plt.title("HadGEM2 E1 Scenario", fontsize=10)
iplt.contourf(delta_e1, levels, colors=colors, extend="both")
plt.gca().coastlines()
# get the current axes' subplot for use later on
plt1_ax = plt.gca()
# Calculate the difference from the preindustial control run.
exp_anom_cube = exp_cube - preindustrial

# Add the second subplot showing the A1B scenario
plt.subplot(122)
plt.title("HadGEM2 A1B-Image Scenario", fontsize=10)
# Plot this anomaly.
plt.sca(ax)
ax.set_title(f"HadGEM2 {label} Scenario", fontsize=10)
contour_result = iplt.contourf(
delta_a1b, levels, colors=colors, extend="both"
exp_anom_cube, levels, colors=colors, extend="both"
)
plt.gca().coastlines()
# get the current axes' subplot for use later on
plt2_ax = plt.gca()

# Now add a colourbar who's leftmost point is the same as the leftmost
# point of the left hand plot and rightmost point is the rightmost
# point of the right hand plot
# Now add a colourbar who's leftmost point is the same as the leftmost
# point of the left hand plot and rightmost point is the rightmost
# point of the right hand plot.

# Get the positions of the 2nd plot and the left position of the 1st
# plot
left, bottom, width, height = plt2_ax.get_position().bounds
first_plot_left = plt1_ax.get_position().bounds[0]
# Get the positions of the 2nd plot and the left position of the 1st plot.
left, bottom, width, height = ax_array[1].get_position().bounds
first_plot_left = ax_array[0].get_position().bounds[0]

# the width of the colorbar should now be simple
width = left - first_plot_left + width
# The width of the colorbar should now be simple.
width = left - first_plot_left + width

# Add axes to the figure, to place the colour bar
colorbar_axes = fig.add_axes([first_plot_left, 0.18, width, 0.03])
# Add axes to the figure, to place the colour bar.
colorbar_axes = fig.add_axes([first_plot_left, 0.18, width, 0.03])

# Add the colour bar
cbar = plt.colorbar(
contour_result, colorbar_axes, orientation="horizontal"
)
# Add the colour bar.
cbar = plt.colorbar(
contour_result, colorbar_axes, orientation="horizontal"
)

# Label the colour bar and add ticks
cbar.set_label(e1_slice.units)
cbar.ax.tick_params(length=0)
# Label the colour bar and add ticks.
cbar.set_label(preindustrial.units)
cbar.ax.tick_params(length=0)

# Get the time datetime from the coordinate.
time = time_coord.units.num2date(time_coord.points[0])
# Set a title for the entire figure, using the year from the datetime
# object. Also, set the y value for the title so that it is not tight to
# the top of the plot.
fig.suptitle(
f"Annual Temperature Predictions for {time.year}",
y=0.9,
fontsize=18,
)

iplt.show()
iplt.show()


if __name__ == "__main__":
Expand Down
9 changes: 1 addition & 8 deletions docs/gallery_code/meteorology/plot_deriving_phenomena.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,7 @@ def limit_colorbar_ticks(contour_object):
number of ticks on the colorbar to 4.

"""
# Under Matplotlib v1.2.x the colorbar attribute of a contour object is
# a tuple containing the colorbar and an axes object, whereas under
# Matplotlib v1.3.x it is simply the colorbar.
try:
colorbar = contour_object.colorbar[0]
except (AttributeError, TypeError):
colorbar = contour_object.colorbar

colorbar = contour_object.colorbar
colorbar.locator = matplotlib.ticker.MaxNLocator(4)
colorbar.update_ticks()

Expand Down
5 changes: 5 additions & 0 deletions docs/src/_templates/footer.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{% extends "!footer.html" %}
{% block extrafooter %}
Built using Python {{ python_version }}.
{{ super() }}
{% endblock %}
2 changes: 2 additions & 0 deletions docs/src/common_links.inc
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
.. comment
Common resources in alphabetical order:

.. _black: https://black.readthedocs.io/en/stable/
.. _.cirrus.yml: https://github.com/SciTools/iris/blob/master/.cirrus.yml
.. _.flake8.yml: https://github.com/SciTools/iris/blob/master/.flake8
.. _cirrus-ci: https://cirrus-ci.com/github/SciTools/iris
Expand All @@ -19,6 +20,7 @@
.. _legacy documentation: https://scitools.org.uk/iris/docs/v2.4.0/
.. _matplotlib: https://matplotlib.org/
.. _napolean: https://sphinxcontrib-napoleon.readthedocs.io/en/latest/sphinxcontrib.napoleon.html
.. _nox: https://nox.thea.codes/en/stable/
.. _New Issue: https://github.com/scitools/iris/issues/new/choose
.. _pull request: https://github.com/SciTools/iris/pulls
.. _pull requests: https://github.com/SciTools/iris/pulls
Expand Down
14 changes: 9 additions & 5 deletions docs/src/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ def autolog(message):

# define the copyright information for latex builds. Note, for html builds,
# the copyright exists directly inside "_templates/layout.html"
upper_copy_year = datetime.datetime.now().year
copyright = "Iris Contributors"
copyright_years = f"2010 - {datetime.datetime.now().year}"
copyright = f"{copyright_years}, Iris Contributors"
author = "Iris Developers"

# The version info for the project you're documenting, acts as replacement for
Expand All @@ -95,9 +95,12 @@ def autolog(message):

# Create a variable that can be inserted in the rst "|copyright_years|".
# You can add more variables here if needed.

build_python_version = ".".join([str(i) for i in sys.version_info[:3]])

rst_epilog = f"""
.. |copyright_years| replace:: 2010 - {upper_copy_year}
.. |python_version| replace:: {'.'.join([str(i) for i in sys.version_info[:3]])}
.. |copyright_years| replace:: {copyright_years}
.. |python_version| replace:: {build_python_version}
.. |iris_version| replace:: v{version}
.. |build_date| replace:: ({datetime.datetime.now().strftime('%d %b %Y')})
"""
Expand Down Expand Up @@ -225,7 +228,8 @@ def autolog(message):
}

html_context = {
"copyright_years": "2010 - {}".format(upper_copy_year),
"copyright_years": copyright_years,
"python_version": build_python_version,
# menu_links and menu_links_name are used in _templates/layout.html
# to include some nice icons. See http://fontawesome.io for a list of
# icons (used in the sphinx_rtd_theme)
Expand Down
3 changes: 3 additions & 0 deletions docs/src/developers_guide/contributing_documentation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ The documentation uses specific packages that need to be present. Please see
Building
~~~~~~~~

This documentation was built using the latest Python version that Iris
supports. For more information see :ref:`installing_iris`.

The build can be run from the documentation directory ``docs/src``.

The build output for the html is found in the ``_build/html`` sub directory.
Expand Down
10 changes: 8 additions & 2 deletions docs/src/developers_guide/contributing_running_tests.rst
Original file line number Diff line number Diff line change
Expand Up @@ -175,11 +175,17 @@ For further `nox`_ command-line options::

nox --help

.. tip::
For `nox`_ sessions that use the `conda`_ backend, you can use the ``-v`` or ``--verbose``
flag to display the `nox`_ `conda`_ environment package details and environment info.
For example::

nox --session tests -- --verbose


.. note:: `nox`_ will cache its testing environments in the `.nox` root ``iris`` project directory.


.. _black: https://black.readthedocs.io/en/stable/
.. _nox: https://nox.thea.codes/en/latest/
.. _setuptools: https://setuptools.readthedocs.io/en/latest/
.. _tox: https://tox.readthedocs.io/en/latest/
.. _virtualenv: https://virtualenv.pypa.io/en/latest/
Expand Down
Loading