Skip to content

Commit

Permalink
Merge pull request #5 from boutproject/cleanup
Browse files Browse the repository at this point in the history
Cleanup some dead code as well as add GHA for linting
  • Loading branch information
dschwoerer authored Nov 1, 2021
2 parents 4f419fc + 94f9dfe commit fbb837f
Show file tree
Hide file tree
Showing 15 changed files with 74 additions and 75 deletions.
39 changes: 39 additions & 0 deletions .github/workflows/black-fix.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: linting

on: [push, pull_request]

defaults:
run:
shell: bash

jobs:
black:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
with:
ref: ${{ github.head_ref }}

- name: Install black
run: |
sudo apt update -y
sudo apt -y install python3-pip python3-setuptools python3-wheel
pip3 install black isort
- name: Version
run: |
python3 --version
$HOME/.local/bin/black --version
$HOME/.local/bin/isort --version
- name: Run black
run: |
pwd
ls
$HOME/.local/bin/black zoidberg
$HOME/.local/bin/isort zoidberg
- uses: stefanzweifel/git-auto-commit-action@v4
with:
commit_message: "[skip ci] Apply black/isort changes"
21 changes: 0 additions & 21 deletions .github/workflows/black.yml

This file was deleted.

5 changes: 1 addition & 4 deletions zoidberg/__init__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
import zoidberg
from . import grid
from . import field
from . import fieldtracer
from . import plot

from . import field, fieldtracer, grid, plot
from .zoidberg import make_maps, write_maps

__all__ = [
Expand Down
34 changes: 11 additions & 23 deletions zoidberg/field.py
Original file line number Diff line number Diff line change
Expand Up @@ -317,22 +317,8 @@ def Rfunc(self, x, z, phi):


try:
from sympy import (
Symbol,
atan2,
cos,
sin,
log,
pi,
sqrt,
lambdify,
Piecewise,
Sum,
gamma,
And,
factorial,
diff,
)
from sympy import (And, Piecewise, Sum, Symbol, atan2, cos, diff,
factorial, gamma, lambdify, log, pi, sin, sqrt)

class StraightStellarator(MagneticField):
"""A "rotating ellipse" stellarator without curvature
Expand Down Expand Up @@ -1124,7 +1110,7 @@ def read_vmec_file(self, vmec_file, ntheta=None, nzeta=None):

def __init__(self, vmec_file, ntheta=None, nzeta=None, nr=32, nz=32):
# Only needed here
from scipy.interpolate import griddata, RegularGridInterpolator
from scipy.interpolate import RegularGridInterpolator, griddata

self.read_vmec_file(vmec_file, ntheta, nzeta)

Expand Down Expand Up @@ -1433,8 +1419,8 @@ def __init__(
While the description are at:
http://svvmec1.ipp-hgw.mpg.de:8080/vmecrest/v1/Coil_currents_1_AA_T_0011.pdf
"""
from scipy.interpolate import RegularGridInterpolator
import numpy as np
from scipy.interpolate import RegularGridInterpolator

## create 1D arrays of cylindrical coordinates
r = np.linspace(x_range[0], x_range[-1], nx)
Expand Down Expand Up @@ -1497,13 +1483,14 @@ def field_values(r, phi, z, configuration=0, plot_poincare=False):
Contact [email protected] for questions
"""
from osa import Client
import os.path
import xarray as xr
import pickle
import matplotlib.pyplot as plt
from time import sleep

import matplotlib.pyplot as plt
import xarray as xr
from osa import Client

tracer = Client("http://esb.ipp-hgw.mpg.de:8280/services/FieldLineProxy?wsdl")

nx = r.shape[0]
Expand Down Expand Up @@ -1684,10 +1671,11 @@ def plasma_field(r, phi, z, wout_file="wout.nc"):
Contact [email protected] for questions
"""
from osa import Client
import os.path
import pickle

from osa import Client

cl = Client("http://esb.ipp-hgw.mpg.de:8280/services/Extender?wsdl")

vmecURL = "http://svvmec1.ipp-hgw.mpg.de:8080/vmecrest/v1/w7x_ref_1/wout.nc"
Expand Down Expand Up @@ -1826,8 +1814,8 @@ def __init__(
phi_range=[0, 2 * np.pi],
vmec_id="w7x_ref_171",
):
from scipy.interpolate import RegularGridInterpolator
import numpy as np
from scipy.interpolate import RegularGridInterpolator

## create 1D arrays of cylindrical coordinates
r = np.linspace(x_range[0], x_range[-1], nx)
Expand Down
2 changes: 0 additions & 2 deletions zoidberg/grid.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import division

import numpy as np

# Import classes representing poloidal grids
Expand Down
4 changes: 2 additions & 2 deletions zoidberg/plot.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from . import fieldtracer
import warnings

import numpy as np

import warnings
from . import fieldtracer

try:
import matplotlib.animation as anim
Expand Down
6 changes: 3 additions & 3 deletions zoidberg/poloidal_grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@
"""

import warnings

import numpy as np
from numpy import pi, linspace, zeros
from numpy import linspace, pi, zeros
from scipy.interpolate import RectBivariateSpline
from scipy.spatial import cKDTree as KDTree

import warnings

try:
import matplotlib.pyplot as plt

Expand Down
10 changes: 4 additions & 6 deletions zoidberg/rzline.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@
"""

import numpy as np
import warnings

from numpy import pi, linspace, sqrt, cos, sin, append, argmin
from scipy.interpolate import splrep, splev, interp1d
import numpy as np
from numpy import append, argmin, cos, linspace, pi, sin, sqrt
from scipy.integrate import cumtrapz

import warnings
from scipy.interpolate import interp1d, splev, splrep

try:
import matplotlib.pyplot as plt
Expand Down Expand Up @@ -518,7 +517,6 @@ def line_from_points(rarray, zarray, show=False):

#############################################################################
# Define the magnetic field

# Length in y after which the coils return to their starting (R,Z) locations
yperiod = 10.0

Expand Down
3 changes: 2 additions & 1 deletion zoidberg/test_field.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import numpy as np
from .field import Slab, CurvedSlab

from .field import CurvedSlab, Slab


def test_slab():
Expand Down
3 changes: 1 addition & 2 deletions zoidberg/test_fieldtracer.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import numpy as np

from . import fieldtracer
from . import field
from . import field, fieldtracer


def test_slab():
Expand Down
3 changes: 2 additions & 1 deletion zoidberg/test_grid.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from .grid import rectangular_grid
import numpy as np

from .grid import rectangular_grid


def test_getPoloidalGrid():
# Create a simple non-periodic grid
Expand Down
3 changes: 1 addition & 2 deletions zoidberg/test_poloidal_grid.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import numpy as np

from . import rzline
from . import poloidal_grid
from . import poloidal_grid, rzline


def test_out_of_domain():
Expand Down
5 changes: 2 additions & 3 deletions zoidberg/test_rzline.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from . import rzline

import numpy as np

from . import rzline


def test_circular_boundaries():
inner = rzline.circle(R0=1.0, r=1.0, n=20)
Expand Down Expand Up @@ -37,7 +37,6 @@ def test_distance():
def test_order_by_distance():
# Check the RZline.equallySpaced function
inner = rzline.circle(R0=1.0, r=1.0, n=20)
outer = rzline.circle(R0=1.0, r=2.0, n=20)

new_inner = inner.equallySpaced(n=10)

Expand Down
4 changes: 3 additions & 1 deletion zoidberg/test_zoidberg.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from itertools import chain, product

import numpy as np
from . import zoidberg, grid, field

from . import field, grid, zoidberg


def test_make_maps_slab():
Expand Down
7 changes: 3 additions & 4 deletions zoidberg/zoidberg.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
from __future__ import division
from collections import namedtuple
from itertools import chain

import numpy as np
from boututils import datafile as bdata
from collections import namedtuple
from itertools import chain

from . import fieldtracer
from .progress import update_progress
Expand Down Expand Up @@ -483,8 +482,8 @@ def upscale(field, maps, upscale_factor=4, quiet=True):
"""

from scipy.ndimage.interpolation import map_coordinates
from scipy.interpolate import griddata
from scipy.ndimage.interpolation import map_coordinates

xt_prime = maps["forward_xt_prime"]
zt_prime = maps["forward_zt_prime"]
Expand Down

0 comments on commit fbb837f

Please sign in to comment.