Skip to content

Commit

Permalink
Merge pull request #40 from boutproject/list-file-attributes
Browse files Browse the repository at this point in the history
DataFile method to list file attributes
  • Loading branch information
johnomotani authored Apr 7, 2022
2 parents c94705f + f13d9a3 commit 70c0645
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 9 deletions.
8 changes: 4 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
6 changes: 3 additions & 3 deletions boututils/View3D.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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))

Expand Down
9 changes: 9 additions & 0 deletions boututils/datafile.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion boututils/linear_regression.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion boututils/spectrogram.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 70c0645

Please sign in to comment.