Skip to content

Commit 8e2f0cb

Browse files
committed
Improve API documentation
1 parent 9266a65 commit 8e2f0cb

10 files changed

Lines changed: 61 additions & 41 deletions

File tree

docs/README.md

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,4 @@ by running:
55

66
make html
77

8-
The generated HTML documentation pages are available in `build/html`. If
9-
Pyresample's API has changed (new functions, modules, classes, etc) then the
10-
API documentation should be regenerated before running the above make
11-
command.
12-
13-
sphinx-apidoc -f -T -o source/api ../pyresample ../pyresample/test
8+
The generated HTML documentation pages are available in `build/html`.

docs/environment.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,4 @@ dependencies:
1818
- pykdtree
1919
- sphinx_rtd_theme
2020
- sphinx-reredirects
21+
- sphinx-autodoc-typehints

docs/source/conf.py

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,14 @@
2424

2525
# -- General configuration -----------------------------------------------
2626

27+
# sphinxcontrib.apidoc was added to sphinx in 8.2.0 as sphinx.etx.apidoc
28+
needs_sphinx = "8.2.0"
29+
2730
# Add any Sphinx extension module names here, as strings. They can be extensions
2831
# coming with Sphinx (named 'sphinx.ext.*') or your custom ones.
2932
extensions = [
3033
'sphinx.ext.doctest', 'sphinx.ext.autodoc', 'sphinx.ext.napoleon', 'sphinx.ext.intersphinx',
31-
'sphinx_reredirects', 'doi_role',
34+
'sphinx.ext.apidoc', 'sphinx_reredirects', 'doi_role', "sphinx_autodoc_typehints",
3235
]
3336

3437
# DocTest Settings
@@ -52,6 +55,37 @@
5255
Basemap = None
5356
'''
5457

58+
# API docs
59+
apidoc_modules = [
60+
{
61+
"path": "../../pyresample",
62+
"destination": "api/",
63+
"exclude_patterns": [
64+
# Prefer to not document test modules. Most users will look at
65+
# source code if needed and we want to avoid documentation builds
66+
# suffering from import-time test data creation. We want to keep
67+
# things contributors might be interested in like satpy.tests.utils.
68+
"../../pyresample/test/test_*.py",
69+
"../../pyresample/test/**/test_*.py",
70+
],
71+
},
72+
]
73+
apidoc_separate_modules = True
74+
apidoc_include_private = True
75+
76+
autodoc_mock_imports = ["hashlib._Hash"]
77+
autodoc_type_aliases = {
78+
"ArrayLike": "numpy.typing.ArrayLike",
79+
"DTypeLike": "numpy.typing.DTypeLike",
80+
}
81+
autodoc_default_options = {
82+
"special-members": "__init__, __reduce_ex__",
83+
}
84+
nitpick_ignore_regex: list[tuple[str, str]] = []
85+
autoclass_content = "both" # append class __init__ docstring to the class docstring
86+
87+
88+
5589
# Napoleon Settings (to support numpy style docs)
5690
napoleon_numpy_docstring = True
5791
napoleon_use_admonition_for_examples = True
@@ -252,7 +286,7 @@
252286
'trollsift': ('https://trollsift.readthedocs.io/en/stable', None),
253287
'trollimage': ('https://trollimage.readthedocs.io/en/stable', None),
254288
'pyproj': ('https://pyproj4.github.io/pyproj/dev/', None),
255-
'proj': ('https://proj.org', None),
289+
'proj': ('https://proj.org/en/stable', None),
256290
'satpy': ('https://satpy.readthedocs.io/en/stable', None),
257291
'donfig': ('https://donfig.readthedocs.io/en/latest', None),
258292
}

docs/source/reference.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@ of how to use this information see the :doc:`/howtos/index`.
1111
.. toctree::
1212
:maxdepth: 1
1313

14-
API <api/pyresample>
14+
API <api/modules>
1515
roadmap
1616
dev_guide/index

pyresample/_formatting_html.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -221,10 +221,8 @@ def swath_area_attrs_section(area: 'geom.SwathDefinition') -> str: # noqa F821
221221
Returns:
222222
Html with collapsible section of swath attributes.
223223
224-
Todo:
225-
- Improve resolution estimation from lat/lon arrays. Maybe use CoordinateDefinition.geocentric_resolution?
226-
227224
"""
225+
# TODO: Improve resolution estimation from lat/lon arrays. Maybe use CoordinateDefinition.geocentric_resolution?
228226
if np.ndim(area.lons) == 1:
229227
area_name = "1D Swath"
230228
resolution_str = "NAxNA"

pyresample/area_config.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -246,11 +246,15 @@ def _capture_subarguments(params: dict, arg_name: str, sub_arg_list: list[str])
246246
"""Capture :func:`~pyresample.utils.create_area_def` sub-arguments (i.e. units, height, dx, etc) from a yaml file.
247247
248248
Example:
249-
resolution:
250-
dx: 11
251-
dy: 22
252-
units: meters
253-
# returns DataArray((11, 22), attrs={'units': 'meters})
249+
Specify the units for the individual dx/dy values::
250+
251+
resolution:
252+
dx: 11
253+
dy: 22
254+
units: meters
255+
256+
would return the equivalent of ``DataArray((11, 22), attrs={'units': 'meters})``.
257+
254258
"""
255259
# Check if argument is in yaml.
256260
argument = params.get(arg_name)

pyresample/bilinear/_base.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@
2525
"""Code for resampling using bilinear algorithm for irregular grids.
2626
2727
The algorithm is taken from
28-
29-
http://www.ahinson.com/algorithms_general/Sections/InterpolationRegression/InterpolationIrregularBilinear.pdf
28+
`here <http://www.ahinson.com/algorithms_general/Sections/InterpolationRegression/InterpolationIrregularBilinear.pdf>`__.
3029
3130
"""
3231

@@ -424,8 +423,8 @@ def _ensure_array(val):
424423
def _calc_abc(corner_points, out_y, out_x):
425424
"""Calculate coefficients for quadratic equation.
426425
427-
In this order of arguments used for _get_fractional_distances_irregular() and
428-
_get_fractional_distances_uprights(). For _get_fractional_distances_uprights switch order of pt_2 and
426+
In this order of arguments used for ``_get_fractional_distances_irregular()`` and
427+
``_get_fractional_distances_uprights()``. For ``_get_fractional_distances_uprights`` switch order of pt_2 and
429428
pt_3.
430429
431430
"""
@@ -451,9 +450,9 @@ def _calc_abc(corner_points, out_y, out_x):
451450

452451

453452
def _solve_another_fractional_distance(f__, y_corners, out_y):
454-
"""Solve parameter t__ from s__, or vice versa.
453+
"""Solve parameter ``t__`` from ``s__``, or vice versa.
455454
456-
For solving s__, switch order of y_2 and y_3.
455+
For solving ``s__``, switch order of y_2 and y_3.
457456
"""
458457
y_1, y_2, y_3, y_4 = y_corners
459458

pyresample/bilinear/xarr.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -172,13 +172,10 @@ def from_delayed(delayeds, shp):
172172

173173
slicer = get_slicer(data)
174174

175-
return from_delayed(
176-
self._delayed_slice_data(
177-
slicer, data, fill_value), shp)
178-
179-
@delayed(nout=4)
180-
def _delayed_slice_data(self, slicer, data, fill_value):
181-
return slicer(data.values, self.slices_x, self.slices_y, self.mask_slices, fill_value)
175+
delayed_slicer = delayed(slicer, pure=True, nout=4)
176+
sliced_data = delayed_slicer(data, self.slices_x, self.slices_y, self.mask_slices, fill_value)
177+
# TODO: Replace with single-chunk 'blockwise' call for better dask graph optimization
178+
return from_delayed(sliced_data, shp)
182179

183180
def _get_target_proj_vectors(self):
184181
try:

pyresample/future/resamplers/resampler.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,10 @@
3131

3232
from pyresample.geometry import AreaDefinition, CoordinateDefinition
3333

34-
if TYPE_CHECKING:
35-
# defined in typeshed to hide private C-level type
36-
from hashlib import _Hash
37-
3834
logger = logging.getLogger(__name__)
3935

4036

41-
def hash_dict(the_dict: dict, existing_hash: Optional[_Hash] = None) -> _Hash:
37+
def hash_dict(the_dict: dict, existing_hash: Optional[hashlib._Hash] = None) -> hashlib._Hash:
4238
"""Calculate a hash for a dictionary and optionally update an existing hash."""
4339
if existing_hash is None:
4440
existing_hash = hashlib.sha1() # nosec: B324

pyresample/geometry.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,6 @@
7171

7272
logger = getLogger(__name__)
7373

74-
if TYPE_CHECKING:
75-
# defined in typeshed to hide private C-level type
76-
from hashlib import _Hash
77-
7874

7975
class DimensionError(ValueError):
8076
"""Wrap ValueError."""
@@ -133,7 +129,7 @@ def __hash__(self):
133129
self.hash = int(self.update_hash().hexdigest(), 16)
134130
return self.hash
135131

136-
def update_hash(self, existing_hash: Optional[_Hash] = None) -> _Hash:
132+
def update_hash(self, existing_hash: Optional[hashlib._Hash] = None) -> hashlib._Hash:
137133
"""Update the hash."""
138134
if existing_hash is None:
139135
existing_hash = hashlib.sha1() # nosec: B324
@@ -2125,7 +2121,7 @@ def __ne__(self, other):
21252121
"""Test for equality."""
21262122
return not self.__eq__(other)
21272123

2128-
def update_hash(self, existing_hash: Optional[_Hash] = None) -> _Hash:
2124+
def update_hash(self, existing_hash: Optional[hashlib._Hash] = None) -> hashlib._Hash:
21292125
"""Update a hash, or return a new one if needed."""
21302126
if existing_hash is None:
21312127
existing_hash = hashlib.sha1() # nosec: B324

0 commit comments

Comments
 (0)