Skip to content

Commit 7f1d126

Browse files
committed
Remove NetcdfFileBuffer.parse_name
variable is a (str, str) tuple of field name to variable name in the NetCDF file. variable[1] is never a list
1 parent 9bf9fe5 commit 7f1d126

File tree

2 files changed

+3
-13
lines changed

2 files changed

+3
-13
lines changed

parcels/field.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -568,7 +568,7 @@ def from_netcdf(
568568
interp_method=interp_method,
569569
gridindexingtype=gridindexingtype,
570570
) as filebuffer:
571-
filebuffer.name = filebuffer.parse_name(variable[1])
571+
filebuffer.name = variable[1]
572572
if dimensions["depth"] == "not_yet_set":
573573
depth = filebuffer.depth_dimensions
574574
kwargs["depth_field"] = "not_yet_set"
@@ -628,7 +628,7 @@ def from_netcdf(
628628
) as filebuffer:
629629
# If Field.from_netcdf is called directly, it may not have a 'data' dimension
630630
# In that case, assume that 'name' is the data dimension
631-
filebuffer.name = filebuffer.parse_name(variable[1])
631+
filebuffer.name = variable[1]
632632
buffer_data = filebuffer.data
633633
if len(buffer_data.shape) == 4:
634634
errormessage = (
@@ -1112,7 +1112,7 @@ def computeTimeChunk(self, data, tindex):
11121112
time_data = g.time_origin.reltime(time_data)
11131113
filebuffer.ti = (time_data <= g.time[tindex]).argmin() - 1
11141114
if self.netcdf_engine != "xarray":
1115-
filebuffer.name = filebuffer.parse_name(self.filebuffername)
1115+
filebuffer.name = self.filebuffername
11161116
buffer_data = filebuffer.data
11171117
if len(buffer_data.shape) == 2:
11181118
buffer_data = np.reshape(buffer_data, sum(((1, 1), buffer_data.shape), ()))

parcels/fieldfilebuffer.py

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -51,16 +51,6 @@ def close(self):
5151
self.dataset.close()
5252
self.dataset = None
5353

54-
def parse_name(self, name):
55-
if isinstance(name, list):
56-
for nm in name:
57-
if hasattr(self.dataset, nm):
58-
name = nm
59-
break
60-
if isinstance(name, list):
61-
raise OSError("None of variables in list found in file")
62-
return name
63-
6454
@property
6555
def latlon(self):
6656
lon = self.dataset[self.dimensions["lon"]]

0 commit comments

Comments
 (0)