From 449e2a41e8d1b90f4e86585cf4813cd3719481c8 Mon Sep 17 00:00:00 2001 From: John Omotani Date: Wed, 6 Apr 2022 16:37:24 +0100 Subject: [PATCH 1/3] Method to list file attributes of a DataFile --- boututils/datafile.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/boututils/datafile.py b/boututils/datafile.py index 659e72a..8e9befe 100644 --- a/boututils/datafile.py +++ b/boututils/datafile.py @@ -314,6 +314,9 @@ def read_file_attribute(self, name): def write_file_attribute(self, name, value): return self.impl.write_file_attribute(name, value) + def list_file_attributes(self): + return self.impl.list_file_attributes() + def get(self, name, default=None): if default is None or name in self.keys(): return self[name] @@ -689,6 +692,9 @@ def read_file_attribute(self, name): def write_file_attribute(self, name, value): setattr(self.handle, name, value) + def list_file_attributes(self): + return self.handle.ncattrs() + def attributes(self, varname): try: return self._attributes_cache[varname] @@ -999,6 +1005,9 @@ def read_file_attribute(self, name): def write_file_attribute(self, name, value): self.handle.attrs[name] = value + def list_file_attributes(self): + return self.handle.attrs.keys() + def attributes(self, varname): try: From 989951acda4930737c1af80f76bc000cfc898752 Mon Sep 17 00:00:00 2001 From: John Omotani Date: Wed, 6 Apr 2022 16:38:00 +0100 Subject: [PATCH 2/3] Formatting changes from updated black --- boututils/View3D.py | 6 +++--- boututils/linear_regression.py | 2 +- boututils/spectrogram.py | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/boututils/View3D.py b/boututils/View3D.py index 82fe867..4028da6 100644 --- a/boututils/View3D.py +++ b/boututils/View3D.py @@ -113,7 +113,7 @@ def View3D(g, path=None, gb=None): BBx = B1p + B1t BBy = B2p + B2t BBz = B3p + B3t - btotal = np.sqrt(BBx ** 2 + BBy ** 2 + BBz ** 2) + btotal = np.sqrt(BBx**2 + BBy**2 + BBz**2) Psi = psi_field(g, X, Y, Z, rmin, rmax, zmin, zmax) @@ -329,7 +329,7 @@ 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) + rho = np.sqrt(X**2 + Y**2) phi = np.arctan2(Y, X) br = np.zeros(np.shape(X)) @@ -372,7 +372,7 @@ 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) + rho = np.sqrt(X**2 + Y**2) psi = np.zeros(np.shape(X)) diff --git a/boututils/linear_regression.py b/boututils/linear_regression.py index 8b2a98b..543dfa6 100644 --- a/boututils/linear_regression.py +++ b/boututils/linear_regression.py @@ -20,7 +20,7 @@ def linear_regression(x, y): mx = mean(x) my = mean(y) - b = (mean(x * y) - mx * my) / (mean(x ** 2) - mx ** 2) + b = (mean(x * y) - mx * my) / (mean(x**2) - mx**2) a = my - b * mx return a, b diff --git a/boututils/spectrogram.py b/boututils/spectrogram.py index 4ab6972..aeb76a3 100644 --- a/boututils/spectrogram.py +++ b/boututils/spectrogram.py @@ -71,7 +71,7 @@ def spectrogram(data, dx, sigma, clip=1.0, optimise_clipping=True, nskip=1.0): while 1: nn = nn / 2.0 if nn <= 2.0: - n_clipped = 2 ** two_count + n_clipped = 2**two_count print("clipping window length from ", n, " to ", n_clipped, " points") break else: From f13d9a3d2734e484ab6c1412a5b88008a37896e2 Mon Sep 17 00:00:00 2001 From: John Omotani Date: Wed, 6 Apr 2022 17:30:01 +0100 Subject: [PATCH 3/3] Update tool versions for pre-commit checks --- .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 c816694..0b37abe 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: 20.8b1 + rev: 22.3.0 hooks: - id: black - repo: https://gitlab.com/pycqa/flake8 - rev: 3.8.4 + rev: 3.9.2 hooks: - id: flake8 - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v3.4.0 + rev: v4.1.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.7.0 + rev: 5.10.1 hooks: - id: isort