Skip to content
Open
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
4 changes: 2 additions & 2 deletions .devcontainer/scipy2023/jupyter_lab_config.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
c = get_config() # noqa
c.LabApp.default_url = '/lab/tree/workshops/scipy2023/index.ipynb'
c.ServerApp.allow_origin = '*'
c.LabApp.default_url = "/lab/tree/workshops/scipy2023/index.ipynb"
c.ServerApp.allow_origin = "*"
4 changes: 2 additions & 2 deletions .devcontainer/scipy2024/jupyter_lab_config.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
c = get_config() # noqa
c.LabApp.default_url = '/lab/tree/workshops/scipy2024/index.ipynb'
c.ServerApp.allow_origin = '*'
c.LabApp.default_url = "/lab/tree/workshops/scipy2024/index.ipynb"
c.ServerApp.allow_origin = "*"
6 changes: 3 additions & 3 deletions .github/actions/setup-pixi/action.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
name: "Setup Pixi"
description: "Create Python environment for GitHub Action Job"
name: 'Setup Pixi'
description: 'Create Python environment for GitHub Action Job'

runs:
using: "composite"
using: 'composite'
steps:
- uses: prefix-dev/setup-pixi@v0.8.10
with:
Expand Down
6 changes: 3 additions & 3 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Regularly update Docker tags and Actions steps
version: 2
updates:
- package-ecosystem: "github-actions"
directory: "/.github"
- package-ecosystem: 'github-actions'
directory: '/.github'
schedule:
interval: "monthly"
interval: 'monthly'
2 changes: 1 addition & 1 deletion .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ on:
push:
branches: main
paths-ignore:
- ".devcontainer/**"
- '.devcontainer/**'

# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
permissions:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/pull_request.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ on:
pull_request:
types: [opened, synchronize, reopened, closed]
paths-ignore:
- ".devcontainer/**"
- '.devcontainer/**'

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/qaqc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ on:
branches:
- main
paths-ignore:
- ".devcontainer/**"
- '.devcontainer/**'

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
Expand All @@ -28,7 +28,7 @@ jobs:
with:
check_filenames: true
check_hidden: true
skip: ".git,*.js,qaqc.yml"
skip: '.git,*.js,qaqc.yml'
ignore_words_list: hist,nd

# borrowed from https://github.com/ProjectPythia/pythia-foundations/blob/main/.github/workflows/link-checker.yaml
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/surge_preview.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Pull Request Preview

on:
workflow_run:
workflows: ["Pull Request Build"]
workflows: ['Pull Request Build']
types:
- completed

Expand Down
28 changes: 17 additions & 11 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,9 @@ repos:
- id: check-json
exclude: ^.devcontainer/
- id: check-yaml
- id: double-quote-string-fixer

- repo: https://github.com/codespell-project/codespell
rev: "v2.4.1"
rev: 'v2.4.1'
hooks:
- id: codespell

Expand All @@ -28,21 +27,28 @@ repos:
rev: v0.4.6
hooks:
- id: blackdoc
additional_dependencies: ['black==26.1.0']
- id: blackdoc-autoupdate-black

- repo: https://github.com/PyCQA/flake8
rev: 7.3.0
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.15.15
hooks:
- id: flake8
- id: ruff-check
args: ['--fix', '--show-fixes']

- repo: https://github.com/PyCQA/isort
rev: 8.0.1
- repo: https://github.com/rbubley/mirrors-prettier
rev: v3.8.3
hooks:
- id: isort
- id: prettier
args: ['--cache-location=.prettier_cache/cache']

- repo: https://github.com/pre-commit/mirrors-prettier
rev: v4.0.0-alpha.8
- repo: https://github.com/ComPWA/taplo-pre-commit
rev: v0.9.3
hooks:
- id: prettier
- id: taplo-format
args: ['--option', 'array_auto_collapse=false']
- id: taplo-lint
args: ['--no-schema']

- repo: https://github.com/kynan/nbstripout
rev: 0.9.1
Expand Down
14 changes: 7 additions & 7 deletions _config.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Learn more at https://jupyterbook.org/customize/config.html
title: ""
title: ''
author: The Xarray Community
copyright: "2025"
copyright: '2025'
logo: images/logo.png
only_build_toc_files: true
exclude_patterns: [.github, .pixi]
Expand All @@ -18,7 +18,7 @@ html:
extra_footer: '<p>Xarray is a fiscally sponsored project of <a href="https://numfocus.org">NumFOCUS</a>, a nonprofit dedicated to supporting the open-source scientific computing community.<br> Theme by the <a href="https://ebp.jupyterbook.org">Executable Book Project</a>.</p> Content licensed under the terms of the <a href="https://www.apache.org/licenses/LICENSE-2.0.html">Apache 2.0 License</a>.'
analytics:
google_analytics_id: G-JRQHYVFQR7
favicon: "images/favicon.ico"
favicon: 'images/favicon.ico'

parse:
# https://jupyterbook.org/content/content-blocks.html?highlight=myst%20substitution#define-substitutions-for-your-whole-book
Expand All @@ -40,7 +40,7 @@ parse:
# Force re-execution of notebooks on each build.
# See https://jupyterbook.org/content/execute.html
execute:
execute_notebooks: "cache"
execute_notebooks: 'cache'
allow_errors: false
# Per-cell notebook execution limit (seconds)
timeout: 300
Expand All @@ -53,11 +53,11 @@ latex:
# Configure your Binder links, such as the URL of the BinderHub.
launch_buttons:
notebook_interface: jupyterlab
binderhub_url: "https://mybinder.org"
binderhub_url: 'https://mybinder.org'

# Information about where the book exists on the web
repository:
url: "https://github.com/xarray-contrib/xarray-tutorial"
url: 'https://github.com/xarray-contrib/xarray-tutorial'
branch: main

# Bibliography
Expand All @@ -78,7 +78,7 @@ sphinx:
config:
language: en # accessibility
# application/vnd.holoviews_load.v0+json, application/vnd.holoviews_exec.v0+json
suppress_warnings: ["mystnb.unknown_mime_type", "misc.highlighting_failure"]
suppress_warnings: ['mystnb.unknown_mime_type', 'misc.highlighting_failure']
codeautolink_concat_default: True
notfound_context:
body: "<h1>Whoops! 404 Page Not Found</h1>\n\n<p>Sorry, this page doesn't exist. Many sections of this book have been updated recently.</p><p> Try the search box 🔎 to find what you're looking for!</p>"
Expand Down
2 changes: 1 addition & 1 deletion _static/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
/* workaround Pydata Sphinx theme using light colors for widget cell outputs in dark-mode */
/* works for many widgets but not for Xarray html reprs */
/* https://github.com/pydata/pydata-sphinx-theme/issues/2189 */
html[data-theme="dark"] div.cell_output .text_html:has(div.xr-wrap) {
html[data-theme='dark'] div.cell_output .text_html:has(div.xr-wrap) {
background-color: var(--pst-color-on-background) !important;
color: var(--pst-color-text-base) !important;
}
51 changes: 26 additions & 25 deletions advanced/accessors/01_accessor_examples.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@
"outputs": [],
"source": [
"ds = xr.tutorial.load_dataset(\"air_temperature\")\n",
"ds[\"skewair\"] = ds['air'].stats.skewness(dim=\"time\")\n",
"ds[\"skewair\"] = ds[\"air\"].stats.skewness(dim=\"time\")\n",
"ds"
]
},
Expand Down Expand Up @@ -126,8 +126,9 @@
"metadata": {},
"outputs": [],
"source": [
"import numpy as np\n",
"import os\n",
"\n",
"import numpy as np\n",
"import pandas as pd\n",
"import xarray as xr\n",
"\n",
Expand All @@ -151,7 +152,7 @@
"\n",
" @staticmethod\n",
" def _validate(self, req_dim=None, req_vars=None):\n",
" '''\n",
" \"\"\"\n",
" Make sure the xarray dataset has the correct dimensions and variables.\n",
"\n",
" Running this function will check that my dataset has all the needed dimensions and variables\n",
Expand All @@ -164,7 +165,7 @@
" List of all required dimension names\n",
" req_vars : list of str\n",
" List of all required variable names\n",
" '''\n",
" \"\"\"\n",
"\n",
" if req_dim is not None:\n",
" if all([dim not in list(self._xrds.dims) for dim in req_dim]):\n",
Expand All @@ -179,8 +180,8 @@
"\n",
" def change_vars_to_coords(\n",
" self,\n",
" req_dim=['ny', 'nx'],\n",
" req_vars={'xaxis': ['nx'], 'yaxis': ['ny']},\n",
" req_dim=[\"ny\", \"nx\"],\n",
" req_vars={\"xaxis\": [\"nx\"], \"yaxis\": [\"ny\"]},\n",
" ):\n",
" \"\"\"\n",
" Turn the xaxis and y axis variables into coordinates.\n",
Expand All @@ -195,8 +196,8 @@
"\n",
" self._validate(self, req_dim, req_vars)\n",
"\n",
" self._xrds = self._xrds.swap_dims({'ny': 'yaxis', 'nx': 'xaxis'})\n",
" self._xrds = self._xrds.rename({'xaxis': 'x', 'yaxis': 'y'})\n",
" self._xrds = self._xrds.swap_dims({\"ny\": \"yaxis\", \"nx\": \"xaxis\"})\n",
" self._xrds = self._xrds.rename({\"xaxis\": \"x\", \"yaxis\": \"y\"})\n",
"\n",
" return self._xrds\n",
"\n",
Expand All @@ -207,7 +208,7 @@
" \"\"\"\n",
"\n",
" reorged = []\n",
" for reorg_var in ['vx', 'vy', 'err']:\n",
" for reorg_var in [\"vx\", \"vy\", \"err\"]:\n",
" ds = self.reorg_var_time(reorg_var)\n",
" reorged.append(ds)\n",
"\n",
Expand All @@ -232,12 +233,12 @@
" das_to_reorg = [self._xrds[var] for var in to_reorg]\n",
"\n",
" # add the time dimension\n",
" das_to_reorg = [das_to_reorg[var].expand_dims('time') for var in range(len(das_to_reorg))]\n",
" das_to_reorg = [das_to_reorg[var].expand_dims(\"time\") for var in range(len(das_to_reorg))]\n",
"\n",
" # update variable name to remove time\n",
" das_to_reorg = [das_to_reorg[var].rename(reorg_var) for var in range(len(das_to_reorg))]\n",
"\n",
" ds = xr.concat(das_to_reorg, dim='time')\n",
" ds = xr.concat(das_to_reorg, dim=\"time\")\n",
"\n",
" return ds"
]
Expand All @@ -248,7 +249,7 @@
"metadata": {},
"outputs": [],
"source": [
"ds = xr.tutorial.open_dataset('ASE_ice_velocity.nc')"
"ds = xr.tutorial.open_dataset(\"ASE_ice_velocity.nc\")"
]
},
{
Expand Down Expand Up @@ -311,15 +312,15 @@
" # as specific to my workflow, saving time and headache later if they were missing and the computation fails\n",
" # partway through.\n",
" self._validate(\n",
" self, req_dim=['x', 'y', 'dtime'], req_vars={'elevation': ['x', 'y', 'dtime']}\n",
" self, req_dim=[\"x\", \"y\", \"dtime\"], req_vars={\"elevation\": [\"x\", \"y\", \"dtime\"]}\n",
" )\n",
"\n",
" # ----------------------------------------------------------------------\n",
" # Methods\n",
"\n",
" @staticmethod\n",
" def _validate(self, req_dim=None, req_vars=None):\n",
" '''\n",
" \"\"\"\n",
" Make sure the xarray dataset has the correct dimensions and variables\n",
"\n",
" Parameters\n",
Expand All @@ -328,7 +329,7 @@
" List of all required dimension names\n",
" req_vars : list of str\n",
" List of all required variable names\n",
" '''\n",
" \"\"\"\n",
"\n",
" if req_dim is not None:\n",
" if all([dim not in list(self._xrds.dims) for dim in req_dim]):\n",
Expand All @@ -340,8 +341,8 @@
" # Notice that 'geoid' has been added to the req_vars list\n",
" def to_geoid(\n",
" self,\n",
" req_dim=['dtime', 'x', 'y'],\n",
" req_vars={'elevation': ['x', 'y', 'dtime', 'geoid']},\n",
" req_dim=[\"dtime\", \"x\", \"y\"],\n",
" req_vars={\"elevation\": [\"x\", \"y\", \"dtime\", \"geoid\"]},\n",
" source=None,\n",
" ):\n",
" \"\"\"\n",
Expand All @@ -361,11 +362,11 @@
"\n",
" # check to make sure you haven't already run this function (and are thus applying the offset twice)\n",
" try:\n",
" values = self._xrds.attrs['offset_names']\n",
" assert 'geoid_offset' not in values, \"You've already applied the geoid offset!\"\n",
" values = list([values]) + ['geoid_offset']\n",
" values = self._xrds.attrs[\"offset_names\"]\n",
" assert \"geoid_offset\" not in values, \"You've already applied the geoid offset!\"\n",
" values = list([values]) + [\"geoid_offset\"]\n",
" except KeyError:\n",
" values = ['geoid_offset']\n",
" values = [\"geoid_offset\"]\n",
"\n",
" self._validate(self, req_dim, req_vars)\n",
"\n",
Expand All @@ -374,12 +375,12 @@
" # them to. If not, you will need to reproject and/or resample them to match the data to which you are applying them.\n",
" # That step is not included here to emphasize the accessor aspect of the workflow.\n",
" with rasterio.open(source) as src:\n",
" geoid = src['geoid_varname']\n",
" geoid = src[\"geoid_varname\"]\n",
"\n",
" # As noted above, this step will fail or produce unreliable results if your data is not properly gridded\n",
" self._xrds['elevation'] = self._xrds.elevation - geoid\n",
" self._xrds[\"elevation\"] = self._xrds.elevation - geoid\n",
"\n",
" self._xrds.attrs['offset_names'] = values\n",
" self._xrds.attrs[\"offset_names\"] = values\n",
"\n",
" return self._xrds"
]
Expand All @@ -401,7 +402,7 @@
},
"outputs": [],
"source": [
"ds = ds.geoidxr.to_geoid(source='/Path/to/Custom/source/file.nc')\n",
"ds = ds.geoidxr.to_geoid(source=\"/Path/to/Custom/source/file.nc\")\n",
"ds"
]
}
Expand Down
2 changes: 1 addition & 1 deletion advanced/apply_ufunc/automatic-vectorizing-numpy.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,8 @@
"source": [
"%xmode minimal\n",
"\n",
"import xarray as xr\n",
"import numpy as np\n",
"import xarray as xr\n",
"\n",
"xr.set_options(display_expand_data=False)\n",
"\n",
Expand Down
2 changes: 1 addition & 1 deletion advanced/apply_ufunc/complex-output-numpy.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@
"source": [
"%xmode minimal\n",
"\n",
"import xarray as xr\n",
"import numpy as np\n",
"import xarray as xr\n",
"\n",
"np.set_printoptions(threshold=10, edgeitems=2)\n",
"xr.set_options(display_expand_data=False)\n",
Expand Down
2 changes: 1 addition & 1 deletion advanced/apply_ufunc/example-interp.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@
"source": [
"%xmode minimal\n",
"\n",
"import xarray as xr\n",
"import numpy as np\n",
"import xarray as xr\n",
"\n",
"# limit the amount of information printed to screen\n",
"xr.set_options(display_expand_data=False)\n",
Expand Down
Loading
Loading