Skip to content

Commit 060665c

Browse files
author
Elizabeth Fischer
committed
Python extension: Allow creation of an Indexing object diretly, rather than reading from a file. Makes it more flexible.
1 parent 56ba008 commit 060665c

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

pylib/icebin/ibgrid.py

+11-6
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,10 @@
2727

2828
# -------------------------------------------------------
2929
class Indexing(object):
30-
def __init__(self, nc, vname):
31-
ncvar = nc.variables[vname]
32-
self.base = ncvar.base
33-
self.extent = ncvar.extent
34-
self.indices = ncvar.indices
30+
def __init__(self, base, extent, indices):
31+
self.base = np.array(base)
32+
self.extent = np.array(extent)
33+
self.indices = np.array(indices)
3534

3635
# Turn it all into Numpy arrays
3736
if not isinstance(self.base, np.ndarray):
@@ -86,7 +85,13 @@ def index_to_tuple(self, ix):
8685

8786
tpl[self.indices[self.rank-1]] = ix
8887
return tuple(tpl)
89-
88+
# -------------------------------------------------------
89+
def read_nc_indexing(nc, vname):
90+
ncvar = nc.variables[vname]
91+
base = ncvar.base
92+
extent = ncvar.extent
93+
indices = ncvar.indices
94+
return Indexing(base,extent,indices)
9095

9196
# -------------------------------------------------------
9297
class Vertex(object):

0 commit comments

Comments
 (0)