### Install Iris Sample Data Source: https://github.com/scitools/iris/blob/main/docs/src/installing.rst Commands to install the Iris sample data, which is required to run examples in the gallery, using either Conda or Pip. ```Shell conda install -c conda-forge iris-sample-data ``` ```Shell pip install iris-sample-data ``` -------------------------------- ### Iris Cube Test Setup Source: https://github.com/scitools/iris/blob/main/docs/src/userguide/navigating_a_cube.rst Initial setup for loading an Iris cube from a sample data path, used for subsequent examples. This block is typically used for testing or demonstration environments. ```python import iris filename = iris.sample_data_path('rotated_pole.nc') cube = iris.load_cube(filename) coord_names = [coord.name() for coord in cube.coords()] coord = cube.coord('grid_latitude') ``` -------------------------------- ### Setup for Iris Interpolation Examples Source: https://github.com/scitools/iris/blob/main/docs/src/userguide/interpolation_and_regridding.rst Initializes necessary libraries like NumPy and Iris, and configures warnings to be ignored for the subsequent examples. ```Python import numpy as np import iris import warnings warnings.simplefilter('ignore') ``` -------------------------------- ### Iris: Setup for Metadata Examples Source: https://github.com/scitools/iris/blob/main/docs/src/further_topics/metadata.rst Initializes an Iris cube by loading sample data from 'A1B_north_america.nc', used as a prerequisite for subsequent metadata examples. ```python import iris cube = iris.load_cube(iris.sample_data_path("A1B_north_america.nc")) ``` -------------------------------- ### Update Iris Installation Guide for WSL Source: https://github.com/scitools/iris/blob/main/docs/src/whatsnew/3.0.rst The `installing_iris` documentation section was updated to include a reference to Windows Subsystem for Linux (WSL) for installation guidance. ```APIDOC Documentation Section: installing_iris Content: Added reference to Windows Subsystem for Linux. ``` -------------------------------- ### Run Iris Test Suite Source: https://github.com/scitools/iris/blob/main/docs/src/installing.rst Command to execute the Iris test suite, ensuring that the development setup is correctly configured and functional. ```Shell pytest ``` -------------------------------- ### Configure Iris Custom Site Settings Source: https://github.com/scitools/iris/blob/main/docs/src/installing.rst Example configuration snippet for `iris/etc/site.cfg` to override default system settings, such as specifying a non-standard path for the `dot` executable. This allows for custom environment adjustments. ```INI [System] dot_path = /usr/bin/dot ``` -------------------------------- ### Setup for Lenient Cube Maths Example Source: https://github.com/scitools/iris/blob/main/docs/src/further_topics/lenient_maths.rst Initializes `experiment` and `control` Cube objects for demonstrating lenient cube maths. It loads a sample cube, modifies its attributes, and removes certain coordinates to create distinct but related cubes for the example. ```python import iris from iris.common import LENIENT experiment = iris.load_cube(iris.sample_data_path("hybrid_height.nc"), "air_potential_temperature") control = experiment[0] control.remove_aux_factory(control.aux_factory()) for coord in ["sigma", "forecast_reference_time", "forecast_period", "atmosphere_hybrid_height_coordinate", "surface_altitude"]: control.remove_coord(coord) control.attributes["Conventions"] = "CF-1.7" experiment.attributes["experiment-id"] = "RT3 50" ``` -------------------------------- ### Install pre-commit using pip Source: https://github.com/scitools/iris/blob/main/docs/src/developers_guide/contributing_code_formatting.rst This command installs the `pre-commit` tool into your Python development environment using the `pip` package manager. It is the recommended way to get `pre-commit` if you are managing your environment with `pip`. ```bash $ pip install pre-commit ``` -------------------------------- ### Improved Developer Setup with Conda Source: https://github.com/scitools/iris/blob/main/docs/src/whatsnew/3.0.rst The developer setup process for Iris has been improved, with curated conda environment YAML files making it easier to configure and install dependencies from source. ```Python Developer Setup: - Curated conda environment YAML files available. - Simplifies dependency management for source installations. ``` -------------------------------- ### Example Git Status Output Source: https://github.com/scitools/iris/blob/main/docs/src/developers_guide/gitwash/development_workflow.rst This is an example of the output from the `git status` command. It shows files that have been modified but not yet staged for commit, and untracked files that are not yet under version control, guiding the user on how to proceed. ```Shell # On branch ny-new-feature # Changed but not updated: # (use "git add ..." to update what will be committed) # (use "git checkout -- ..." to discard changes in working directory) # # modified: README # # Untracked files: # (use "git add ..." to include in what will be committed) # # INSTALL no changes added to commit (use "git add" and/or "git commit -a") ``` -------------------------------- ### Python Setup for Iris Warning Examples Source: https://github.com/scitools/iris/blob/main/docs/src/further_topics/filtering_warnings.rst This setup code initializes Iris, configures warning handling for doctests to ensure warnings are visible and paths are relative. It also defines `my_operation()`, a hypothetical function designed to trigger specific Iris warnings for demonstration. ```python from pathlib import Path import sys import warnings import iris import iris.coord_systems import iris.warnings # Hack to ensure doctests actually see Warnings that are raised, and that # they have a relative path (so a test pass is not machine-dependent). warnings.filterwarnings("default") IRIS_FILE = Path(iris.__file__) def custom_warn(message, category, filename, lineno, file=None, line=None): filepath = Path(filename) filename = str(filepath.relative_to(IRIS_FILE.parents[1])) sys.stdout.write(warnings.formatwarning(message, category, filename, lineno)) warnings.showwarning = custom_warn geog_cs_globe = iris.coord_systems.GeogCS(6400000) orthographic_coord_system = iris.coord_systems.Orthographic( longitude_of_projection_origin=0, latitude_of_projection_origin=0, ellipsoid=geog_cs_globe, ) def my_operation(): geog_cs_globe.inverse_flattening = 0.1 _ = orthographic_coord_system.as_cartopy_crs() ``` -------------------------------- ### Replace unittest setUp() with pytest fixture Source: https://github.com/scitools/iris/blob/main/docs/src/developers_guide/contributing_pytest_conversions.rst This snippet demonstrates how to replace the unittest setUp() method with a pytest fixture. The _setup() function, decorated with @pytest.fixture(autouse=True), will automatically run before each test, serving the same purpose as setUp() in unittest. ```python @pytest.fixture(autouse=True) def _setup(self): ... ``` -------------------------------- ### Python: Import necessary libraries for Iris data examples Source: https://github.com/scitools/iris/blob/main/docs/src/userguide/real_and_lazy_data.rst This setup block imports `dask.array`, `iris`, `iris.cube.CubeList`, and `numpy` to prepare the environment for demonstrating Iris data concepts, including lazy and real data handling. ```python import dask.array as da import iris from iris.cube import CubeList import numpy as np ``` -------------------------------- ### Install Released Iris Library Source: https://github.com/scitools/iris/blob/main/docs/src/installing.rst Instructions for installing the stable release of the Iris library using either the Conda package manager from conda-forge or Pip from PyPI. ```Shell conda install -c conda-forge iris ``` ```Shell pip install scitools-iris ``` -------------------------------- ### Example output of git commit with pre-commit hooks Source: https://github.com/scitools/iris/blob/main/docs/src/developers_guide/contributing_code_formatting.rst This snippet shows the typical output when performing a `git commit` after `pre-commit` hooks have been installed. It illustrates how various checks (like `black` and `flake8`) are run automatically, indicating their status (Passed, Skipped, etc.) before the commit is finalized. ```bash Check for added large files..............................................Passed Check for merge conflicts................................................Passed Debug Statements (Python)............................(no files to check)Skipped Don't commit to branch...................................................Passed black................................................(no files to check)Skipped flake8...............................................(no files to check)Skipped [contribution_overhaul c8513187] this is my commit message 2 files changed, 10 insertions(+), 9 deletions(-) ``` -------------------------------- ### Start Jupyter Notebook Server Source: https://github.com/scitools/iris/blob/main/docs/gallery_code/README.rst After downloading the gallery notebooks, execute this command in your terminal to launch the Jupyter notebook server. This will open a web browser interface where you can access and run the downloaded notebooks. ```bash jupyter notebook ``` -------------------------------- ### Inspect contents of loaded Iris CubeList Source: https://github.com/scitools/iris/blob/main/docs/src/userguide/loading_iris_cubes.rst Shows how to print the `CubeList` returned by `iris.load` to get a high-level overview of the loaded cubes, including their names, units, and primary dimensions. This example uses a sample PP file. ```python >>> import iris >>> filename = iris.sample_data_path('uk_hires.pp') >>> cubes = iris.load(filename) >>> print(cubes) 0: air_potential_temperature / (K) (time: 3; model_level_number: 7; grid_latitude: 204; grid_longitude: 187) 1: surface_altitude / (m) (grid_latitude: 204; grid_longitude: 187) ``` -------------------------------- ### Install Iris Sample Data and Jupyter with Conda Source: https://github.com/scitools/iris/blob/main/docs/gallery_code/README.rst This command uses the Conda package manager to install 'iris-sample-data' and 'jupyter' from the 'conda-forge' channel. These packages are required to successfully view and interact with the gallery's Jupyter notebooks locally. ```bash conda install -c conda-forge iris-sample-data jupyter ``` -------------------------------- ### Setup for Lenient Metadata Behaviour Examples Source: https://github.com/scitools/iris/blob/main/docs/src/further_topics/lenient_metadata.rst Initializes an Iris cube and extracts a latitude coordinate, preparing for demonstrations of lenient metadata operations. ```python import iris cube = iris.load_cube(iris.sample_data_path("A1B_north_america.nc")) latitude = cube.coord("latitude") ``` -------------------------------- ### Configure GitHub App: Post-Creation Setup Source: https://github.com/scitools/iris/blob/main/docs/src/developers_guide/github_app.rst Outlines the essential configuration steps after a GitHub App has been created, including noting the App ID and generating a private key for signing access token requests. ```APIDOC SciTools settings / iris-actions form: About: App ID: (Note this value for later use in GHA secrets) Display information: (Optional) Upload iris logo (png image) Private keys: Generate a private key: (Click button to generate and download) ``` -------------------------------- ### Install pre-commit Git hooks Source: https://github.com/scitools/iris/blob/main/docs/src/developers_guide/contributing_code_formatting.rst This command installs the Git hooks defined in the project's `.pre-commit-config.yaml` file. Running this from the root directory of the Iris project enables automatic code formatting and linting upon `git commit`. ```bash $ pre-commit install ``` -------------------------------- ### Iris Test Setup for PP and Fieldsfile Handling Source: https://github.com/scitools/iris/blob/main/docs/src/further_topics/um_files_loading.rst Initializes the test environment by importing necessary Iris and NumPy modules and setting NumPy print options for precision. ```python import numpy as np import iris import iris.fileformats.pp np.set_printoptions(precision=2) ``` -------------------------------- ### Setup: Initializing Cube and Area Weights Source: https://github.com/scitools/iris/blob/main/docs/src/userguide/cube_statistics.rst This setup code loads a sample Iris cube and prepares its geographical coordinates by guessing bounds. It then calculates area weights, which are essential for accurate area-weighted statistical operations on the cube. ```python import iris filename = iris.sample_data_path('uk_hires.pp') cube = iris.load_cube(filename, 'air_potential_temperature') import iris.analysis.cartography cube.coord('grid_latitude').guess_bounds() cube.coord('grid_longitude').guess_bounds() grid_areas = iris.analysis.cartography.area_weights(cube) ``` -------------------------------- ### Example of a Complete What's New Contribution Entry Source: https://github.com/scitools/iris/blob/main/docs/src/developers_guide/documenting/whats_new_contributions.rst Provides a full example of a 'What's New' entry, illustrating the reStructuredText auto-enumerated list format, inclusion of multiple contributors (including reviewers), references to Iris classes/methods, issue numbers, and pull request IDs. This serves as a template for new contributions, emphasizing conciseness and user-centric language. ```reStructuredText #. `@tkknight `_ and `@trexfeathers `_ (reviewer) changed argument ``x`` to be optional in :class:`~iris.module.class` and :meth:`iris.module.method`. This allows greater flexibility as requested in :issue:`9999`. (:pull:`1111`, :pull:`9999`) ``` -------------------------------- ### Install pre-commit using conda Source: https://github.com/scitools/iris/blob/main/docs/src/developers_guide/contributing_code_formatting.rst This command installs the `pre-commit` tool into your Python development environment using the `conda` package manager. It specifies the 'conda-forge' channel to ensure access to the `pre-commit` package. ```bash $ conda install -c conda-forge pre-commit ``` -------------------------------- ### Inspect Iris Cube Methods and Attributes Source: https://github.com/scitools/iris/blob/main/docs/src/userguide/navigating_a_cube.rst Illustrates using `dir()` to list available methods and attributes, and `help()` to get detailed documentation for an Iris cube object. This helps in exploring the capabilities of the cube. ```python dir(cube) help(cube) ``` -------------------------------- ### Install Local Iris Development Source Source: https://github.com/scitools/iris/blob/main/docs/src/installing.rst Command to install the local Iris source code in editable mode, allowing changes to the source to be immediately reflected without reinstallation. This command should be run from the root directory of your local Iris copy. ```Shell pip install --no-deps --editable . ``` -------------------------------- ### Create Iris Development Environment Source: https://github.com/scitools/iris/blob/main/docs/src/installing.rst Steps to set up a development environment for Iris by creating a Conda environment from the provided `requirements/iris.yml` file and then activating it. This environment includes dependencies for coding, testing, and building documentation. ```Shell conda env create --file=requirements/iris.yml conda activate iris-dev ``` -------------------------------- ### Run Single Iris Gallery Test by Pattern Source: https://github.com/scitools/iris/blob/main/docs/src/developers_guide/contributing_documentation_full.rst This command allows you to run a specific gallery example test by using the pytest -k option for pattern matching, useful for focused debugging. ```Shell pytest -v -k plot_coriolis docs/gallery_tests/test_gallery_examples.py ``` -------------------------------- ### Documentation Update: ORCA Grid Reprojection Example Source: https://github.com/scitools/iris/blob/main/docs/src/whatsnew/1.7.rst Notes the addition of an example demonstrating data reprojection from 2D auxiliary spatial coordinates, such as those from the ORCA grid. ```APIDOC Example: plot_orca_projection.py (ORCA grid reprojection) ``` -------------------------------- ### Documentation Update: Custom Aggregator Example Source: https://github.com/scitools/iris/blob/main/docs/src/whatsnew/1.7.rst Notes the addition of an example demonstrating how to create a custom `iris.analysis.Aggregator`. ```APIDOC Example: plot_custom_aggregation.py (iris.analysis.Aggregator) ``` -------------------------------- ### Install Iris from PyPI for Testing Source: https://github.com/scitools/iris/blob/main/docs/src/developers_guide/release.rst These commands deactivate the current conda environment, create a new 'iris-dev' environment from a YAML file, activate it, and then install 'scitools-iris' from PyPI using pip without dependencies for testing purposes. ```Shell conda deactivate conda env create --file ./requirements/iris.yml . activate iris-dev python -m pip install --no-deps scitools-iris ``` -------------------------------- ### Example Pytest Output Source: https://github.com/scitools/iris/blob/main/docs/src/developers_guide/contributing_running_tests.rst This example displays a trimmed output from a `pytest` session, showing the test progress, summary of passed/skipped tests, and warnings. It highlights common output patterns, including messages for skipped tests due to missing dependencies or external data. ```shell ============================= test session starts ============================== platform linux -- Python 3.10.5, pytest-7.1.2, pluggy-1.0.0 rootdir: /path/to/git/clone/iris, configfile: pyproject.toml, testpaths: lib/iris plugins: xdist-2.5.0, forked-1.4.0 gw0 I / gw1 I gw0 [6361] / gw1 [6361] ........................................................................ [ 1%] ........................................................................ [ 2%] ........................................................................ [ 3%] ... .......................ssssssssssssssssss............................... [ 99%] ........................ [100%] =============================== warnings summary =============================== ... -- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html =========================== short test summary info ============================ SKIPPED [1] lib/iris/tests/experimental/test_raster.py:152: Test requires 'gdal'. SKIPPED [1] lib/iris/tests/experimental/test_raster.py:155: Test requires 'gdal'. ... ========= 6340 passed, 21 skipped, 1659 warnings in 193.57s (0:03:13) ========== ``` -------------------------------- ### Using Iris Plugins Source: https://github.com/scitools/iris/blob/main/docs/src/community/plugins.rst Once an Iris plugin is installed, it can be activated using the `iris.use_plugin` function or by directly importing its module from `iris.plugins`. ```python import iris iris.use_plugin("my_plugin") # OR import iris.plugins.my_plugin ``` -------------------------------- ### Documentation Update: Custom Log-Scale Colouring Example Source: https://github.com/scitools/iris/blob/main/docs/src/whatsnew/1.7.rst Notes the addition of an example demonstrating custom log-scale colouring in plots. ```APIDOC Example: plot_anomaly_log_colouring.py ``` -------------------------------- ### Run Iris Documentation Doctests Source: https://github.com/scitools/iris/blob/main/docs/src/developers_guide/contributing_documentation_full.rst This command runs doctests embedded within the documentation pages, verifying that Python code examples are still valid and produce expected outputs. ```Shell make doctest ``` -------------------------------- ### Documentation Gallery Reorganization Source: https://github.com/scitools/iris/blob/main/docs/src/whatsnew/3.0.rst The `plot_orca_projection.py` example has been moved from the general gallery to the oceanography section in the documentation. ```Documentation Documentation Gallery: - plot_orca_projection.py moved to oceanography section. ``` -------------------------------- ### Clone Your Git Fork and Add Upstream Remote Source: https://github.com/scitools/iris/blob/main/docs/src/developers_guide/gitwash/set_up_fork.rst This snippet demonstrates the initial steps to set up your local repository: cloning your personal fork from GitHub, changing into the project directory, and then adding the main SciTools/iris repository as an 'upstream' remote. This allows you to pull changes from the main project. ```bash git clone git@github.com:your-user-name/iris.git cd iris git remote add upstream git@github.com/SciTools/iris.git ``` -------------------------------- ### Example Docstring for Python Unit Test Module Source: https://github.com/scitools/iris/blob/main/docs/src/developers_guide/contributing_tests.rst Illustrates the required docstring format for a unit test module, specifying the exact unit (function or class) being tested within the `iris` project. ```Python """Unit tests for the `iris.experimental.raster.export_geotiff` function.""" ``` -------------------------------- ### Cross-referencing Internal Documents in reST Source: https://github.com/scitools/iris/blob/main/docs/src/developers_guide/documenting/rest_guide.rst Shows how to link to other documents within the same project using the `:doc:` role in reStructuredText. This is useful for building interconnected documentation sets. ```reStructuredText :doc:`document_name` ``` -------------------------------- ### Setup for CubeList.merge vs CubeList.merge_cube Comparison Source: https://github.com/scitools/iris/blob/main/docs/src/userguide/merge_and_concat.rst Initializes a `CubeList` with three identical cubes and adds a 'Conventions' attribute to the first cube, preparing for a comparison of merge methods. ```python import numpy as np import iris def _xy_cube(z): cube = iris.cube.Cube(np.arange(20).reshape(4, 5), 'air_temperature', units='kelvin') cube.add_dim_coord(iris.coords.DimCoord(range(4), long_name='y'), 0) cube.add_dim_coord(iris.coords.DimCoord(range(5), long_name='x'), 1) cube.add_aux_coord(iris.coords.DimCoord(z, long_name='z', units='meters')) return cube cubes = iris.cube.CubeList([_xy_cube(1), _xy_cube(2), _xy_cube(3)]) cubes[0].attributes['Conventions'] = 'CF-1.5' ``` -------------------------------- ### Iris Plugin setup.cfg Configuration Source: https://github.com/scitools/iris/blob/main/docs/src/community/plugins.rst This example shows a minimal `setup.cfg` configuration for an Iris plugin. The package name should ideally include 'iris' and the plugin name. The `packages = find_namespace:` and `where = lib` options are crucial for correctly identifying the namespace package. ```ini [metadata] name = iris-my-plugin [options] packages = find_namespace: [options.packages.find] where = lib ``` -------------------------------- ### Install Nox in an existing Conda environment Source: https://github.com/scitools/iris/blob/main/docs/src/developers_guide/contributing_running_tests.rst Instructions to install the nox package from conda-forge into an already active Conda environment. This is suitable if you prefer to integrate Nox into an existing setup. ```Shell conda install -c conda-forge nox ``` -------------------------------- ### Creating Basic External Links in reST Source: https://github.com/scitools/iris/blob/main/docs/src/developers_guide/documenting/rest_guide.rst Demonstrates how to create a simple external hyperlink in reStructuredText using inline syntax. This syntax allows embedding a URL directly within the link text. ```reStructuredText `Text of the link `_ ``` -------------------------------- ### Running Benchmarks Locally with Nox Source: https://github.com/scitools/iris/blob/main/benchmarks/README.md Instructions on how to use the Nox 'benchmarks' session to run performance benchmarks locally, including how to access detailed help for the command. ```Shell nox -s benchmarks -- --help ``` -------------------------------- ### Documentation Update: Cube Broadcasting Section Source: https://github.com/scitools/iris/blob/main/docs/src/whatsnew/1.7.rst Highlights the addition of a new section on cube broadcasting to the Iris user guide. ```APIDOC User Guide: cube broadcasting ``` -------------------------------- ### Install Nox in a new Conda environment Source: https://github.com/scitools/iris/blob/main/docs/src/developers_guide/contributing_running_tests.rst Instructions to create a new Conda environment named 'nox' and install the nox package from conda-forge, then activate the environment. This ensures an isolated setup for Nox. ```Shell conda create -n nox -c conda-forge nox conda activate nox ``` -------------------------------- ### Python: Setup for Iris CubeList.concatenate Example Source: https://github.com/scitools/iris/blob/main/docs/src/userguide/merge_and_concat.rst This setup code defines a helper function `_xyt_cube` to create sample Iris cubes with varying 't' coordinates and initializes a CubeList with three such cubes for demonstration purposes. ```python import numpy as np import iris def _xyt_cube(t): cube = iris.cube.Cube(np.arange(12 * len(t)).reshape(-1, 3, 4), 'air_temperature', units='kelvin') cube.add_dim_coord(iris.coords.DimCoord(range(3), long_name='y'), 1) cube.add_dim_coord(iris.coords.DimCoord(range(4), long_name='x'), 2) cube.add_dim_coord(iris.coords.DimCoord(t, long_name='t'), 0) return cube cubes = iris.cube.CubeList([_xyt_cube(np.arange(31)), _xyt_cube(np.arange(28) + 31), _xyt_cube(np.arange(31) + 59)]) ``` -------------------------------- ### Iris Plugin Repository Layout Example Source: https://github.com/scitools/iris/blob/main/docs/src/community/plugins.rst This snippet illustrates the recommended directory structure for an Iris plugin. It must appear as a folder within `iris/plugins`, and importantly, there should be no `__init__.py` files at higher levels than the plugin itself to ensure proper namespace package behavior. ```text + lib + iris + plugins + my_plugin - __init__.py - (more code...) - README.md - pyproject.toml - setup.cfg - (other project files...) ``` -------------------------------- ### Setup for Iris Cube Concatenation with Time Unit Unification Source: https://github.com/scitools/iris/blob/main/docs/src/userguide/merge_and_concat.rst Initializes necessary libraries for demonstrating concatenation with time unit differences, preparing for the use of 'iris.util.unify_time_units'. ```python import numpy as np ``` -------------------------------- ### Python: Setup for Iris CubeList.concatenate_cube Comparison Source: https://github.com/scitools/iris/blob/main/docs/src/userguide/merge_and_concat.rst This setup code prepares sample Iris cubes similar to the previous example, but with an added 'History' attribute to the first cube. This difference in attributes will be used to demonstrate the behavior of `concatenate_cube` when input cubes are inconsistent. ```python import numpy as np import iris def _xyt_cube(t): cube = iris.cube.Cube(np.arange(12 * len(t)).reshape(-1, 3, 4), 'air_temperature', units='kelvin') cube.add_dim_coord(iris.coords.DimCoord(range(3), long_name='y'), 1) cube.add_dim_coord(iris.coords.DimCoord(range(4), long_name='x'), 2) cube.add_dim_coord(iris.coords.DimCoord(t, long_name='t'), 0) return cube cubes = iris.cube.CubeList([_xyt_cube(np.arange(31)), _xyt_cube(np.arange(28) + 31), _xyt_cube(np.arange(31) + 59)]) cubes[0].attributes['History'] = 'Created 2010-06-30' ``` -------------------------------- ### Running Benchmarks Locally with bm_runner.py Source: https://github.com/scitools/iris/blob/main/benchmarks/README.md Instructions on how to directly execute 'benchmarks/bm_runner.py' for running performance benchmarks locally, including how to access detailed help for the script. ```Shell benchmarks/bm_runner.py --help ``` -------------------------------- ### Quick Build Iris Documentation (No Gallery or API) Source: https://github.com/scitools/iris/blob/main/docs/src/developers_guide/contributing_documentation_full.rst This command performs a quick build of the documentation by skipping both the gallery and the API documentation creation. ```Shell make html-quick ``` -------------------------------- ### Setup for Strict Metadata Behaviour Examples Source: https://github.com/scitools/iris/blob/main/docs/src/further_topics/lenient_metadata.rst Initializes an Iris cube and extracts a latitude coordinate for demonstrating strict metadata operations. ```python import iris cube = iris.load_cube(iris.sample_data_path("A1B_north_america.nc")) latitude = cube.coord("latitude") ``` -------------------------------- ### Python: Populate Latitude Metadata Attributes Source: https://github.com/scitools/iris/blob/main/docs/src/further_topics/lenient_metadata.rst Illustrates how to assign a dictionary of attributes to a `latitude` coordinate's metadata in Iris. This setup prepares the metadata for subsequent lenient comparison examples, showing how to modify `latitude.attributes`. ```Python attributes = {"grinning face": "😀", "neutral face": "😐"} latitude.attributes = attributes latitude.metadata # doctest: +SKIP ``` -------------------------------- ### Setup: Create a Sample Iris Cube with Time Series Data Source: https://github.com/scitools/iris/blob/main/docs/src/userguide/subsetting_a_cube.rst Initializes a sample Iris cube named `long_ts` with a time coordinate representing weekly intervals over several years. This cube is used as a basis for subsequent time constraint examples. ```Python import datetime import numpy as np from iris.time import PartialDateTime long_ts = iris.cube.Cube(np.arange(150), long_name='data', units='1') _mondays = iris.coords.DimCoord(7 * np.arange(150), standard_name='time', units='days since 2007-04-09') long_ts.add_dim_coord(_mondays, 0) ``` -------------------------------- ### View Built Iris Documentation in Browser Source: https://github.com/scitools/iris/blob/main/docs/src/developers_guide/contributing_documentation_full.rst After building the documentation, this command opens the generated HTML documentation in your default web browser. ```Shell make show ``` -------------------------------- ### Python: Setup for Iris Cube Merging Example Source: https://github.com/scitools/iris/blob/main/docs/src/userguide/merge_and_concat.rst Defines a helper function `_xy_cube` to create a sample Iris cube with `y` and `x` dimensions and a scalar `z` coordinate. It then initializes a `CubeList` named `cubes` with three such cubes, each having a different `z` value, to be used in subsequent merge operations. ```python import numpy as np import iris def _xy_cube(z): cube = iris.cube.Cube(np.arange(20).reshape(4, 5), 'air_temperature', units='kelvin') cube.add_dim_coord(iris.coords.DimCoord(range(4), long_name='y'), 0) cube.add_dim_coord(iris.coords.DimCoord(range(5), long_name='x'), 1) cube.add_aux_coord(iris.coords.DimCoord(z, long_name='z', units='meters')) return cube cubes = iris.cube.CubeList([_xy_cube(1), _xy_cube(2), _xy_cube(3)]) ``` -------------------------------- ### Combining Iris Metadata with `combine` Method Source: https://github.com/scitools/iris/blob/main/docs/src/further_topics/metadata.rst Illustrates the `combine` method for merging Iris metadata instances. It shows how combining identical metadata returns an identical instance, and how combining instances with differing values results in `None` for the non-common members, or common values for identical members. Includes setup code for the examples. ```python import iris cube = iris.load_cube(iris.sample_data_path("A1B_north_america.nc")) longitude = cube.coord("longitude") ``` ```python cube.metadata ``` ```python metadata = cube.metadata.combine(cube.metadata) cube.metadata == metadata ``` ```python metadata = cube.metadata._replace(standard_name="air_pressure_at_sea_level") metadata != cube.metadata metadata.combine(cube.metadata) # doctest: +SKIP CubeMetadata(standard_name=None, long_name=None, var_name='air_temperature', units=Unit('K'), attributes={'STASH': STASH(model=1, section=3, item=236), 'Model scenario': 'A1B', 'source': 'Data from Met Office Unified Model 6.05', 'Conventions': 'CF-1.5'}, cell_methods=(CellMethod(method='mean', coord_names=('time',), intervals=('6 hour',), comments=()),)) ``` -------------------------------- ### Run All Iris Gallery Tests Source: https://github.com/scitools/iris/blob/main/docs/src/developers_guide/contributing_documentation_full.rst This command executes all tests associated with the documentation gallery entries, ensuring their correctness and functionality. ```Shell pytest -v docs/gallery_tests/test_gallery_examples.py ``` -------------------------------- ### Inspect Iris UGRID Cube and Mesh Properties Source: https://github.com/scitools/iris/blob/main/docs/src/further_topics/ugrid/data_model.rst These doctest examples demonstrate how to query and display various attributes of an Iris Cube that is linked to a UGRID mesh. It shows how to print the cube's summary, access its location, determine its mesh dimension, and get a detailed summary of the associated `MeshXY` object. ```python >>> print(edge_cube) edge_data / (K) (-- : 6; height: 3) Dimension coordinates: height - x Mesh coordinates: latitude x - longitude x - Mesh: name my_mesh location edge >>> print(edge_cube.location) edge >>> print(edge_cube.mesh_dim()) 0 >>> print(edge_cube.mesh.summary(shorten=True)) >>> print(edge_cube.mesh) MeshXY : 'my_mesh' topology_dimension: 2 node node_dimension: 'Mesh2d_node' node coordinates edge edge_dimension: 'Mesh2d_edge' edge_node_connectivity: edge coordinates face face_dimension: 'Mesh2d_face' face_node_connectivity: face coordinates long_name: 'my_mesh' ``` -------------------------------- ### Example Git Configuration File Structure Source: https://github.com/scitools/iris/blob/main/docs/src/developers_guide/gitwash/configure_git.rst This snippet shows a typical structure of a `.gitconfig` file, located in your home directory. It includes common sections like user, alias, core, and merge, demonstrating how personal Git settings are organized. ```Git Config [user] name = Your Name email = you@yourdomain.example.com [alias] ci = commit -a co = checkout st = status stat = status br = branch wdiff = diff --color-words [core] editor = vim [merge] summary = true ``` -------------------------------- ### Add New Wind Speed Plot Example Source: https://github.com/scitools/iris/blob/main/docs/src/whatsnew/1.10.rst A new code example, `plot_wind_speed.py`, has been added to the gallery. This example demonstrates the use of a quiver plot to display wind speeds over Lake Victoria. ```APIDOC Example: sphx_glr_generated_gallery_meteorology_plot_wind_speed.py Description: Demonstrates quiver plot for wind speeds over Lake Victoria. ``` -------------------------------- ### Documentation Theme and Hosting Update Source: https://github.com/scitools/iris/blob/main/docs/src/whatsnew/3.0.rst The Iris documentation has been updated to use a modern Sphinx theme and is now hosted at `https://scitools-iris.readthedocs.io/en/latest/`. ```Documentation Documentation: - Modern Sphinx theme applied. - New hosting URL: https://scitools-iris.readthedocs.io/en/latest/ ``` -------------------------------- ### Overhaul Iris Developers Guide Source: https://github.com/scitools/iris/blob/main/docs/src/whatsnew/3.0.rst The Iris developers guide was extensively revised to include new information on contributing to the project and to improve its overall structure. ```APIDOC Documentation Section: developers_guide Content: Overhauled with contributor information and structural improvements. ``` -------------------------------- ### Check PyPI Package Description Rendering Source: https://github.com/scitools/iris/blob/main/docs/src/developers_guide/release.rst This command uses 'twine check' to verify that the package description in the built artifacts will render correctly on PyPI, ensuring proper display of the project information. ```Shell python -m twine check dist/* ``` -------------------------------- ### Update User Guide on Multi-dimensional Coordinates Source: https://github.com/scitools/iris/blob/main/docs/src/whatsnew/1.10.rst A note has been added to the user guide regarding the impossibility of partially collapsing multi-dimensional coordinates, providing important usage constraints. ```APIDOC User Guide: Multi-dimensional Coordinates Update: Added note on impossibility of partial collapsing. ``` -------------------------------- ### Add Cube Maths Units Clarification to User Guide Source: https://github.com/scitools/iris/blob/main/docs/src/whatsnew/3.0.rst A new section, `cube_maths_combining_units`, was added to the user guide to provide clarity on how units are managed during cube arithmetic operations. ```APIDOC Documentation Section: cube_maths_combining_units Content: Clarifies Unit handling in cube arithmetic. ``` -------------------------------- ### Create and Checkout a New Feature Branch Source: https://github.com/scitools/iris/blob/main/docs/src/developers_guide/gitwash/development_workflow.rst This sequence of commands first updates your local mirror of the upstream 'trunk', then creates a new feature branch named 'my-new-feature' based on the current state of 'upstream/main', and finally switches your working directory to this new branch. This ensures your new work starts from the latest upstream code. ```Shell # Update the mirror of trunk git fetch upstream # Make new feature branch starting at current trunk git branch my-new-feature upstream/main git checkout my-new-feature ``` -------------------------------- ### Get Iris Cube String, Representation, and Type Source: https://github.com/scitools/iris/blob/main/docs/src/userguide/navigating_a_cube.rst Shows how to use standard Python functions like `str()`, `repr()`, and `type()` to get different string representations and the object type of an Iris cube. ```python print(str(cube)) print(repr(cube)) print(type(cube)) ``` -------------------------------- ### Get Iris Cube Name Method Source: https://github.com/scitools/iris/blob/main/docs/src/userguide/navigating_a_cube.rst Shows how to use the `name()` method to get a string representation of the cube's name. This method always returns a string, providing a consistent way to identify the cube. ```python print(cube.name()) ``` -------------------------------- ### Build Iris Source Distribution and Wheel Source: https://github.com/scitools/iris/blob/main/docs/src/developers_guide/release.rst This command builds the source distribution (.tar.gz) and pure Python wheel (.whl) files for the Iris project from its root directory, populating the './dist' directory. ```Shell python -m build ``` -------------------------------- ### Initial GRIB file loading script without Dask Source: https://github.com/scitools/iris/blob/main/docs/src/further_topics/dask_best_practices/dask_bags_and_greed.rst This script demonstrates a common approach to loading GRIB files using the Iris library. It includes a callback function to filter or modify cubes during loading. A sample of 11 GRIB files takes approximately 600 seconds to load, highlighting a performance bottleneck. ```Python import iris import glob fpaths=glob.glob('20190416/*t18z*f???') cubes = iris.load(fpaths, callback=callback) def callback(cube, field, fname): if field.sections[5]['bitsPerValue'] == 0: raise iris.exceptions.IgnoreCubeException if field.sections[4]['parameterNumber'] == 20: raise iris.exceptions.IgnoreCubeException elif field.sections[4]['parameterNumber'] == 234: cube.long_name = 'Icing Severity' ``` -------------------------------- ### Combined example: interactive plotting and mode check Source: https://github.com/scitools/iris/blob/main/docs/src/userguide/plotting_a_cube.rst A comprehensive example demonstrating the combined use of enabling interactive mode, plotting data, and checking the interactive status. It highlights that import statements are not necessary to repeat when combining functionalities. ```python import matplotlib.pyplot as plt plt.interactive(True) plt.plot([1, 2, 2.5]) print(plt.isinteractive()) ``` -------------------------------- ### Python List Multiple Assignment Example Source: https://github.com/scitools/iris/blob/main/docs/src/userguide/loading_iris_cubes.rst A general Python example demonstrating the use of multiple assignment to unpack elements from a list of a pre-known length and order into separate variables. This is a common Python idiom for handling sequences. ```Python >>> number_one, number_two = [1, 2] >>> print(number_one) 1 >>> print(number_two) 2 ``` -------------------------------- ### Load and Extract Iris Cubes with Multiple Constraints Source: https://github.com/scitools/iris/blob/main/docs/src/userguide/subsetting_a_cube.rst Demonstrates loading a sample PP file and extracting cubes based on combined constraints for air temperature, forecast period, and model level. It also shows how to print the loaded cubes and inspect a specific cube's metadata, including dimension, auxiliary, derived, and scalar coordinates, as well as attributes. ```Python filename = iris.sample_data_path('uk_hires.pp') cubes = iris.load(filename).extract(air_temp_and_fp_6 & level_10) print(cubes) 0: air_potential_temperature / (K) (grid_latitude: 204; grid_longitude: 187) print(cubes[0]) air_potential_temperature / (K) (grid_latitude: 204; grid_longitude: 187) Dimension coordinates: grid_latitude x - grid_longitude - x Auxiliary coordinates: surface_altitude x x Derived coordinates: altitude x x Scalar coordinates: forecast_period 6.0 hours forecast_reference_time 2009-11-19 04:00:00 level_height 395.0 m, bound=(360.0, 433.3332) m model_level_number 10 sigma 0.9549927, bound=(0.9589389, 0.95068014) time 2009-11-19 10:00:00 Attributes: STASH m01s00i004 source 'Data from Met Office Unified Model' um_version '7.3' ``` -------------------------------- ### GitHub Pull Request Description Template Source: https://github.com/scitools/iris/blob/main/docs/src/developers_guide/contributing_documentation_easy.rst This template is provided by GitHub when creating a pull request, guiding contributors to provide a clear and concise description of their changes, new features, improvements, or bug fixes for reviewers. ```Markdown ### Description ``` -------------------------------- ### Install and Run Ruff for Iris Codebase Compliance Source: https://github.com/scitools/iris/blob/main/docs/src/developers_guide/contributing_ci_tests.rst As of Iris 3.8, `ruff` has been adopted to ensure best practices in the codebase. This snippet provides the commands to install `ruff` within the `iris-dev` conda environment and then run it against the Iris project directory to check for compliance. ```Shell conda activate iris-dev pip install ruff cd iris ruff . ``` -------------------------------- ### PP Field Data Structure Example Source: https://github.com/scitools/iris/blob/main/lib/iris/tests/results/usecases/pp_to_cf_conversion/to_pp/000003000000.16.202.000128.1860.09.01.00.00.b.pp.txt An example representation of multiple PP Field instances, illustrating the various metadata attributes (e.g., lbyr, lbmon, blev, bplat) and the associated numerical data array. Each field represents data at a specific atmospheric level (blev). ```APIDOC [PP Field lbyr: 1860 lbmon: 9 lbdat: 1 lbhr: 0 lbmin: 0 lbsec: 0 lbyrd: 1860 lbmond: 12 lbdatd: 1 lbhrd: 0 lbmind: 0 lbsecd: 0 lbtim: 422 lbft: 2156 lblrec: 7008 lbcode: 1 lbhem: 0 lbrow: 73 lbnpt: 96 lbext: 0 lbpack: 0 lbrel: 3 lbfc: 1 lbcfc: 0 lbproc: 128 lbvc: 8 lbrvc: 0 lbexp: 0 lbegin: 0 lbnrec: 0 lbproj: 0 lbtyp: 0 lblev: 0 lbrsvd: (0, 0, 0, 0) lbsrce: 1111 lbuser: (1, -99, 0, 16202, 0, 0, 1) brsvd: (0.0, 0.0, 0.0, 0.0) bdatum: 0.0 bacc: 0.0 blev: 200.0 brlev: 0.0 bhlev: 0.0 bhrlev: 0.0 bplat: 90.0 bplon: 0.0 bgor: 0.0 bzy: 92.499985 bdy: -2.499999 bzx: -3.749999 bdx: 3.749999 bmdi: -1e+30 bmks: 1.0 data: [[11203. 11203. 11203. ... 11203. 11203. 11203.] [11201. 11199. 11198. ... 11207. 11205. 11203.] [11201. 11199. 11197. ... 11208. 11207. 11204.] ... [10497. 10495. 10492. ... 10507. 10504. 10501.] [10482. 10481. 10480. ... 10488. 10486. 10483.] [10502. 10502. 10502. ... 10502. 10502. 10502.]] , PP Field lbyr: 1860 lbmon: 9 lbdat: 1 lbhr: 0 lbmin: 0 lbsec: 0 lbyrd: 1860 lbmond: 12 lbdatd: 1 lbhrd: 0 lbmind: 0 lbsecd: 0 lbtim: 422 lbft: 2156 lblrec: 7008 lbcode: 1 lbhem: 0 lbrow: 73 lbnpt: 96 lbext: 0 lbpack: 0 lbrel: 3 lbfc: 1 lbcfc: 0 lbproc: 128 lbvc: 8 lbrvc: 0 lbexp: 0 lbegin: 0 lbnrec: 0 lbproj: 0 lbtyp: 0 lblev: 0 lbrsvd: (0, 0, 0, 0) lbsrce: 1111 lbuser: (1, -99, 0, 16202, 0, 0, 1) brsvd: (0.0, 0.0, 0.0, 0.0) bdatum: 0.0 bacc: 0.0 blev: 500.0 brlev: 0.0 bhlev: 0.0 bhrlev: 0.0 bplat: 90.0 bplon: 0.0 bgor: 0.0 bzy: 92.499985 bdy: -2.499999 bzx: -3.749999 bdx: 3.749999 bmdi: -1e+30 bmks: 1.0 data: [[5252. 5252. 5252. ... 5252. 5252. 5252.] [5248. 5248. 5248. ... 5249. 5249. 5248.] [5250. 5249. 5248. ... 5251. 5250. 5250.] ... [4873. 4872. 4870. ... 4874. 4874. 4874.] [4858. 4857. 4857. ... 4859. 4859. 4859.] [4854. 4854. 4854. ... 4854. 4854. 4854.]] , PP Field lbyr: 1860 lbmon: 9 lbdat: 1 lbhr: 0 lbmin: 0 lbsec: 0 lbyrd: 1860 lbmond: 12 lbdatd: 1 lbhrd: 0 lbmind: 0 lbsecd: 0 lbtim: 422 lbft: 2156 lblrec: 7008 lbcode: 1 lbhem: 0 lbrow: 73 lbnpt: 96 lbext: 0 lbpack: 0 lbrel: 3 lbfc: 1 lbcfc: 0 lbproc: 128 lbvc: 8 lbrvc: 0 lbexp: 0 lbegin: 0 lbnrec: 0 lbproj: 0 lbtyp: 0 lblev: 0 lbrsvd: (0, 0, 0, 0) lbsrce: 1111 lbuser: (1, -99, 0, 16202, 0, 0, 1) brsvd: (0.0, 0.0, 0.0, 0.0) bdatum: 0.0 bacc: 0.0 blev: 700.0 brlev: 0.0 bhlev: 0.0 bhrlev: 0.0 bplat: 90.0 bplon: 0.0 bgor: 0.0 bzy: 92.499985 bdy: -2.499999 bzx: -3.749999 bdx: 3.749999 bmdi: -1e+30 bmks: 1.0 data: [[2818. 2818. 2818. ... 2818. 2818. 2818.] [2815. 2816. 2816. ... 2813. 2814. 2815.] [2815. 2815. 2815. ... 2814. 2814. 2815.] ... [2563. 2564. 2566. ... 2555. 2558. 2561.] [2555. 2555. 2555. ... 2554. 2555. 2555.] [2540. 2540. 2540. ... 2540. 2540. 2540.]] ] ```