Skip to content

Commit

Permalink
Add codespell and ruff (#32)
Browse files Browse the repository at this point in the history
* Create codespell.yml

* Create ruff.yml

* Allow ruff workflow to run on command

* Fix spelling, exclude lockin

* Fix some lint errors
  • Loading branch information
rly authored Jan 8, 2025
1 parent c0dc913 commit 1388254
Show file tree
Hide file tree
Showing 11 changed files with 44 additions and 12 deletions.
14 changes: 14 additions & 0 deletions .github/workflows/codespell.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name: Codespell
on:
pull_request:
workflow_dispatch:

jobs:
codespell:
name: Check for spelling errors
runs-on: ubuntu-latest
steps:
- name: Checkout repo
uses: actions/checkout@v4
- name: Codespell
uses: codespell-project/actions-codespell@v2
13 changes: 13 additions & 0 deletions .github/workflows/ruff.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
name: Ruff
on:
pull_request:
workflow_dispatch:

jobs:
ruff:
runs-on: ubuntu-latest
steps:
- name: Checkout repo
uses: actions/checkout@v4
- name: Run ruff
uses: astral-sh/ruff-action@v3
2 changes: 1 addition & 1 deletion notebook/read_phot_box_files.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -721,7 +721,7 @@
"print(sig2)\n",
"print(OG_signals['sig2'])\n",
"\n",
"# print(f\"Lenth of visits: {len(visits)}\")\n",
"# print(f\"Length of visits: {len(visits)}\")\n",
"# print(visits)\n",
"\n",
"import matplotlib.pyplot as plt\n",
Expand Down
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ exclude = [

[tool.codespell]
skip = "htmlcov,.git,.mypy_cache,.pytest_cache,.coverage,*.pdf,*.svg,venvs"
ignore-words-list = "datas,assertIn"
ignore-words-list = "datas,assertIn,lockin"

[tool.coverage.run]
branch = true
Expand All @@ -99,7 +99,7 @@ preview = true
exclude = ".git|.mypy_cache|.tox|.venv|venv|.ipynb_checkpoints|_build/|dist/|__pypackages__|.ipynb"

[tool.ruff]
lint.select = ["E", "F", "T100", "T201", "T203"]
lint.select = ["E", "F", "T100", "T203"]
exclude = [
".git",
".tox",
Expand Down
4 changes: 4 additions & 0 deletions src/jdb_to_nwb/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
from ._version import __version__

__all__ = [
"__version__",
]
2 changes: 1 addition & 1 deletion src/jdb_to_nwb/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def create_nwbs(
# reset the session start time to the earliest of the data streams
nwbfile.fields["session_start_time"] = datetime.now(tz.tzlocal())

print(f"Writing file, including iterative read from raw ephys data...")
print("Writing file, including iterative read from raw ephys data...")

with NWBHDF5IO(output_nwb_file_path, mode="w") as io:
io.write(nwbfile)
Expand Down
4 changes: 2 additions & 2 deletions src/jdb_to_nwb/convert_behavior.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ def load_maze_configurations(maze_configuration_file_path: Path):
maze = set(map(int, line.strip().split(",")))
maze_sequence.append(maze)
return maze_sequence
except:
warnings.warn(f"Could not load maze configurations from {maze_configuration_file_path}")
except Exception as e:
warnings.warn(f"Could not load maze configurations from {maze_configuration_file_path}: {e}")
return []


Expand Down
2 changes: 1 addition & 1 deletion src/jdb_to_nwb/convert_photometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ def airPLS(data, lambda_=1e8, max_iterations=50):
"""

num_data_points = data.shape[0]
weights = np.ones(num_data_points) # Set the intial weights to 1 to treat all points equally
weights = np.ones(num_data_points) # Set the initial weights to 1 to treat all points equally

# Loop runs up to 'max_iterations' times to adjust the weights and fit the baseline
for i in range(1, max_iterations + 1):
Expand Down
2 changes: 1 addition & 1 deletion src/jdb_to_nwb/convert_raw_ephys.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ def add_electrode_data(
).all(), "First column is not the same as the second column."
electrode_data.drop(columns=["Channel Number"], inplace=True)

# Get electrode coordinates as a (2, 256) arrray
# Get electrode coordinates as a (2, 256) array
# The first column is the relative x coordinate, and the second column is the relative y coordinate
channel_geometry = get_electrode_coords() # formerly pd.read_csv(channel_geometry_file_path, header=None)

Expand Down
2 changes: 1 addition & 1 deletion tests/test_convert_behavior.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def test_convert_behavior():
assert photometry_start_in_arduino_time == 55520059.6736

# Note that we do not run validation tests on the trial- and block-level data (e.g. trials/blocks are
# enumerated corrrectly, block metadata is valid, number of trials per block adds to the
# enumerated correctly, block metadata is valid, number of trials per block adds to the
# total number of trials, block start/end times are aligned to trial start/end times)
# because these checks are already run by validate_trial_and_block_data every time add_behavior is run

Expand Down
7 changes: 4 additions & 3 deletions tests/test_convert_photometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,8 @@ def test_add_photometry_from_signals_mat():

# Check that the lengths match
assert len(green_z_scored_dFF) == len(green_z_scored_dFF_reference), (
f"Data length mismatch: z_scored_green_dFF has {len(green_z_scored_dFF)} points, " f"but the reference signal has {len(green_z_scored_dFF_reference)} points."
f"Data length mismatch: z_scored_green_dFF has {len(green_z_scored_dFF)} points, "
f"but the reference signal has {len(green_z_scored_dFF_reference)} points."
)

# Check that the z-scored green dF/F signal in the nwbfile matches the reference green signal (within a tolerance)
Expand All @@ -119,7 +120,7 @@ def test_add_photometry_from_signals_mat():
green_z_scored_dFF_reference,
atol=0.005,
rtol=0.05,
err_msg=f"Data mismatch between nwbfile z_scored_green_dFF and reference data",
err_msg="Data mismatch between nwbfile z_scored_green_dFF and reference data",
)


Expand Down Expand Up @@ -204,7 +205,7 @@ def test_add_photometry_from_pyphotometry():
This version of the test uses the ppd file from pyPhotometry to add photometry signals to the NWB.
TODO: Implement this test once adding photometry via ppd file is inplemented!!
TODO: Implement this test once adding photometry via ppd file is implemented!!
"""

# Create a test metadata dictionary with pyPhotometry data
Expand Down

0 comments on commit 1388254

Please sign in to comment.