Skip to content

Commit

Permalink
Merge pull request #296 from boutproject/ruff-fixes
Browse files Browse the repository at this point in the history
Fix linting errors
  • Loading branch information
ZedThree authored Nov 15, 2023
2 parents 3b33eeb + 38c5880 commit 4670160
Show file tree
Hide file tree
Showing 25 changed files with 664 additions and 742 deletions.
19 changes: 0 additions & 19 deletions .github/workflows/master.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,22 +68,3 @@ jobs:
- name: Test with pytest
run: |
pytest -vv --long --cov
# Need to tidy up the things that flake8 finds before we activate this
#flake8:

# runs-on: ubuntu-latest
# if: always()

# steps:
# - uses: actions/checkout@v2
# - name: Set up Python
# uses: actions/setup-python@v1
# - name: Install dependencies
# run: |
# python -m pip install --upgrade pip
# - name: Lint with flake8
# run: |
# pip install flake8
# flake8
18 changes: 0 additions & 18 deletions .github/workflows/pythonpackage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,21 +68,3 @@ jobs:
- name: Test with pytest
run: |
pytest -vv --long --cov
# Need to tidy up the things that flake8 finds before we activate this
#flake8:

# runs-on: ubuntu-latest
# if: always()

# steps:
# - uses: actions/checkout@v2
# - name: Set up Python
# uses: actions/setup-python@v1
# - name: Install dependencies
# run: |
# python -m pip install --upgrade pip
# - name: Lint with flake8
# run: |
# pip install flake8
# flake8
15 changes: 15 additions & 0 deletions .github/workflows/ruff.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
name: Linting
on: [pull_request]

jobs:
dependency-review:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: '3.x'
- name: Install ruff
run: pip install ruff
- name: Run ruff
run: ruff xbout
1 change: 0 additions & 1 deletion examples/boutmodules/tests/test_stormdataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

from xarray import concat
from xbout import open_boutdataset
from xbout.tests.test_load import bout_xyt_example_files


@pytest.mark.skip
Expand Down
3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -78,3 +78,6 @@ write_to = "xbout/_version.py"

[tool.setuptools]
packages = ["xbout"]

[tool.ruff]
ignore = ["E501"]
20 changes: 16 additions & 4 deletions xbout/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,25 @@

from .fastoutput import open_fastoutput

try:
from importlib.metadata import version, PackageNotFoundError
except ModuleNotFoundError:
from importlib_metadata import version, PackageNotFoundError
from importlib.metadata import version, PackageNotFoundError

try:
__version__ = version(__name__)
except PackageNotFoundError:
from setuptools_scm import get_version

__version__ = get_version(root="..", relative_to=__file__)

__all__ = [
"open_boutdataset",
"collect",
"geometries",
"register_geometry",
"REGISTERED_GEOMETRIES",
"BoutDataArrayAccessor",
"BoutDatasetAccessor",
"animate_pcolormesh",
"animate_poloidal",
"plot_separatrix",
"open_fastoutput",
]
5 changes: 0 additions & 5 deletions xbout/boutdataarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,6 @@ def interpolate_parallel(
# Select a particular 'region' and interpolate to higher parallel resolution
da = self.data
region = da.bout._regions[region]
tcoord = da.metadata["bout_tdim"]
xcoord = da.metadata["bout_xdim"]
ycoord = da.metadata["bout_ydim"]
zcoord = da.metadata["bout_zdim"]
Expand Down Expand Up @@ -385,9 +384,6 @@ def interpolate_parallel(

return da

def add_cartesian_coordinates(self):
return _add_cartesian_coordinates(self.data)

def add_cartesian_coordinates(self):
"""
Add Cartesian (X,Y,Z) coordinates.
Expand Down Expand Up @@ -950,7 +946,6 @@ def interpolate_from_unstructured(
method = "linear"

# extend input coordinates to cover all dims, so we can flatten them
input_coords = []
for coord in kwargs:
data = da[coord]
missing_dims = tuple(set(dims) - set(data.dims))
Expand Down
7 changes: 0 additions & 7 deletions xbout/boutdataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,9 +266,6 @@ def find_with_dims(first_var, dims):

return ds

def add_cartesian_coordinates(self):
return _add_cartesian_coordinates(self.data)

def integrate_midpoints(self, variable, *, dims=None, cumulative_t=False):
"""
Integrate using the midpoint rule for spatial dimensions, and trapezium rule for
Expand Down Expand Up @@ -619,7 +616,6 @@ def interpolate_to_cartesian(

from scipy.interpolate import (
RegularGridInterpolator,
griddata,
)

# Create Cylindrical coordinates for intermediate grid
Expand Down Expand Up @@ -681,9 +677,6 @@ def interp_single_time(da):
# just use da.min().item() here (to get a scalar value instead of a
# zero-size array) because .item() doesn't work for dask arrays (yet!).

datamin = float_type(da.min().values)
datamax = float_type(da.max().values)

if tdim in da.dims:
data_cartesian = np.zeros((nt, nX, nY, nZ), dtype=float_type)
for tind in range(nt):
Expand Down
2 changes: 2 additions & 0 deletions xbout/calc/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
from .turbulence import rms

__all__ = ["rms"]
5 changes: 2 additions & 3 deletions xbout/geometries.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import xarray as xr
import numpy as np

from .region import Region, _create_regions_toroidal, _create_single_region
from .region import _create_regions_toroidal, _create_single_region
from .utils import (
_add_attrs_to_var,
_set_attrs_on_all_vars,
Expand Down Expand Up @@ -156,7 +156,6 @@ def apply_geometry(ds, geometry_name, *, coordinates=None, grid=None):
_add_attrs_to_var(updated_ds, xcoord)

if ycoord not in updated_ds.coords:
ny = updated_ds.dims[ycoord]
# dy should always be constant in x, so it is safe to convert to a 1d
# coordinate. [The y-coordinate has to be a 1d coordinate that labels x-z
# slices of the grid (similarly x-coordinate is 1d coordinate that labels y-z
Expand Down Expand Up @@ -206,7 +205,7 @@ def apply_geometry(ds, geometry_name, *, coordinates=None, grid=None):
if bout_v5:
if not np.all(updated_ds["dz"].min() == updated_ds["dz"].max()):
raise ValueError(
f"Spacing is not constant. Cannot create z coordinate"
"Spacing is not constant. Cannot create z coordinate"
)

dz = updated_ds["dz"].min()
Expand Down
14 changes: 6 additions & 8 deletions xbout/plotting/plotfuncs.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
_decompose_regions,
_is_core_only,
_k3d_plot_isel,
_make_structured_triangulation,
plot_separatrices,
plot_targets,
)
Expand Down Expand Up @@ -48,7 +47,7 @@ def plot_regions(da, ax=None, **kwargs):
da_regions = _decompose_regions(da)

colored_regions = [
xr.full_like(da_region, fill_value=num / len(regions))
xr.full_like(da_region, fill_value=num / len(da_regions))
for num, da_region in enumerate(da_regions.values())
]

Expand Down Expand Up @@ -311,11 +310,11 @@ def plot2d_wrapper(

for x, y in zip(x_regions, y_regions):
if (
not da.metadata["bout_xdim"] in x.dims
and not da.metadata["bout_ydim"] in x.dims
da.metadata["bout_xdim"] not in x.dims
and da.metadata["bout_ydim"] not in x.dims
) or (
not da.metadata["bout_xdim"] in y.dims
and not da.metadata["bout_ydim"] in y.dims
da.metadata["bout_xdim"] not in y.dims
and da.metadata["bout_ydim"] not in y.dims
):
# Small regions around X-point do not have segments in x- or y-directions,
# so skip
Expand Down Expand Up @@ -545,7 +544,6 @@ def plot3d(
from scipy.interpolate import (
RegularGridInterpolator,
griddata,
LinearNDInterpolator,
)

print("start interpolating")
Expand Down Expand Up @@ -801,7 +799,7 @@ def create_or_update_plot(plot_objects=None, tind=None, this_save_as=None):
# First create png files in the temporary directory
temp_path = Path(d)
temp_save_as = str(temp_path.joinpath("temp.png"))
print(f"tind=0")
print("tind=0")
plot_objects = create_or_update_plot(
tind=0, this_save_as=temp_save_as
)
Expand Down
1 change: 0 additions & 1 deletion xbout/plotting/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,6 @@ def plot_targets(da, ax, *, x="R", y="Z", hatching=True):

da0 = list(da_regions.values())[0]

xcoord = da0.metadata["bout_xdim"]
ycoord = da0.metadata["bout_ydim"]

if da0.metadata["keep_yboundaries"]:
Expand Down
10 changes: 1 addition & 9 deletions xbout/region.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from copy import copy, deepcopy
from copy import deepcopy
import numpy as np
import xarray as xr
from .utils import _set_attrs_on_all_vars
Expand Down Expand Up @@ -145,9 +145,6 @@ def __repr__(self):
result += f"\t{attr}\t{val}\n"
return result

def __eq__(self, other):
return vars(self) == vars(other)

def get_slices(self, mxg=0, myg=0):
"""
Return x- and y-dimension slices that select this region from the global
Expand Down Expand Up @@ -1229,11 +1226,6 @@ def _create_single_region(ds, periodic_y=True):
nx = ds.metadata["nx"]
ny = ds.metadata["ny"]

mxg = ds.metadata["MXG"]
myg = ds.metadata["MYG"]
# keep_yboundaries is 1 if there are y-boundaries and 0 if there are not
ybndry = ds.metadata["keep_yboundaries"] * myg

connection = "all" if periodic_y else None

regions = {
Expand Down
Loading

0 comments on commit 4670160

Please sign in to comment.