diff --git a/.github/workflows/python-package.yml b/.github/workflows/python-package.yml index 4ea5abe..3686c07 100644 --- a/.github/workflows/python-package.yml +++ b/.github/workflows/python-package.yml @@ -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 diff --git a/requirements_dev.txt b/requirements_dev.txt index 47a0e4d..e4fb35c 100644 --- a/requirements_dev.txt +++ b/requirements_dev.txt @@ -2,3 +2,4 @@ flake8 mypy pytest pytest_mock +black \ No newline at end of file diff --git a/setup.cfg b/setup.cfg index bb26738..9be6e58 100644 --- a/setup.cfg +++ b/setup.cfg @@ -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 + diff --git a/src/drift_chamber/__init__.py b/src/drift_chamber/__init__.py index faaea64..26f2f6b 100644 --- a/src/drift_chamber/__init__.py +++ b/src/drift_chamber/__init__.py @@ -1,3 +1,3 @@ +from .driftchamber import DriftChamber from .muon import Muon from .widget import Widget -from .driftchamber import DriftChamber diff --git a/src/drift_chamber/__main__.py b/src/drift_chamber/__main__.py new file mode 100644 index 0000000..9702253 --- /dev/null +++ b/src/drift_chamber/__main__.py @@ -0,0 +1 @@ +print("Executing as a module!") diff --git a/src/drift_chamber/driftchamber.py b/src/drift_chamber/driftchamber.py index 9d60f18..37fbf5f 100644 --- a/src/drift_chamber/driftchamber.py +++ b/src/drift_chamber/driftchamber.py @@ -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: @@ -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 @@ -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: diff --git a/src/drift_chamber/muon.py b/src/drift_chamber/muon.py index b0995ba..949a118 100644 --- a/src/drift_chamber/muon.py +++ b/src/drift_chamber/muon.py @@ -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 @@ -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]: """ diff --git a/src/drift_chamber/widget.py b/src/drift_chamber/widget.py index c9380f2..446abb6 100644 --- a/src/drift_chamber/widget.py +++ b/src/drift_chamber/widget.py @@ -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: diff --git a/tests/test_muon.py b/tests/test_muon.py index 43a60c7..a89625b 100644 --- a/tests/test_muon.py +++ b/tests/test_muon.py @@ -1,5 +1,6 @@ import sys from unittest.mock import MagicMock + sys.modules["drift_chamber.widget"] = MagicMock() import numpy as np @@ -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) @@ -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