Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update docstrings to be consistent with function signature #3310

Merged
merged 7 commits into from
May 29, 2021
Merged
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
2 changes: 1 addition & 1 deletion yt/frontends/ramses/field_handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ def any_exist(cls, ds):

Arguments
---------
* ds: a Ramses Dataset
ds : a Ramses Dataset

Note
----
Expand Down
8 changes: 4 additions & 4 deletions yt/frontends/ramses/hilbert.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ def hilbert3d(X, bit_length):

Arguments
---------
* X: (N, ndim) float array
X : (N, ndim) float array
The positions
* bit_length: integer
bit_length : integer
The bit_length for the indexing.
"""
X = np.atleast_2d(X)
Expand Down Expand Up @@ -266,9 +266,9 @@ def get_cpu_list(ds, X):

Parameters
----------
* ds: Dataset
ds : Dataset
The dataset containing the information
* X: (N, ndim) float array
X : (N, ndim) float array
An array containing positions. They should be between 0 and 1.
"""
X = np.atleast_2d(X)
Expand Down
10 changes: 7 additions & 3 deletions yt/funcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,10 @@
def is_sequence(obj):
"""
Grabbed from Python Cookbook / matplotlib.cbook. Returns true/false for
*obj* iterable.

Parameters
----------
obj : iterable
"""
try:
len(obj)
Expand All @@ -56,7 +59,7 @@ def iter_fields(field_or_fields):

Parameters
----------
obj: str, tuple(str, str), or any iterable of the previous types.
field_or_fields: str, tuple(str, str), or any iterable of the previous types.

Examples
--------
Expand Down Expand Up @@ -1277,7 +1280,8 @@ def levenshtein_distance(seq1, seq2, max_dist=None):

Parameters
----------
seq1, seq2 : str
seq1 : str
seq2 : str
The strings to compute the distance between
max_dist : integer
If not None, maximum distance returned (see notes).
Expand Down
2 changes: 2 additions & 0 deletions yt/loaders.py
Original file line number Diff line number Diff line change
Expand Up @@ -1125,6 +1125,8 @@ def load_unstructured_mesh(
Size of computational domain in units of the length unit.
sim_time : float, optional
The simulation time in seconds
length_unit : string
Unit to use for length. Defaults to unitless.
mass_unit : string
Unit to use for masses. Defaults to unitless.
time_unit : string
Expand Down
3 changes: 2 additions & 1 deletion yt/utilities/lib/octree_raytracing.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,8 @@ def cast_rays(self, vp_pos, vp_dir):

Parameters
----------
vp_pos, vp_dir : float arrays (Nrays, Ndim)
vp_pos : float arrays (Nrays, Ndim)
vp_dir : float arrays (Nrays, Ndim)
The position (unitary) and direction of each ray

Returns
Expand Down
6 changes: 0 additions & 6 deletions yt/utilities/parallel_tools/parallel_analysis_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -570,12 +570,6 @@ def parallel_ring(objects, generator_func, mutable=False):
mutable : bool
Should the arrays be considered mutable? Currently, this will only
work if the number of processors equals the number of objects.
dynamic : bool
This governs whether or not dynamic load balancing will be enabled.
This requires one dedicated processor; if this is enabled with a set of
128 processors available, only 127 will be available to iterate over
objects as one will be load balancing the rest.


Examples
--------
Expand Down
2 changes: 1 addition & 1 deletion yt/visualization/color_maps.py
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ def make_colormap(ctuple_list, name=None, interpolate=True):
If you wish this colormap to be added as a valid colormap to the
current session, specify a name here. Default: None

interpolation: boolean, optional
interpolate: boolean
Designates whether or not the colormap will interpolate between
the colors provided or just give solid colors across the intervals.
Default: True
Expand Down
2 changes: 1 addition & 1 deletion yt/visualization/fits_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -616,7 +616,7 @@ def writeto(self, fileobj, fields=None, overwrite=False, **kwargs):
fields : list of strings, optional
The fields to write to the file. If not specified
all of the fields in the buffer will be written.
clobber : overwrite, optional
overwrite : boolean
Whether or not to overwrite a previously existing file.
Default: False
**kwargs
Expand Down
31 changes: 26 additions & 5 deletions yt/visualization/fixed_resolution.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import types
import weakref
from functools import wraps

import numpy as np

Expand Down Expand Up @@ -505,10 +505,31 @@ def setup_filters(self):
if key in ignored:
continue
filtername = filter_registry[key]._filter_name
FilterMaker = filter_registry[key]
filt = apply_filter(FilterMaker)
filt.__doc__ = FilterMaker.__doc__
self.__dict__["apply_" + filtername] = types.MethodType(filt, self)

# We need to wrap to create a closure so that
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have updated the PR description to explain why this is required.

# FilterMaker is bound to the wrapped method.
def closure():
FilterMaker = filter_registry[key]

@wraps(FilterMaker)
def method(*args, **kwargs):
# We need to also do it here as "invalidate_plot"
# and "apply_callback" require the functions'
# __name__ in order to work properly
@wraps(FilterMaker)
def cb(self, *a, **kwa):
# We construct the callback method
# skipping self
return FilterMaker(*a, **kwa)

# Create callback
cb = apply_filter(cb)

return cb(self, *args, **kwargs)

return method

self.__dict__["apply_" + filtername] = closure()


class CylindricalFixedResolutionBuffer(FixedResolutionBuffer):
Expand Down
10 changes: 5 additions & 5 deletions yt/visualization/line_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,8 @@ def __init__(
start_point,
end_point,
npoints,
figure_size=5.0,
fontsize=14.0,
figure_size=5,
fontsize=14,
field_labels=None,
):
"""
Expand All @@ -175,7 +175,7 @@ def __init__(

@classmethod
def _initialize_instance(
cls, obj, ds, fields, figure_size=5.0, fontsize=14.0, field_labels=None
cls, obj, ds, fields, figure_size=5, fontsize=14, field_labels=None
):
obj._x_unit = None
obj._y_units = {}
Expand Down Expand Up @@ -204,7 +204,7 @@ def _initialize_instance(

@classmethod
def from_lines(
cls, ds, fields, lines, figure_size=5.0, font_size=14.0, field_labels=None
cls, ds, fields, lines, figure_size=5, font_size=14, field_labels=None
):
"""
A class method for constructing a line plot from multiple sampling lines
Expand All @@ -222,7 +222,7 @@ def from_lines(
figure_size : int or two-element iterable of ints
Size in inches of the image.
Default: 5 (5x5)
fontsize : int
font_size : int
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with the annotated type, but the default value's type should also reflect it, can you fix it too ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be good now!

Font size for all text in the plot.
Default: 14
field_labels : dictionary
Expand Down
31 changes: 26 additions & 5 deletions yt/visualization/plot_window.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import types
from collections import defaultdict
from distutils.version import LooseVersion
from functools import wraps
from numbers import Number

import matplotlib
Expand Down Expand Up @@ -1262,10 +1262,31 @@ def setup_callbacks(self):
if key in ignored:
continue
cbname = callback_registry[key]._type_name
CallbackMaker = callback_registry[key]
callback = invalidate_plot(apply_callback(CallbackMaker))
callback.__doc__ = CallbackMaker.__doc__
self.__dict__["annotate_" + cbname] = types.MethodType(callback, self)

# We need to wrap to create a closure so that
# CallbackMaker is bound to the wrapped method.
def closure():
CallbackMaker = callback_registry[key]

@wraps(CallbackMaker)
def method(*args, **kwargs):
# We need to also do it here as "invalidate_plot"
# and "apply_callback" require the functions'
# __name__ in order to work properly
@wraps(CallbackMaker)
def cb(self, *a, **kwa):
# We construct the callback method
# skipping self
return CallbackMaker(*a, **kwa)

# Create callback
cb = invalidate_plot(apply_callback(cb))

return cb(self, *args, **kwargs)

return method

self.__dict__["annotate_" + cbname] = closure()

def annotate_clear(self, index=None):
"""
Expand Down
14 changes: 6 additions & 8 deletions yt/visualization/profile_plotter.py
Original file line number Diff line number Diff line change
Expand Up @@ -594,7 +594,7 @@ def set_unit(self, field, unit):
field : string
The name of the field that is to be changed.

new_unit : string or Unit object
unit : string or Unit object
The name of the new unit.
"""
fd = self.profiles[0].data_source._determine_fields(field)[0]
Expand Down Expand Up @@ -809,8 +809,8 @@ def annotate_text(self, xpos=0.0, ypos=0.0, text=None, field="all", **text_kwarg
The text to insert onto the plot.
field : str or tuple
The name of the field to add text to.
text_kwargs : dict
Dictionary of text keyword arguments to be passed to matplotlib
**text_kwargs : dict
Extra keyword arguments will be passed to matplotlib text instance

>>> import yt
>>> from yt.units import kpc
Expand Down Expand Up @@ -1250,16 +1250,14 @@ def annotate_text(self, xpos=0.0, ypos=0.0, text=None, **text_kwargs):

Parameters
----------
field : str or tuple
The name of the field to add text to.
xpos : float
Position on plot in x-coordinates.
ypos : float
Position on plot in y-coordinates.
text : str
The text to insert onto the plot.
text_kwargs : dict
Dictionary of text keyword arguments to be passed to matplotlib
**text_kwargs : dict
Extra keyword arguments will be passed to matplotlib text instance

>>> plot.annotate_text(1e-15, 5e4, "Hello YT")

Expand Down Expand Up @@ -1495,7 +1493,7 @@ def set_unit(self, field, unit):
field : string
The name of the field that is to be changed.

new_unit : string or Unit object
unit : string or Unit object
The name of the new unit.
"""
fd = self.data_source._determine_fields(field)[0]
Expand Down
2 changes: 1 addition & 1 deletion yt/visualization/streamlines.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class Streamlines(ParallelAnalysisInterface):
----------
ds : ~yt.data_objects.static_output.Dataset
This is the dataset to streamline
pos : array_like
positions : array_like
An array of initial starting positions of the streamlines.
xfield : str or tuple of str, optional
The x component of the vector field to be streamlined.
Expand Down
6 changes: 3 additions & 3 deletions yt/visualization/volume_rendering/camera.py
Original file line number Diff line number Diff line change
Expand Up @@ -384,13 +384,13 @@ def set_position(self, position, north_vector=None):
Parameters
----------

width : number, YTQuantity, :obj:`!iterable`, or 3 element YTArray
position : number, YTQuantity, :obj:`!iterable`, or 3 element YTArray
If a scalar, assumes that the position is the same in all three
coordinates. If an iterable, must contain only scalars or
(length, unit) tuples.

north_vector : array_like, optional
The 'up' direction for the plane of rays. If not specific,
The 'up' direction for the plane of rays. If not specific,
calculated automatically.

"""
Expand All @@ -408,7 +408,7 @@ def set_focus(self, new_focus):
Parameters
----------

focus : number, YTQuantity, :obj:`!iterable`, or 3 element YTArray
new_focus : number, YTQuantity, :obj:`!iterable`, or 3 element YTArray
If a scalar, assumes that the focus is the same is all three
coordinates. If an iterable, must contain only scalars or
(length, unit) tuples.
Expand Down
7 changes: 2 additions & 5 deletions yt/visualization/volume_rendering/camera_path.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,11 +218,8 @@ def prob(self, prev, next, temperature):
return np.exp(-abs(next - prev) / temperature)

def get_shortest_path(self):
r"""Determine shortest path between all keyframes.

Parameters
----------
None.
"""
Determine shortest path between all keyframes.
"""
# this obviously doesn't work. When someone fixes it, remove the NOQA
self.setup_tsp(niter, init_temp, alpha, fixed_start) # NOQA
Expand Down
5 changes: 1 addition & 4 deletions yt/visualization/volume_rendering/old_camera.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,6 @@ class Camera(ParallelAnalysisInterface):
ds : ~yt.data_objects.static_output.Dataset
For now, this is a require parameter! But in the future it will become
optional. This is the dataset to volume render.
use_kd: bool, optional
Specifies whether or not to use a kd-Tree framework for
the Homogenized Volume and ray-casting. Default to True.
max_level: int, optional
Specifies the maximum level to be rendered. Also
specifies the maximum level used in the kd-Tree
Expand Down Expand Up @@ -1441,7 +1438,7 @@ def yaw(self, theta, rot_center):
theta : float, in radians
Angle (in radians) by which to yaw the view.

center : a tuple (x, y, z)
rot_center : a tuple (x, y, z)
The point to rotate about

Examples
Expand Down
8 changes: 0 additions & 8 deletions yt/visualization/volume_rendering/render_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -915,14 +915,6 @@ def apply_colormap(self):

Applies a colormap to the current image without re-rendering.

Parameters
----------
cmap_name : string, optional
An acceptable colormap. See either yt.visualization.color_maps or
https://scipy-cookbook.readthedocs.io/items/Matplotlib_Show_colormaps.html .
color_bounds : tuple of floats, optional
The min and max to scale between. Outlying values will be clipped.

Returns
-------
current_image : A new image with the specified color scale applied to
Expand Down
4 changes: 0 additions & 4 deletions yt/visualization/volume_rendering/scene.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,6 @@ class Scene:
This does very little setup, and requires additional input
to do anything useful.

Parameters
----------
None

Examples
--------

Expand Down
3 changes: 0 additions & 3 deletions yt/visualization/volume_rendering/transfer_function_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,6 @@ def build_transfer_function(self):
Builds the transfer function according to the current state of the
TransferFunctionHelper.

Parameters
----------
None

Returns
-------
Expand Down