Skip to content

Commit 673e3ca

Browse files
authored
Add logo, version switcher, and docs corrections (#149)
* Update formatting * Add version switcher and logo * Rename contributing guide * Add v0.3.0 to version switcher * Update description of overlapping batches
1 parent 553e5ee commit 673e3ca

File tree

10 files changed

+146
-27
lines changed

10 files changed

+146
-27
lines changed

README.rst

+4-3
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@ xbatcher: Batch Generation from Xarray Datasets
44
|Build Status| |codecov| |docs| |pypi| |conda-forge| |license|
55

66

7-
Xbatcher is a small library for iterating xarray DataArrays in batches. The
8-
goal is to make it easy to feed xarray datasets to machine learning libraries
9-
such as PyTorch_ or TensorFlow_. View the |docs| for more info.
7+
Xbatcher is a small library for iterating Xarray DataArrays and Datasets in
8+
batches. The goal is to make it easy to feed Xarray objects to machine
9+
learning libraries such as PyTorch_ or TensorFlow_. View the |docs| for more
10+
info.
1011

1112
.. _TensorFlow: https://www.tensorflow.org/
1213

doc/_static/logo.svg

+58
Loading

doc/_static/switcher.json

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
[
2+
{
3+
"name": "dev",
4+
"version": "latest",
5+
"url": "https://xbatcher.readthedocs.io/en/latest/"
6+
},
7+
{
8+
"version": "0.3.0",
9+
"url": "https://xbatcher.readthedocs.io/en/v0.3.0/"
10+
},
11+
{
12+
"version": "0.2.0",
13+
"url": "https://xbatcher.readthedocs.io/en/v0.2.0/"
14+
},
15+
{
16+
"version": "0.1.0",
17+
"url": "https://xbatcher.readthedocs.io/en/0.1.0/"
18+
}
19+
]

doc/api.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Core
1616
BatchGenerator
1717
BatchSchema
1818

19-
Xbatcher xarray accessors
19+
Xbatcher Xarray accessors
2020
=========================
2121

2222
.. currentmodule:: xarray

doc/conf.py

+40-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
# type: ignore
1616

1717
import datetime
18+
import os
1819
import sys
1920

2021
import sphinx_autosummary_accessors
@@ -141,15 +142,53 @@
141142
# a list of builtin themes.
142143
# tml_theme = 'default'
143144
html_theme = "pydata_sphinx_theme"
145+
html_logo = "_static/logo.svg"
146+
html_favicon = "_static/logo.svg"
147+
148+
# The following is from the pydata-sphinx-theme settings (https://github.com/pydata/pydata-sphinx-theme/blob/main/docs/conf.py)
149+
# Define the json_url for our version switcher.
150+
json_url = "https://xbatcher.readthedocs.io/en/latest/_static/switcher.json"
151+
152+
# Define the version we use for matching in the version switcher.
153+
version_match = os.environ.get("READTHEDOCS_VERSION")
154+
# If READTHEDOCS_VERSION doesn't exist, we're not on RTD
155+
# If it is an integer, we're in a PR build and the version isn't correct.
156+
if not version_match or version_match.isdigit():
157+
# For local development, infer the version to match from the package.
158+
release = xbatcher.__version__
159+
if "dev" in release or "post" in release or "rc" in release:
160+
version_match = "latest"
161+
# We want to keep the relative reference if we are in dev mode
162+
# but we want the whole url if we are effectively in a released version
163+
json_url = "_static/switcher.json"
164+
else:
165+
version_match = "v" + release
166+
167+
print(f"release: {release}")
168+
144169

145170
# Theme options are theme-specific and customize the look and feel of a theme
146171
# further. For a list of options available for each theme, see the
147172
# documentation.
148173
html_theme_options = {
149174
"search_bar_position": "sidebar",
150175
"github_url": "https://github.com/xarray-contrib/xbatcher",
176+
"switcher": {
177+
"json_url": json_url,
178+
"version_match": version_match,
179+
},
180+
"logo": {
181+
"text": "Xbatcher",
182+
"alt_text": "Xbatcher",
183+
},
184+
"navbar_align": "left", # [left, content, right] For testing that the navbar items align properly
185+
"navbar_center": ["version-switcher", "navbar-nav"],
151186
}
152187

188+
# Define the json_url for our version switcher.
189+
190+
json_url = "https://xbatcher.readthedocs.io/en/latest/_static/switcher.json"
191+
153192
# Add any paths that contain custom themes here, relative to this directory.
154193
# html_theme_path = []
155194

@@ -162,7 +201,7 @@
162201

163202
# The name of an image file (relative to this directory) to place at the top
164203
# of the sidebar.
165-
html_logo = None
204+
# html_logo = None
166205

167206
# The name of an image file (within the static path) to use as favicon of the
168207
# docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32

doc/contributing.rst

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
.. _contributing:
22

3-
************************
4-
Contributing to xbatcher
5-
************************
3+
******************
4+
Contributing guide
5+
******************
66

77
.. note::
88

doc/demo.ipynb

+12-10
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"cells": [
33
{
4+
"attachments": {},
45
"cell_type": "markdown",
56
"id": "sticky-exhibit",
67
"metadata": {},
@@ -10,7 +11,7 @@
1011
"Author: Cindy Chiao\n",
1112
"\n",
1213
"## What is xbatcher? \n",
13-
"Xbatcher is a small library for iterating through xarray objects (DataArrays and Datasets) in batches. The goal is to make it easy to feed xarray objects to machine learning libraries such as Keras and PyTorch. \n",
14+
"Xbatcher is a small library for iterating through Xarray objects (DataArrays and Datasets) in batches. The goal is to make it easy to feed Xarray objects to machine learning libraries such as Keras and PyTorch. \n",
1415
"\n",
1516
"## What is included in this notebook?\n",
1617
"* showcase current abilities with example data \n",
@@ -197,13 +198,14 @@
197198
]
198199
},
199200
{
201+
"attachments": {},
200202
"cell_type": "markdown",
201203
"id": "spectacular-reading",
202204
"metadata": {},
203205
"source": [
204206
"## Last batch behavior\n",
205207
"\n",
206-
"If the input ds is not divisible by the specified `input_dims`, the remainder will be discarded instead of having a fractional batch. See https://github.com/xarray-contrib/xbatcher/issues/5 for more on this topic."
208+
"If the input ds is not divisible by the specified `input_dims`, the remainder will be discarded instead of having a fractional batch. See https://github.com/xarray-contrib/xbatcher/discussions/82 for more on this topic."
207209
]
208210
},
209211
{
@@ -260,11 +262,12 @@
260262
]
261263
},
262264
{
265+
"attachments": {},
263266
"cell_type": "markdown",
264267
"id": "harmful-benefit",
265268
"metadata": {},
266269
"source": [
267-
"We can inspect the samples in a batch for a lat/lon pixel, noting that the overlap only applies within a batch and not across. Thus, within the 20 time points in a batch, we can get 11 samples each with 10 time points and 9 time points allowed to overlap."
270+
"We can inspect the samples in a batch for a lat/lon pixel, noting that the overlap applies across batches."
268271
]
269272
},
270273
{
@@ -365,6 +368,7 @@
365368
]
366369
},
367370
{
371+
"attachments": {},
368372
"cell_type": "markdown",
369373
"id": "persistent-culture",
370374
"metadata": {},
@@ -375,16 +379,14 @@
375379
"\n",
376380
"Additional features of interest can include: \n",
377381
"\n",
378-
"1. Handling overlaps across batches. The common use case of batching in machine learning training involves generating all samples, then group them into batches. When overlap is enabled, this yields different results compared to first generating batches then creating possible samples within each batch. \n",
382+
"1. Shuffling/randomization of samples across batches. It is often desirable for each batch to be grouped randomly instead of along a specific dimension. \n",
379383
"\n",
380-
"2. Shuffling/randomization of samples across batches. It is often desirable for each batch to be grouped randomly instead of along a specific dimension. \n",
384+
"2. Be efficient in terms of memory usage. In the case where overlap is enabled, each sample would comprised of mostly repetitive values compared to adjacent samples. It would be beneficial if each batch/sample is generated lazily to avoid storing these extra duplicative values. \n",
381385
"\n",
382-
"3. Be efficient in terms of memory usage. In the case where overlap is enabled, each sample would comprised of mostly repetitive values compared to adjacent samples. It would be beneficial if each batch/sample is generated lazily to avoid storing these extra duplicative values. \n",
386+
"3. Handling preprocessing steps. For example, data augmentation, scaling/normalization, outlier detection, etc. \n",
383387
"\n",
384-
"4. Handling preprocessing steps. For example, data augmentation, scaling/normalization, outlier detection, etc. \n",
385388
"\n",
386-
"\n",
387-
"More thoughts on 1. and 2. can be found in [this issue](https://github.com/xarray-contrib/xbatcher/issues/30). Interested users are welcomed to comment or submit other issues in GitHub. "
389+
"More thoughts on 1. can be found in [this discussion](https://github.com/xarray-contrib/xbatcher/discussions/78). Interested users are welcomed to comment or submit other issues in GitHub. "
388390
]
389391
}
390392
],
@@ -404,7 +406,7 @@
404406
"name": "python",
405407
"nbconvert_exporter": "python",
406408
"pygments_lexer": "ipython3",
407-
"version": "3.9.13"
409+
"version": "3.8.13 | packaged by conda-forge | (default, Mar 25 2022, 06:04:14) \n[Clang 12.0.1 ]"
408410
},
409411
"vscode": {
410412
"interpreter": {

doc/index.rst

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
xbatcher: Batch Generation from Xarray Datasets
22
===============================================
33

4-
Xbatcher is a small library for iterating xarray DataArrays in batches. The
5-
goal is to make it easy to feed xarray datasets to machine learning libraries
6-
such as Keras_.
4+
Xbatcher is a small library for iterating Xarray DataArrays and Datasets in
5+
batches. The goal is to make it easy to feed Xarray objects to machine learning
6+
libraries such as Keras_.
77

88
.. _Keras: https://keras.io/
99

@@ -51,7 +51,7 @@ Or via PyPI::
5151
Basic Usage
5252
-----------
5353

54-
Let's say we have an xarray dataset
54+
Let's say we have an Xarray Dataset
5555

5656
.. ipython:: python
5757

doc/roadmap.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
.. _roadmap:
22

3-
Development Roadmap
4-
===================
3+
Roadmap
4+
=======
55

66
Authors: Joe Hamman and Ryan Abernathey
77
Date: February 7, 2019

xbatcher/generators.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
class BatchSchema:
1717
"""
1818
A representation of the indices and stacking/transposing parameters needed
19-
to generator batches from Xarray Datasets and DataArrays using
19+
to generator batches from Xarray DataArrays and Datasets using
2020
xbatcher.BatchGenerator.
2121
2222
Parameters
@@ -94,7 +94,7 @@ def _gen_batch_selectors(
9494
) -> BatchSelectorSet:
9595
"""
9696
Create batch selectors dict, which can be used to create a batch
97-
from an xarray data object.
97+
from an Xarray data object.
9898
"""
9999
# Create an iterator that returns an object usable for .isel in xarray
100100
patch_selectors = self._gen_patch_selectors(ds)
@@ -336,7 +336,7 @@ def _maybe_stack_batch_dims(
336336

337337

338338
class BatchGenerator:
339-
"""Create generator for iterating through xarray datarrays / datasets in
339+
"""Create generator for iterating through Xarray DataArrays / Datasets in
340340
batches.
341341
342342
Parameters

0 commit comments

Comments
 (0)