Skip to content

Commit 9161412

Browse files
committed
Rename kargs to kwargs
1 parent 5797047 commit 9161412

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+847
-835
lines changed

Stoner/Image/attrs.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ def _draw_apaptor(func):
2121
"""Adapt methods for DrawProxy class to bind :py:mod:`skimage.draw` functions."""
2222

2323
@wraps(func)
24-
def _proxy(self, *args, **kargs):
25-
value = kargs.pop("value", np.ones(1, dtype=self._img.dtype)[0])
26-
coords = func(*args, **kargs)
24+
def _proxy(self, *args, **kwargs):
25+
value = kwargs.pop("value", np.ones(1, dtype=self._img.dtype)[0])
26+
coords = func(*args, **kwargs)
2727
if len(coords) == 3:
2828
rr, cc, vv = coords
2929
if len(rr) == len(cc):
@@ -58,7 +58,7 @@ class DrawProxy:
5858
is saved.
5959
"""
6060

61-
def __init__(self, *args, **kargs): # pylint: disable=unused-argument
61+
def __init__(self, *args, **kwargs): # pylint: disable=unused-argument
6262
"""Grab the parent image from the constructor."""
6363
self._img = args[0]
6464
self._parent = args[1]
@@ -300,8 +300,8 @@ def __getattr__(self, name):
300300
raise AttributeError(f"{name} not a callable mask method.")
301301

302302
@wraps(func)
303-
def _proxy_call(*args, **kargs):
304-
retval = func(self._mask.astype(float).view(type(self._imagearray)) * 1000, *args, **kargs)
303+
def _proxy_call(*args, **kwargs):
304+
retval = func(self._mask.astype(float).view(type(self._imagearray)) * 1000, *args, **kwargs)
305305
if isinstance(retval, np.ndarray) and retval.shape == self._imagearray.shape:
306306
retval.normalise()
307307
self._imagearray.mask = retval > 0
@@ -356,7 +356,7 @@ def invert(self):
356356
"""Invert the mask."""
357357
self._imagearray.mask = ~self._imagearray.mask
358358

359-
def select(self, **kargs):
359+
def select(self, **kwargs):
360360
"""Interactive selection mode.
361361
362362
This method allows the user to interactively choose a mask region on the image. It will require the
@@ -382,7 +382,7 @@ def select(self, **kargs):
382382
383383
This method directly sets the mask and then returns a copy of the parent :py:class:`Stoner.ImageFile`.
384384
"""
385-
selection = kargs.get("_selection", [])
385+
selection = kwargs.get("_selection", [])
386386
if len(selection) == 0:
387387
selector = ShapeSelect()
388388
self._imagearray.mask = selector(self._imagearray)

Stoner/Image/core.py

Lines changed: 54 additions & 54 deletions
Large diffs are not rendered by default.

Stoner/Image/folders.py

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -19,32 +19,32 @@
1919
from .core import ImageArray
2020

2121

22-
def _prep_figure(self, kargs):
23-
plts = kargs.pop("plots_per_page", getattr(self, "plots_per_page", len(self)))
22+
def _prep_figure(self, kwargs):
23+
plts = kwargs.pop("plots_per_page", getattr(self, "plots_per_page", len(self)))
2424
self.plots_per_page = plts
2525
plts = min(plts, len(self))
2626

27-
fig_num = kargs.pop("figure", getattr(self, "_figure", None))
27+
fig_num = kwargs.pop("figure", getattr(self, "_figure", None))
2828
if isinstance(fig_num, Figure):
29-
kargs.setdefault("figsize", tuple(fig_num.get_size_inches()))
30-
kargs.setdefault("facecolor", fig_num.get_facecolor())
31-
kargs.setdefault("edgecolor", fig_num.get_edgecolor())
32-
kargs.setdefault("frameon", fig_num.get_frameon())
33-
kargs.setdefault("FigureClass", fig_num.__class__)
29+
kwargs.setdefault("figsize", tuple(fig_num.get_size_inches()))
30+
kwargs.setdefault("facecolor", fig_num.get_facecolor())
31+
kwargs.setdefault("edgecolor", fig_num.get_edgecolor())
32+
kwargs.setdefault("frameon", fig_num.get_frameon())
33+
kwargs.setdefault("FigureClass", fig_num.__class__)
3434
fig_num = fig_num.number
3535

3636
fig_args = getattr(self, "_fig_args", [])
37-
fig_kargs = getattr(self, "_fig_kargs", {"layout": "constrained"})
37+
fig_kwargs = getattr(self, "_fig_kwargs", {"layout": "constrained"})
3838
for arg in ("figsize", "dpi", "facecolor", "edgecolor", "frameon", "FigureClass"):
39-
if arg in kargs:
40-
fig_kargs[arg] = kargs.pop(arg)
39+
if arg in kwargs:
40+
fig_kwargs[arg] = kwargs.pop(arg)
4141
if fig_num is None:
42-
fig = figure(*fig_args, **fig_kargs)
42+
fig = figure(*fig_args, **fig_kwargs)
4343
elif fig_num in get_fignums():
4444
fig = figure(fig_num)
4545
else:
46-
fig = figure(fig_num, **fig_kargs)
47-
kargs["figure"] = fig_num
46+
fig = figure(fig_num, **fig_kwargs)
47+
kwargs["figure"] = fig_num
4848
return fig, plts
4949

5050

@@ -138,7 +138,7 @@ def __getter__(self, name, instantiate=True):
138138
ret._title = name
139139
return ret
140140

141-
def align(self, *args, **kargs):
141+
def align(self, *args, **kwargs):
142142
"""Align each image in the folder to the reference image.
143143
144144
Args:
@@ -184,7 +184,7 @@ def align(self, *args, **kargs):
184184
except (TypeError, ValueError) as err:
185185
raise TypeError(f"Cannot interpret {type(ref)} as reference image data.") from err
186186
# Call align on each object
187-
self.each.align(ref_data, **kargs)
187+
self.each.align(ref_data, **kwargs)
188188
limits = self.metadata.slice("translation_limits", output="array")
189189
stack_limits = np.zeros(4)
190190
stack_limits[::2] = limits.max(axis=0)[::2]
@@ -195,7 +195,7 @@ def align(self, *args, **kargs):
195195
self.metadata["align_box"] = tuple(stack_limits.astype(int))
196196
return self
197197

198-
def apply_all(self, func, *args, **kargs):
198+
def apply_all(self, func, *args, **kwargs):
199199
"""Apply function to all images in the stack.
200200
201201
Args:
@@ -205,10 +205,10 @@ def apply_all(self, func, *args, **kargs):
205205
if False print '.' for every iteration
206206
207207
Note:
208-
Further args, kargs are passed through to the function
208+
Further args, kwargs are passed through to the function
209209
"""
210210
warn("apply_all is deprecated and will be removed in a future version. Use ImageFolder.each() instead")
211-
return self.each(func, *args, **kargs)
211+
return self.each(func, *args, **kwargs)
212212

213213
def average(self, weights=None, _box=False, _metadata="first"):
214214
"""Get an array of average pixel values for the stack.
@@ -256,9 +256,9 @@ def as_stack(self):
256256
return k
257257

258258
@classmethod
259-
def from_tiff(cls, filename, **kargs):
259+
def from_tiff(cls, filename, **kwargs):
260260
"""Create a new ImageArray from a tiff file."""
261-
self = cls(**kargs)
261+
self = cls(**kwargs)
262262
with Image.open(filename, "r") as img:
263263
tags = img.tag_v2
264264
if 270 in tags:
@@ -321,12 +321,12 @@ def mean(self, _box=False, _metadata="first"):
321321
"""
322322
return self.average(_box=_box, _metadata=_metadata)
323323

324-
def montage(self, *args, **kargs):
324+
def montage(self, *args, **kwargs):
325325
"""Call the plot method for each metadataObject, but switching to a subplot each time.
326326
327327
Args:
328328
args: Positional arguments to pass through to the :py:meth:`Stoner.plot.PlotMixin.plot` call.
329-
kargs: Keyword arguments to pass through to the :py:meth:`Stoner.plot.PlotMixin.plot` call.
329+
kwargs: Keyword arguments to pass through to the :py:meth:`Stoner.plot.PlotMixin.plot` call.
330330
331331
Keyword Arguments:
332332
plot_extra (callable(i,j,d)):
@@ -355,36 +355,36 @@ def montage(self, *args, **kargs):
355355
Each plot is generated as sub-plot on a page. The number of rows and columns of subplots is computed
356356
from the aspect ratio of the figure and the number of files in the :py:class:`PlotFolder`.
357357
"""
358-
fig, plts = _prep_figure(self, kargs)
358+
fig, plts = _prep_figure(self, kwargs)
359359

360-
plot_extra = kargs.pop("plot_extra", lambda i, j, d: None)
360+
plot_extra = kwargs.pop("plot_extra", lambda i, j, d: None)
361361

362362
w, h = fig.get_size_inches()
363363
plt_x = int(np.floor(np.sqrt(plts) * w / h))
364364
plt_y = int(np.ceil(plts / plt_x))
365365

366-
kargs["figure"] = fig
366+
kwargs["figure"] = fig
367367
ret = []
368368
j = 0
369369
fignum = fig.number
370370
for i, d in enumerate(self):
371-
plt_kargs = copy(kargs)
371+
plt_kwargs = copy(kwargs)
372372
if i % plts == 0 and i != 0:
373-
fig, _ = _prep_figure(self, kargs)
373+
fig, _ = _prep_figure(self, kwargs)
374374
fignum = fig.number
375375
j = 1
376376
else:
377377
j += 1
378378
fig = figure(fignum)
379379
ax = subplot(plt_y, plt_x, j)
380-
plt_kargs["figure"] = fig
381-
plt_kargs["ax"] = ax
382-
if "title" in kargs:
383-
if isinstance(kargs["title"], str):
384-
plt_kargs["title"] = kargs["title"].format(**d)
385-
elif callable(kargs["title"]):
386-
plt_kargs["title"] = kargs["title"](d)
387-
ret.append(d.imshow(*args, **plt_kargs))
380+
plt_kwargs["figure"] = fig
381+
plt_kwargs["ax"] = ax
382+
if "title" in kwargs:
383+
if isinstance(kwargs["title"], str):
384+
plt_kwargs["title"] = kwargs["title"].format(**d)
385+
elif callable(kwargs["title"]):
386+
plt_kwargs["title"] = kwargs["title"](d)
387+
ret.append(d.imshow(*args, **plt_kwargs))
388388
plot_extra(i, j, d)
389389
return ret
390390

Stoner/Image/imagefuncs.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,19 +52,17 @@
5252
import sys
5353
import warnings
5454

55+
import numpy as np
5556
from matplotlib import cm
5657
from matplotlib import pyplot as plt
5758
from matplotlib.colors import to_rgba
58-
import numpy as np
5959
from PIL import Image, PngImagePlugin
6060
from PIL.TiffImagePlugin import ImageFileDirectory_v2
6161
from scipy import signal
6262
from scipy.interpolate import griddata, interp1d
6363
from scipy.ndimage import gaussian_filter
6464
from skimage import filters, measure, transform
6565

66-
from ..tools import isiterable, istuple, make_Data
67-
6866
from ..compat import ( # Some things to help with Python2 and Python3 compatibility
6967
get_filedialog,
7068
string_types,
@@ -73,6 +71,7 @@
7371
# from .core import ImageArray
7472
from ..core.base import metadataObject
7573
from ..plot.utils import auto_fit_fontsize
74+
from ..tools import isiterable, istuple, make_Data
7675
from ..tools.decorators import changes_size, keep_return_type
7776
from .util import _dtype, _dtype2
7877
from .util import _scale as im_scale

Stoner/Image/stack.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,18 @@
1818
AN_IM_SIZE = (554, 672) # Kerr image with annotation not cropped
1919

2020

21-
def _load_ImageArray(f, **kargs):
21+
def _load_ImageArray(f, **kwargs):
2222
"""Create and image array."""
23-
kargs.pop("Img_num", None) # REemove img_num if it exists
24-
return ImageArray(f, **kargs)
23+
kwargs.pop("Img_num", None) # REemove img_num if it exists
24+
return ImageArray(f, **kwargs)
2525

2626

2727
class ImageStackMixin:
2828
"""Implement an interface for a BaseFolder to store images in a 3D numpy array for faster access."""
2929

3030
_defaults = {"type": ImageFile}
3131

32-
def __init__(self, *args, **kargs):
32+
def __init__(self, *args, **kwargs):
3333
"""Initialise an ImageStack's pricate data and provide a type argument."""
3434
self._stack = np.ma.atleast_3d(ImageArray([])).reshape((0, 0, 0)).view(ImageArray)
3535
self._metadata = RegexpDict()
@@ -38,21 +38,21 @@ def __init__(self, *args, **kargs):
3838
self._sizes = np.array([], dtype=int).reshape(0, 2)
3939

4040
if not args:
41-
super().__init__(**kargs)
41+
super().__init__(**kwargs)
4242
return
4343
other = args[0]
4444
if isinstance(other, ImageStackMixin):
45-
super().__init__(*args[1:], **kargs)
45+
super().__init__(*args[1:], **kwargs)
4646
self._stack = other._stack
4747
self._metadata = other._metadata
4848
self._names = other._names
4949
self._sizes = other._sizes
5050
elif isinstance(other, ImageFolder): # ImageFolder can already init from itself
51-
super().__init__(*args, **kargs)
51+
super().__init__(*args, **kwargs)
5252
elif (
5353
isinstance(other, np.ndarray) and other.ndim == 3
5454
): # Initialise with 3D numpy array, first coordinate is number of images
55-
super().__init__(*args[1:], **kargs)
55+
super().__init__(*args[1:], **kwargs)
5656
self.imarray = other
5757
self._sizes = np.ones((other.shape[0], 2), dtype=int) * other.shape[1:]
5858
self._names = [f"Untitled-{d}" for d in range(other.shape[0])]
@@ -63,12 +63,12 @@ def __init__(self, *args, **kargs):
6363
other = [ImageFile(i) for i in other]
6464
except (TypeError, ValueError, RuntimeError) as err:
6565
raise ValueError("Failed to initialise ImageStack with list input") from err
66-
super().__init__(*args[1:], **kargs)
66+
super().__init__(*args[1:], **kwargs)
6767
for ot in other:
6868
self.append(ot)
6969

7070
else:
71-
super().__init__(*args, **kargs)
71+
super().__init__(*args, **kwargs)
7272

7373
def __lookup__(self, name):
7474
"""Stub for other classes to implement.
@@ -387,7 +387,7 @@ def convert(self, dtype, force_copy=False, uniform=False, normalise=True):
387387
self._stack.mask = mask
388388
return self
389389

390-
def asfloat(self, normalise=True, clip=False, clip_negative=False, **kargs):
390+
def asfloat(self, normalise=True, clip=False, clip_negative=False, **kwargs):
391391
"""Convert stack to floating point type.
392392
393393
Keyword Arguments:
@@ -411,12 +411,12 @@ def asfloat(self, normalise=True, clip=False, clip_negative=False, **kargs):
411411
pass
412412
else:
413413
self.convert(dtype=np.float64, normalise=normalise)
414-
if "clip_neg" in kargs:
414+
if "clip_neg" in kwargs:
415415
warnings.warn(
416416
"clip_neg argument renamed to clip_negative in ImageStack. This will cause an error in future"
417417
+ "versions of the Stoner Package."
418418
)
419-
clip_negative = kargs.pop("clip_neg")
419+
clip_negative = kwargs.pop("clip_neg")
420420
if clip or clip_negative:
421421
self.each.clip_intensity(clip_negative=clip_negative)
422422
return self

0 commit comments

Comments
 (0)