From 1ab5e72a95f2e05e3075d0dc5b6ba80531358988 Mon Sep 17 00:00:00 2001 From: David Bold Date: Thu, 23 Mar 2023 15:09:38 +0100 Subject: [PATCH 1/4] Add basic xarray support Allows to write DataArrays and preserve their dimensions --- boututils/datafile.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/boututils/datafile.py b/boututils/datafile.py index b14cf1e..0072c88 100644 --- a/boututils/datafile.py +++ b/boututils/datafile.py @@ -511,6 +511,8 @@ def _bout_dimensions_from_var(self, data): try: bout_type = data.attributes["bout_type"] except AttributeError: + if hasattr(data, "dims"): + return data.dims defdims_list = [ (), ("t",), @@ -542,6 +544,9 @@ def write(self, name, data, info=False): # Get the variable type t = type(data).__name__ + if t == "DataArray": + t = data.dtype.str + if t == "NoneType": print("DataFile: None passed as data to write. Ignoring") return From 0a34513731c38ac7e934abc174d75e7602f3a1f6 Mon Sep 17 00:00:00 2001 From: David Bold Date: Thu, 23 Mar 2023 15:15:53 +0100 Subject: [PATCH 2/4] CI: Update flake8 to github repo --- .pre-commit-config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 0b37abe..157d346 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -6,7 +6,7 @@ repos: hooks: - id: black - - repo: https://gitlab.com/pycqa/flake8 + - repo: https://github.com/pycqa/flake8 rev: 3.9.2 hooks: - id: flake8 From bf2335d80c66df19c7c43492a0a2fd7b8bfac4c7 Mon Sep 17 00:00:00 2001 From: David Bold Date: Thu, 23 Mar 2023 15:19:59 +0100 Subject: [PATCH 3/4] Auto update pre-commit-config --- .pre-commit-config.yaml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 157d346..96c0be0 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -2,17 +2,17 @@ # pre-commit autoupdate repos: - repo: https://github.com/psf/black - rev: 22.3.0 + rev: 23.1.0 hooks: - id: black - repo: https://github.com/pycqa/flake8 - rev: 3.9.2 + rev: 6.0.0 hooks: - id: flake8 - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.1.0 + rev: v4.4.0 hooks: - id: trailing-whitespace - id: end-of-file-fixer @@ -24,6 +24,6 @@ repos: args: [--prose-wrap=always, --print-width=88] - repo: https://github.com/PyCQA/isort - rev: 5.10.1 + rev: 5.12.0 hooks: - id: isort From 7ba5147b6256a5c021f2a3b1fc6be8270d69ff99 Mon Sep 17 00:00:00 2001 From: David Bold Date: Thu, 23 Mar 2023 15:20:08 +0100 Subject: [PATCH 4/4] black format --- boututils/View3D.py | 3 --- boututils/analyse_equil_2.py | 2 -- boututils/anim.py | 1 - boututils/boutgrid.py | 1 - boututils/closest_line.py | 1 - boututils/crosslines.py | 1 - boututils/datafile.py | 3 --- boututils/efit_analyzer.py | 4 ---- boututils/fft_integrate.py | 1 - boututils/int_func.py | 1 - boututils/mode_structure.py | 3 --- boututils/options.py | 1 - boututils/plotpolslice.py | 1 - boututils/radial_grid.py | 1 - boututils/read_geqdsk.py | 1 - boututils/showdata.py | 1 - 16 files changed, 26 deletions(-) diff --git a/boututils/View3D.py b/boututils/View3D.py index 4028da6..f9aa417 100644 --- a/boututils/View3D.py +++ b/boututils/View3D.py @@ -213,7 +213,6 @@ def View3D(g, path=None, gb=None): # q=i surfaces for i in range(np.shape(x)[0]): - s = mlab.pipeline.streamline(field) s.streamline_type = "line" # s.seed.widget = s.seed.widget_list[0] @@ -328,7 +327,6 @@ def View3D(g, path=None, gb=None): def magnetic_field(g, X, Y, Z, rmin, rmax, zmin, zmax, Br, Bz, Btrz): - rho = np.sqrt(X**2 + Y**2) phi = np.arctan2(Y, X) @@ -371,7 +369,6 @@ def magnetic_field(g, X, Y, Z, rmin, rmax, zmin, zmax, Br, Bz, Btrz): def psi_field(g, X, Y, Z, rmin, rmax, zmin, zmax): - rho = np.sqrt(X**2 + Y**2) psi = np.zeros(np.shape(X)) diff --git a/boututils/analyse_equil_2.py b/boututils/analyse_equil_2.py index 4014679..5e43d03 100644 --- a/boututils/analyse_equil_2.py +++ b/boututils/analyse_equil_2.py @@ -209,7 +209,6 @@ def analyse_equil(F, R, Z): print("") if n_xpoint > 0: - # Find the primary separatrix # First remove non-monotonic separatrices @@ -265,7 +264,6 @@ def analyse_equil(F, R, Z): inner_sep = 0 else: - # No x-points. Pick mid-point in f xpt_f = 0.5 * (numpy.max(F) + numpy.min(F)) diff --git a/boututils/anim.py b/boututils/anim.py index 88244f0..679c2d4 100644 --- a/boututils/anim.py +++ b/boututils/anim.py @@ -65,7 +65,6 @@ def anim(s, d, *args, **kwargs): if __name__ == "__main__": - path = "../../../examples/elm-pb/data" data = collect("P", path=path) diff --git a/boututils/boutgrid.py b/boututils/boutgrid.py index 1dcb6ca..6e62ad9 100644 --- a/boututils/boutgrid.py +++ b/boututils/boutgrid.py @@ -28,7 +28,6 @@ def aligned_points(grid, nz=1, period=1.0, maxshift=0.4): start = 0 for y in range(ny): - end = start + nx * nz phi = zshift[:, y] + phi0[:, None] diff --git a/boututils/closest_line.py b/boututils/closest_line.py index 5d6f136..7f627d5 100644 --- a/boututils/closest_line.py +++ b/boututils/closest_line.py @@ -5,7 +5,6 @@ # Find the closest contour line to a given point def closest_line(n, x, y, ri, zi, mind=None): - mind = numpy.min((x[0] - ri) ** 2 + (y[0] - zi) ** 2) ind = 0 diff --git a/boututils/crosslines.py b/boututils/crosslines.py index aed6186..ae32251 100644 --- a/boututils/crosslines.py +++ b/boututils/crosslines.py @@ -133,7 +133,6 @@ def meshgrid_as_strided(x, y, mask=None): nans_[:, :] = np.isnan(ua) if not np.ma.any(nans): - # remove duplicate cases where intersection happens on an endpoint # ignore[np.ma.where((ua[:, :-1] == 1) & (ua[:, 1:] == 0))] = True # ignore[np.ma.where((ub[:-1, :] == 1) & (ub[1:, :] == 0))] = True diff --git a/boututils/datafile.py b/boututils/datafile.py index 0072c88..2e3d783 100644 --- a/boututils/datafile.py +++ b/boututils/datafile.py @@ -535,7 +535,6 @@ def _bout_dimensions_from_var(self, data): return BoutArray.dims_from_type(bout_type) def write(self, name, data, info=False): - if not self.writeable: raise Exception("File not writeable. Open with write=True keyword") @@ -914,7 +913,6 @@ def size(self, varname): return var.shape def write(self, name, data, info=False): - if not self.writeable: raise Exception("File not writeable. Open with write=True keyword") @@ -977,7 +975,6 @@ def list_file_attributes(self): return self.handle.attrs.keys() def attributes(self, varname): - try: return self._attributes_cache[varname] except KeyError: diff --git a/boututils/efit_analyzer.py b/boututils/efit_analyzer.py index 19a4b58..6433653 100644 --- a/boututils/efit_analyzer.py +++ b/boututils/efit_analyzer.py @@ -31,7 +31,6 @@ def View2D(g, option=0): - # plot and check the field fig = figure(num=2, figsize=(16, 6)) # fig.suptitle('Efit Analysis', fontsize=20) @@ -350,7 +349,6 @@ def View2D(g, option=0): def surface(cs, i, f, opt_ri, opt_zi, style, iplot=0): - # contour_lines( F, np.arange(nx).astype(float), np.arange(ny).astype(float), # levels=[start_f]) # cs=contour( g.r, g.z, g.psi, levels=[f]) @@ -400,7 +398,6 @@ def surface(cs, i, f, opt_ri, opt_zi, style, iplot=0): # y=yy # if iplot == 0: - # plot the start_f line zc = cs.collections[i] setp(zc, linewidth=4, linestyle=style[i]) @@ -417,7 +414,6 @@ def surface(cs, i, f, opt_ri, opt_zi, style, iplot=0): if __name__ == "__main__": - path = "../../tokamak_grids/pyGridGen/" g = read_geqdsk(path + "g118898.03400") diff --git a/boututils/fft_integrate.py b/boututils/fft_integrate.py index 2b53f29..d693891 100644 --- a/boututils/fft_integrate.py +++ b/boututils/fft_integrate.py @@ -39,7 +39,6 @@ def fft_integrate(y, loop=None): def test_integrate(): - n = 10 dx = 2.0 * np.pi / np.float(n) x = dx * np.arange(n) diff --git a/boututils/int_func.py b/boututils/int_func.py index 8eb75c9..6c0e436 100644 --- a/boututils/int_func.py +++ b/boututils/int_func.py @@ -37,7 +37,6 @@ def int_func(xin, fin=None, simple=None): g[i] = g[i - 1] + 0.5 * (x[i] - x[i - 1]) * (f[i] + f[i - 1]) else: - n2 = numpy.int(old_div(n, 2)) g[0] = 0.0 diff --git a/boututils/mode_structure.py b/boututils/mode_structure.py index 19dd69e..e2d50dc 100644 --- a/boututils/mode_structure.py +++ b/boututils/mode_structure.py @@ -19,7 +19,6 @@ # interpolates a 1D periodic function def zinterp(v, zind): - v = numpy.ravel(v) nz = numpy.size(v) @@ -70,7 +69,6 @@ def mode_structure( pmodes=None, _extra=None, ): - # ON_ERROR, 2 # # period = 1 ; default = full torus @@ -362,7 +360,6 @@ def mode_structure( # # if subset is not None: - # get number of modes larger than 5% of the maximum count = numpy.size(numpy.where(fmax > 0.10 * numpy.max(fmax))) diff --git a/boututils/options.py b/boututils/options.py index b3bbc8c..2487315 100644 --- a/boututils/options.py +++ b/boututils/options.py @@ -57,7 +57,6 @@ class BOUTOptions(object): """ def __init__(self, inp_path=None): - self._sections = ["root"] for section in self._sections: diff --git a/boututils/plotpolslice.py b/boututils/plotpolslice.py index 4e96a69..cfd9750 100644 --- a/boututils/plotpolslice.py +++ b/boututils/plotpolslice.py @@ -126,7 +126,6 @@ def plotpolslice(var3d, gridfile, period=1, zangle=0.0, rz=1, fig=0): z[x, ypos] = zxy[x, ny - 1] if fig == 1: - f = mlab.figure(size=(600, 600)) # Tell visual to use this as the viewer. visual.set_viewer(f) diff --git a/boututils/radial_grid.py b/boututils/radial_grid.py index db96f54..6dbeb3d 100644 --- a/boututils/radial_grid.py +++ b/boututils/radial_grid.py @@ -16,7 +16,6 @@ def radial_grid( n, pin, pout, include_in, include_out, seps, sep_factor, in_dp=None, out_dp=None ): - if n == 1: return [0.5 * (pin + pout)] diff --git a/boututils/read_geqdsk.py b/boututils/read_geqdsk.py index 2172cb6..95f7c7a 100644 --- a/boututils/read_geqdsk.py +++ b/boututils/read_geqdsk.py @@ -7,7 +7,6 @@ def read_geqdsk(file): - data = Geqdsk() data.openFile(file) diff --git a/boututils/showdata.py b/boututils/showdata.py index 6163bc1..350cb65 100644 --- a/boututils/showdata.py +++ b/boututils/showdata.py @@ -486,7 +486,6 @@ def showdata( clevels = [] for i in range(0, Nvar): - dummymax.append([]) dummymin.append([]) for j in range(0, Nlines[i]):