Skip to content

Commit

Permalink
fix linting
Browse files Browse the repository at this point in the history
  • Loading branch information
joeb42 committed Oct 29, 2023
1 parent 93322d0 commit 2689e3c
Show file tree
Hide file tree
Showing 9 changed files with 40 additions and 20 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/python-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ jobs:
python -m pip install -r requirements_dev.txt
- name: Lint with flake8
run: |
flake8 .
flake8 src
# stop the build if there are Python syntax errors or undefined names
# flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
# # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
Expand Down
1 change: 1 addition & 0 deletions requirements_dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ flake8
mypy
pytest
pytest_mock
black
7 changes: 7 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,10 @@ package_dir =
=src
zip_safe = no

[flake8]
extend-ignore = E402
max-line-length = 128
per-file-ignores =
# imported but unused
__init__.py: F401

2 changes: 1 addition & 1 deletion src/drift_chamber/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
from .driftchamber import DriftChamber
from .muon import Muon
from .widget import Widget
from .driftchamber import DriftChamber
1 change: 1 addition & 0 deletions src/drift_chamber/__main__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
print("Executing as a module!")
18 changes: 10 additions & 8 deletions src/drift_chamber/driftchamber.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
import numpy as np
from scipy import stats, sparse
import math
import copy
import math

import matplotlib

matplotlib.use("TkAgg")
import matplotlib.pyplot as plt
import matplotlib.animation as animation
from matplotlib.colors import LogNorm
import matplotlib.cm
from .muon import Muon, MissedDetector
import matplotlib.pyplot as plt
import numpy as np
from matplotlib.colors import LogNorm
from scipy import sparse, stats

from .muon import Muon


class DriftChamber:
Expand Down Expand Up @@ -44,7 +46,7 @@ def __init__(
Takes positive numerical spacing, numerical E (electric field), positive numerical D (diffusivity)
and positive numerical tau (timestep) as optional kwargs.
Also takes mat kwarg, True by default, this should be set to False if need to avoid constructing matrix
(e.g for investigating small spacings in the initial ionisation track that would otherwise generate very large matricies).
(e.g for small spacings in the initial ionisation track that would otherwise generate very large matricies).
"""
self.grid: np.ndarray = np.zeros((int(30 / spacing), (int(50 / spacing))))
self.spacing = spacing
Expand Down Expand Up @@ -73,7 +75,7 @@ def __init__(

def __str__(self) -> str:
"""String representation of DriftChamber object for ease of debugging"""
return f"""Drift Chamber object, grid spacing of {self.spacing}cm,
return f"""Drift Chamber object, grid spacing of {self.spacing}cm,
diffusivity of {self.D}, E-field of {self.E}."""

def initial_ion(self, muon: Muon) -> None:
Expand Down
13 changes: 9 additions & 4 deletions src/drift_chamber/muon.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ class Muon:
zen: Zenith angle, random value distributed proportional to cos^2 between 3pi/2 and pi/2
energy: Random log-normal value in GeV of mean 6.55 and stdev 1.8
charge: Randomly generated charge of muon takes values +1 (with probability 0.53) and -1 (with probability 0.47)
x_coord: x coordinate of muon on plane in cm (direction into the page in relation to diagram above)
y_coord: y coordinate of muon on plane in cm (horizontal direction in relation to diagram above)
height: height of plane above detector in cm (vertical direction in relation to diagram above). Must be >= 30 (height of detector)
x_coord: x coordinate of muon on plane in cm (direction into the page wrt diagram above)
y_coord: y coordinate of muon on plane in cm (horizontal direction wrt diagram)
height: height of plane above detector in cm (vertical direction wrt diagram). Must be >= 30 (height of detector)
"""

POSITIVE_CHARGE_PROBABILITY = 0.53
Expand Down Expand Up @@ -39,7 +39,12 @@ def __repr__(self) -> str:
String representation of Muon object for ease of debugging and for use in MissedDetector exception
"""

return f"Muon: energy: {self.energy:.0f} GeV, charge: {self.charge}e, zenith: {self.zen:.3f}, azimuthal: {self.azi:.3f}, x: {self.x_coord:.3f}, y: {self.y_coord:.3f}"
return (f"Muon: energy: {self.energy:.0f} GeV,"
"charge: {self.charge}e,"
"zenith: {self.zen:.3f},"
"azimuthal: {self.azi:.3f},"
"x: {self.x_coord:.3f},"
"y: {self.y_coord:.3f}")

def starting_coords(self) -> tuple[float, float]:
"""
Expand Down
11 changes: 7 additions & 4 deletions src/drift_chamber/widget.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
import tkinter as tk
from tkinter import ttk

import matplotlib

matplotlib.use("TkAgg")
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg
import copy

import matplotlib.animation as animation
from matplotlib.colors import LogNorm
import matplotlib.cm
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg
from matplotlib.colors import LogNorm
from matplotlib.figure import Figure
import copy
from .muon import Muon, MissedDetector

from .driftchamber import DriftChamber
from .muon import MissedDetector, Muon


class Widget:
Expand Down
5 changes: 3 additions & 2 deletions tests/test_muon.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import sys
from unittest.mock import MagicMock

sys.modules["drift_chamber.widget"] = MagicMock()

import numpy as np
Expand All @@ -26,7 +27,7 @@ def test_init(mocker):
r,
azi / (2 * np.pi),
x_coord,
y_coord
y_coord,
]
muon = Muon()
mock_log_normal.assert_called_once_with(6.55, 1.8)
Expand All @@ -35,5 +36,5 @@ def test_init(mocker):
assert muon.energy == mock_log_normal.return_value
assert muon.zen == zen
assert muon.azi == azi
assert muon.x_coord == x_coord * 100 - 50
assert muon.x_coord == x_coord * 100 - 50
assert muon.y_coord == y_coord * 80 - 15

0 comments on commit 2689e3c

Please sign in to comment.