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

Add codespell support (config, workflow to detect/not fix) and make it fix few typos #616

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
25 changes: 25 additions & 0 deletions .github/workflows/codespell.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Codespell configuration is within setup.cfg
---
name: Codespell

on:
push:
branches: [master]
pull_request:
branches: [master]

permissions:
contents: read

jobs:
codespell:
name: Check for spelling errors
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v4
- name: Annotate locations with typos
uses: codespell-project/codespell-problem-matcher@v1
- name: Codespell
uses: codespell-project/actions-codespell@v2
6 changes: 3 additions & 3 deletions doc/developers/style_guide.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Coding style
============

pulse2percept uses the standard Python `PEP8`_ style guide to ensure
readibility and consistency of the code base.
readability and consistency of the code base.

.. note::

Expand All @@ -44,7 +44,7 @@ Imports
-------

pulse2percept recommends using the following package shorthands to increase
consistency and readibility across the library:
consistency and readability across the library:

.. code-block:: python

Expand Down Expand Up @@ -92,7 +92,7 @@ The recommended style is to break a line after binary operators:
- student_loan_interest)

Yes, we are aware of the ongoing `W503 vs W504 discussion <https://www.python.org/dev/peps/pep-0008/#should-a-line-break-before-or-after-a-binary-operator>`_.
W504 would improve readibility.
W504 would improve readability.
However, for now, we want to ensure consistency with the existing code.

Class layout (slots, properties)
Expand Down
2 changes: 1 addition & 1 deletion doc/install.rst
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ You can check the installation location:

pip show pulse2percept

Then add the specificed location to ``$PATH``; see `PATH on Windows`_,
Then add the specified location to ``$PATH``; see `PATH on Windows`_,
`PATH on macOS`_, `PATH on Linux`_.

.. _PATH on Windows: https://helpdeskgeek.com/windows-10/add-windows-path-environment-variable/
Expand Down
4 changes: 2 additions & 2 deletions doc/topics/cortical.rst
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@ For Developers
--------------

In this section we will discuss some of the changes made under the hood
accomadate cortical features, as well as some important notes for developers
accommodate cortical features, as well as some important notes for developers
to keep in mind.

Units
Expand All @@ -449,7 +449,7 @@ the model plotting section.
In order to create your own visual field map, you must create a subclass of
:py:class:`~pulse2percept.topography.CorticalMap`, and implement the `dva_to_v1`
method. In addition, if your map also maps to v2 and/or v3, you must also
implement the `dva_to_v2` and/or `dva_to_v3` methods. Optinally, you can also
implement the `dva_to_v2` and/or `dva_to_v3` methods. Optionally, you can also
implement `v1_to_dva`, `v2_to_dva`, and/or `v3_to_dva` methods.

For example, if you wanted to create a map that mapped `(x, y)` in dva to
Expand Down
2 changes: 1 addition & 1 deletion doc/users/release_notes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ API changes
Backward-incompatible changes
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

* Implants rotation angles are now speicified in degrees, not radians (:pull:`357`)
* Implants rotation angles are now specified in degrees, not radians (:pull:`357`)
* pulse2percept now requires Matplotlib 3.0.2 or newer (:pull:`223`)
* FFMPEG and scikit-video dependencies have been removed (:pull:`196`)
* ``TimeSeries`` has been removed. Please use
Expand Down
2 changes: 1 addition & 1 deletion examples/models/plot_granley2021_biphasic.py
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ def size_modulation(freq, amp, pdur):
# its faster, stripped version `_predict_spatial_batched`. This
# function is only intended to be used if you are repeatedly simulating batches of percepts.
# Since jax compiles each function the first time it is used, using this function only once
# for a singular group of stimuli will be noticably slower than repeatedly applying
# for a singular group of stimuli will be noticeably slower than repeatedly applying
# `predict_percept`. However, splitting a very large set of stimuli into smaller batches and
# using `predict_percept_batched` will be significantly faster than `predict_percept` on each
# individual stimuli.
Expand Down
2 changes: 1 addition & 1 deletion examples/models/plot_nanduri2012.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
#
# Interacting with a model always involves three steps:
#
# 1. **Initalize** the model by passing the desired parameters.
# 1. **Initialize** the model by passing the desired parameters.
# 2. **Build** the model to perform (sometimes expensive) one-time setup
# computations.
# 3. **Predict** the percept for a given stimulus.
Expand Down
2 changes: 1 addition & 1 deletion examples/models/plot_visual_field_maps.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
:py:class:`~pulse2percept.topography.CorticalMap`.
This means that all retinal visual field maps have to specify a ``dva_to_ret`` method,
which transforms visual field coordinates into retinal coordinates, and all cortical
visual field maps have to specify atleast a ``dva_to_v1`` method, which transforms visual
visual field maps have to specify at least a ``dva_to_v1`` method, which transforms visual
field coordinates into cortical V1 coordinates. Cortical models map also specify ``dva_to_v2``
and ``dva_to_v3`` methods, which transform visual field coordinates into cortical V2 and V3.
Most visual field maps also specify the inverse transform, e.g. ``ret_to_dva`` or ``v1_to_dva``.
Expand Down
2 changes: 1 addition & 1 deletion examples/stimuli/plot_psychophysics.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

*This example shows how to use drifting psychophysics-based stimuli for a retinal implant.*

Along with images, videos, and oter built-in stimuli, pulse2percept supports
Along with images, videos, and other built-in stimuli, pulse2percept supports
generating :py:class:`~pulse2percept.stimuli.GratingStimulus` and :py:class:`~pulse2percept.stimuli.BarStimulus` as stimuli
that can be passed as percepts to implants.

Expand Down
2 changes: 1 addition & 1 deletion pulse2percept/implants/cortex/tests/test_neuralink.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def test_LinearEdgeThread():
npt.assert_almost_equal(thread.y, 0)
npt.assert_almost_equal(thread.z, 0)

# elecs arent actually at this spot, but are on the edge, a few microns off
# elecs aren't actually at this spot, but are on the edge, a few microns off
zs = []
for e in thread.electrode_objects:
npt.assert_almost_equal(e.x, thread.r + 7 // 2)
Expand Down
12 changes: 6 additions & 6 deletions pulse2percept/model_selection/optimizers.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ def fit(self, X, y=None, fit_params=None):
self._optimize(X, y, fit_params=fit_params)
if self.verbose:
print(f'Best score: {self._best_score}, Best params: {self._best_params}')
# Use the parameter values found during optimiziation to set the
# Use the parameter values found during optimization to set the
# estimator one more time, then fit it:
self.estimator.set_params(**self._best_params)
if fit_params is None:
Expand Down Expand Up @@ -262,8 +262,8 @@ class FunctionMinimizer(BaseOptimizer):
estimator : ``sklearn.base.estimator``
A scikit-learn estimator, such as a classifier or regressor, that
contains ``fit`` and ``predict`` methods.
serch_params : dict of tupels (lower bound, upper bound)
Dictionary of tupels containing the lower and upper bound of values
serch_params : dict of tuples (lower bound, upper bound)
Dictionary of tuples containing the lower and upper bound of values
for each search parameter.
search_params_init : dict of floats, optional
Initial values of all search parameters. If None, initialize to
Expand Down Expand Up @@ -324,7 +324,7 @@ def _optimize(self, X, y, fit_params=None):
res = minimize(self._calc_error, init, args=(X, y, fit_params),
bounds=bounds, tol=self.tol, options=self.options)
if not res['success']:
print('Optimization unsucessful:')
print('Optimization unsuccessful:')
print(res)

# Pair values of best params with their names to build a dict
Expand All @@ -347,8 +347,8 @@ class ParticleSwarmOptimizer(BaseOptimizer):
estimator : ``sklearn.base.estimator``
A scikit-learn estimator, such as a classifier or regressor, that
contains ``fit`` and ``predict`` methods.
serch_params : dict of tupels (lower bound, upper bound)
Dictionary of tupels containing the lower and upper bound of values
serch_params : dict of tuples (lower bound, upper bound)
Dictionary of tuples containing the lower and upper bound of values
for each search parameter.
swarm_size : int, optional, default: 10 * number of search params
The number of particles in the swarm.
Expand Down
4 changes: 2 additions & 2 deletions pulse2percept/models/_nanduri2012.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ cpdef spatial_fast(const float32[:, ::1] stim,
An array of x or y coordinates at which to calculate the spatial
response (microns)
atten_a : float32
Nominator of the attentuation function (Eq.2 in the paper)
Nominator of the attenuation function (Eq.2 in the paper)
atten_n : float32
Exponent of the attenuation function's denominator (Eq.2 in the paper)
thresh_percept : float32
Expand Down Expand Up @@ -91,7 +91,7 @@ cpdef spatial_fast(const float32[:, ::1] stim,
denom = atten_a + c_pow(zel[idx_el], atten_n)
else:
# Away from the electrode surface, calculate the distance
# to the electrode egde (`d2e`):
# to the electrode edge (`d2e`):
d2e = (c_pow(c_sqrt(d2c) - rel[idx_el], 2) +
c_pow(zel[idx_el], 2))
denom = atten_a + c_pow(c_sqrt(d2e), atten_n)
Expand Down
2 changes: 1 addition & 1 deletion pulse2percept/models/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -757,7 +757,7 @@ def __getattr__(self, attr):
* returns the attribute if found.
* if the attribute exists in both spatial / temporal model,
returns a dictionary ``{'spatial': attr, 'temporal': attr}``.
* if the attribtue is not found, raises an AttributeError.
* if the attribute is not found, raises an AttributeError.

"""
# Check the spatial/temporal model:
Expand Down
2 changes: 1 addition & 1 deletion pulse2percept/models/beyeler2019.py
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,7 @@ def find_closest_axon(self, bundles, xret=None, yret=None,
Note that each bundle will most likely have a different N
xret, yret : scalar or list of scalars
The x,y location on the retina (in microns, where the fovea is the
origin) for which to find the closests axon.
origin) for which to find the closest axon.
return_index : bool, optional
If True, the function will also return the index into ``bundles``
that represents the closest axon
Expand Down
4 changes: 2 additions & 2 deletions pulse2percept/models/cortex/tests/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def test_predict_spatial(ModelClass, regions):
npt.assert_equal(np.all(percept.data[:, half+1:] == 0), True)
npt.assert_equal(np.all(percept.data[:, :half] != 0), True)

# implant only in v1, shouldnt change with v2/v3
# implant only in v1, shouldn't change with v2/v3
vfmap = Polimeni2006Map(k=15, a=0.5, b=90)
model = ModelClass(xrange=(-5, 0), yrange=(-3, 3), xystep=0.1, rho=400, vfmap=vfmap).build()
elecs = [79, 49, 19, 80, 50, 20, 90, 61, 31, 2, 72, 42, 12, 83, 53, 23, 93, 64, 34, 5, 75, 45, 15, 86, 56, 26, 96, 67, 37, 8, 68, 38]
Expand Down Expand Up @@ -171,7 +171,7 @@ def test_plot(ModelClass):


def test_poli_nlink():
# make sure that the polimeni map and neuralink work togther with scoreboard
# make sure that the polimeni map and neuralink work together with scoreboard
# since this is an odd combo of 2d map and 3d implant
model = ScoreboardModel(rho=800, xystep=.5).build()
npt.assert_equal(model.grid.v1.z is None, True)
Expand Down
4 changes: 2 additions & 2 deletions pulse2percept/models/granley2021.py
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ def __setattr__(self, name, value):
# try to set it ourselves, but can't use get_attr
try:
self.__getattribute__(name)
# if we get here, we have the attribute, not (neccesarily) an effects model
# if we get here, we have the attribute, not (necessarily) an effects model
super().__setattr__(name, value)
found = True
except AttributeError:
Expand Down Expand Up @@ -571,7 +571,7 @@ def predict_one(e_params):
def predict_percept(self, implant, t_percept=None):
""" Predicts the spatial response
Override base predict percept to have desired timesteps and
remove unneccesary computation
remove unnecessary computation

Parameters
----------
Expand Down
4 changes: 2 additions & 2 deletions pulse2percept/models/nanduri2012.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class Nanduri2012Spatial(SpatialModel):
Parameters
----------
atten_a : float, optional
Nominator of the attentuation function
Nominator of the attenuation function
atten_n : float32, optional
Exponent of the attenuation function's denominator
vfmap : :py:class:`~pulse2percept.topography.VisualFieldMap`, optional
Expand Down Expand Up @@ -198,7 +198,7 @@ class Nanduri2012Model(Model):
Parameters
----------
atten_a : float, optional
Nominator of the attentuation function (Eq.2 in the paper)
Nominator of the attenuation function (Eq.2 in the paper)
atten_n : float32, optional
Exponent of the attenuation function's denominator (Eq.2 in the paper)
dt : float, optional
Expand Down
8 changes: 4 additions & 4 deletions pulse2percept/models/tests/test_granley2021.py
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ def test_biphasicAxonMapModel(engine):
for atr in ['a' + str(i) for i in range(0, 10)]:
npt.assert_equal(hasattr(model, atr), True)
model.a0 = 5
# Should propogate to size and bright model
# Should propagate to size and bright model
# But should not be a member of streak or spatial
npt.assert_equal(model.spatial.size_model.a0, 5)
npt.assert_equal(model.spatial.bright_model.a0, 5)
Expand All @@ -337,11 +337,11 @@ def test_biphasicAxonMapModel(engine):
npt.assert_equal(model.rho, 432)
npt.assert_equal(model.spatial.size_model.rho, 432)

# If parameter is not an effects model param, it cant be set
# If parameter is not an effects model param, it can't be set
with pytest.raises(FreezeError):
model.invalid_param = 5

# Custom parameters also propogate to effects models
# Custom parameters also propagate to effects models
model = BiphasicAxonMapModel(engine=engine)

class TestSizeModel():
Expand All @@ -361,7 +361,7 @@ def __call__(self, freq, amp, pdur):
class TestInitClassGood():
def __init__(self):
self.model = BiphasicAxonMapModel()
# This shouldnt raise an error
# This shouldn't raise an error
self.model.a0

class TestInitClassBad():
Expand Down
4 changes: 2 additions & 2 deletions pulse2percept/stimuli/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ class Stimulus(PrettyPrint):
The number of time points provided must match the number of time
points extracted from the source type (i.e., M).
Stimuli created from scalars or 1-D NumPy arrays will have no time
componenet, in which case you cannot provide your own time points.
component, in which case you cannot provide your own time points.

metadata : dict, optional
Additional stimulus metadata can be stored in a dictionary.
Expand Down Expand Up @@ -208,7 +208,7 @@ def _from_source(self, source):
time = None
electrodes = None
elif isinstance(source, (list, tuple)):
# List or touple with N elements: 1 electrode, N time points
# List or tuple with N elements: 1 electrode, N time points
data = np.array(source, dtype=np.float32).reshape((1, -1))
time = np.arange(data.shape[-1], dtype=np.float32)
electrodes = None
Expand Down
2 changes: 1 addition & 1 deletion pulse2percept/topography/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
class CoordinateGrid:
"""
Datatype for storing a grid of coordinates
Basically an overriden namedtuple with custom __eq__ method
Basically an overridden namedtuple with custom __eq__ method
"""
x : np.ndarray
y : np.ndarray
Expand Down
2 changes: 1 addition & 1 deletion pulse2percept/topography/cortex.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ def _invert_left_pol(self, theta, radius, inverted = None):

def _invert_left_cart(self, x, y, inverted = None, boundary=0):
"""
'Corrects' the mapping by flipping x axis if neccesary, allowing for both
'Corrects' the mapping by flipping x axis if necessary, allowing for both
left and right hemisphere to use the same map.
"""
# Check if we're reverting from an existing inversion
Expand Down
2 changes: 1 addition & 1 deletion pulse2percept/topography/tests/test_neuropythy.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ def test_dva_to_cortex(regions, jitter_boundary):
def test_Neuralink_from_neuropythy():
nmap = NeuropythyMap('fsaverage', regions=['v1'], jitter_boundary=False)
nlink = Neuralink.from_neuropythy(nmap, locs=np.array([[0, 0], [3, 3], [-2, -2]]))
# 0, 0 should be nan so it wont make one
# 0, 0 should be nan so it won't make one
npt.assert_equal(len(nlink.implants), 2)
npt.assert_equal(nlink.implants['A'].x, nmap.dva_to_v1(3, 3, surface='pial')[0])
npt.assert_equal(nlink.implants['A'].y, nmap.dva_to_v1(3, 3, surface='pial')[1])
Expand Down
7 changes: 7 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,10 @@
universal=1
[easy_install]
zip_ok = False

[codespell]
# Ref: https://github.com/codespell-project/codespell#using-a-config-file
skip = .git*,*.css
check-hidden = true
# ignore-regex =
ignore-words-list = numer,theses
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ def configuration(parent_package='', top_path=None):

config = Configuration(None, parent_package, top_path)

# Avoid non-useful msg:
# Avoid useless msg:
# "Ignoring attempt to set 'name' (from ... "
config.set_options(ignore_setup_xxx_py=True,
assume_default_configuration=True,
Expand Down