Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions src/boutdata/collect.py
Original file line number Diff line number Diff line change
Expand Up @@ -953,15 +953,16 @@ def _check_fieldperp_attributes(
# and check they are unique
if yindex_global is not None and yindex_global != temp_yindex:
raise ValueError(
"Found FieldPerp {} at different global y-indices, {} " "and {}".format(
"Found FieldPerp {} at different global y-indices, {} and {}".format(
varname, temp_yindex, yindex_global
)
)
yindex_global = temp_yindex
if fieldperp_yproc is not None and fieldperp_yproc != pe_yind:
raise ValueError(
"Found FieldPerp {} on different y-processor indices, "
"{} and {}".format(varname, fieldperp_yproc, pe_yind)
"Found FieldPerp {} on different y-processor indices, {} and {}".format(
varname, fieldperp_yproc, pe_yind
)
)
fieldperp_yproc = pe_yind
var_attributes = temp_f_attributes
Expand Down
2 changes: 1 addition & 1 deletion src/boututils/ask.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,4 @@ def query_yes_no(question, default="yes"):
elif choice in valid:
return valid[choice]
else:
sys.stdout.write("Please respond with 'yes' or 'no' " "(or 'y' or 'n').\n")
sys.stdout.write("Please respond with 'yes' or 'no' (or 'y' or 'n').\n")
25 changes: 18 additions & 7 deletions src/boututils/datafile.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ def bout_type(self, varname):
"""
return self.attributes(varname)["bout_type"]

def write(self, name, data, info=False):
def write(self, name, data, info=False, *, dims=None):
"""Write a variable to file

If the variable is not a :py:obj:`~boututils.boutarray.BoutArray` with
Expand All @@ -297,13 +297,15 @@ def write(self, name, data, info=False):
info : bool, optional
If True, print information about what is being written to
file
dims : tuple(str) or None, optional
If passed, specifies the dimensions to be used to write the variable.

Returns
-------
None

"""
return self.impl.write(name, data, info)
return self.impl.write(name, data, info, dims=dims)

def read_file_attribute(self, name):
return self.impl.read_file_attribute(name)
Expand Down Expand Up @@ -525,12 +527,18 @@ def _bout_dimensions_from_var(self, data):

return BoutArray.dims_from_type(bout_type)

def write(self, name, data, info=False):
def write(self, name, data, info=False, *, dims=None):
if not self.writeable:
raise Exception("File not writeable. Open with write=True keyword")

s = np.shape(data)

if dims is not None and len(dims) != data.ndim:
raise ValueError(
f"When dims is passed, it must have an entry for each dimension of "
f"`data`, but dims={dims} and data.ndim={data.ndim}."
)

# Get the variable type
t = type(data).__name__

Expand Down Expand Up @@ -568,7 +576,10 @@ def write(self, name, data, info=False):
# Not found, so add.

# Get dimensions
defdims = self._bout_dimensions_from_var(data)
if dims is None:
defdims = self._bout_dimensions_from_var(data)
else:
defdims = dims

def find_dim(dim):
# Find a dimension with given name and size
Expand Down Expand Up @@ -626,10 +637,10 @@ def find_dim(dim):
# List of (size, 'name') tuples
dlist = list(zip(s, defdims))
# Get new list of variables, and turn into a tuple
dims = tuple(map(find_dim, dlist))
dims_tuple = tuple(map(find_dim, dlist))

# Create the variable
var = self.handle.createVariable(name, t, dims, **self._kwargs)
var = self.handle.createVariable(name, t, dims_tuple, **self._kwargs)

if var is None:
raise Exception("Couldn't create variable")
Expand Down Expand Up @@ -899,7 +910,7 @@ def size(self, varname):
return None
return var.shape

def write(self, name, data, info=False):
def write(self, name, data, info=False, *, dims=None):
if not self.writeable:
raise Exception("File not writeable. Open with write=True keyword")

Expand Down
Loading