diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml new file mode 100644 index 0000000..4731f82 --- /dev/null +++ b/.github/workflows/main.yaml @@ -0,0 +1,43 @@ +name: CI + +# We can specify which Github events will trigger a CI build +on: push + +# now define a single job 'build' (but could define more) +jobs: + + build: + + strategy: + matrix: + os: [ubuntu-latest, macos-latest, windows-latest] + python-version: ["3.9", "3.10"] + + runs-on: ${{ matrix.os }} + + # a job is a seq of steps + steps: + + # Next we need to checkout out repository, and set up Python + # A 'name' is just an optional label shown in the log - helpful to clarify progress - and can be anything + - name: Checkout repository + uses: actions/checkout@v2 + + - name: Set up Python 3.9 + uses: actions/setup-python@v2 + with: + python-version: ${{ matrix.python-version }} + + - name: Install Python dependencies + run: | + python3 -m pip install --upgrade pip + pip3 install -r requirements.txt + + + - name: Test with PyTest + run: | + python -m pytest --cov=fusion_toolbox tests/ + + - name: Check style with Pylint + run: | + python3 -m pylint --fail-under=0 --reports=y fusion_toolbox \ No newline at end of file diff --git a/fusion_toolbox/shot_analysis.py b/fusion_toolbox/shot_analysis.py index 92f20fb..d963179 100644 --- a/fusion_toolbox/shot_analysis.py +++ b/fusion_toolbox/shot_analysis.py @@ -2,7 +2,7 @@ def smooth(data): """Smooth the data to remove noise Args: - data (_type_): _description_ + data (_type_): blablabla """ pass diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..a43e5db --- /dev/null +++ b/requirements.txt @@ -0,0 +1,5 @@ +matplotlib>=3.0.0 +numpy>=1.0.0 +pytest>=7.0.0 +pytest-cov>=4.0.0 +pylint>=2.0.0 \ No newline at end of file diff --git a/test/__init__.py b/tests/__init__.py similarity index 100% rename from test/__init__.py rename to tests/__init__.py diff --git a/tests/test_Bfield.py b/tests/test_Bfield.py new file mode 100644 index 0000000..03e5521 --- /dev/null +++ b/tests/test_Bfield.py @@ -0,0 +1,53 @@ +''' Module to test Bfield.py calculations''' +from math import pi +import numpy as np +import numpy.testing as npt +import pytest +from fusion_toolbox.Bfield import Coil + + +MU_0 = 4*pi*1E-7 # T * m / A + +def generate_pf_coil_xyz(coil_radius, num_coil_pts = 100, coil_height = 0): + ''' + Get xyz coordinates of points along a pf coil + coil radius: [m] + num_coil_points: Number of points used to define the coil (int) + coil_height: pf coil height [m] + Returns: xyz - np.ndarray [N,3] + ''' + thetas = np.linspace(0, 2*pi, num_coil_pts) + xyz = np.zeros((num_coil_pts,3)) + xyz[:,0] = coil_radius * np.cos(thetas) + xyz[:,1] = coil_radius * np.sin(thetas) + xyz[:,2] = coil_height + return xyz + +def analytic_B_center_of_pf_coil(current, coil_radius): + ''' + Analytic calculation of magnetic field at the center of a circular pf coil + current: [A] + coil radius: [m] + returns: B-field [T] + ''' + return np.array([0,0,MU_0 * current / (2 * coil_radius)]) + +@pytest.mark.parametrize( + "current, coil_radius", + [[1E3,0.3], [1E5, 0.02], [1E7, 0.004], [1E2, 1] + ]) +def test_B_center_of_pf_circular_coil(current, coil_radius): + ''' + current: [A] + coil radius: [m] + Checks the calculated field at the center of a circular coil against the analytic solution + ''' + + # Generate test coil and calculate the field at the center + xyz = generate_pf_coil_xyz(coil_radius, num_coil_pts= int(1E4)) + test_coil = Coil(xyz, current) + B_center = test_coil.B([np.array([0,0,0])]) + + # Compare to analytic calculation + B_analytic = [analytic_B_center_of_pf_coil(current,coil_radius)] + npt.assert_almost_equal(B_center, B_analytic, decimal = 4) diff --git a/tests/test_empty.py b/tests/test_empty.py new file mode 100644 index 0000000..f9d032b --- /dev/null +++ b/tests/test_empty.py @@ -0,0 +1,4 @@ + + +def test_empty(): + pass \ No newline at end of file