Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for 4-d variable output in standard memory mode #25

Closed
wants to merge 4 commits into from
Closed
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
35 changes: 25 additions & 10 deletions tonic/models/vic/vic2netcdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -456,16 +456,31 @@ def nc_add_data_to_array(self, point):
def nc_add_data_standard(self, points):
ys = points.get_ys()
xs = points.get_xs()
for p in points:
for name in self.three_dim_vars:
data = points.get_data(name, self.slice)
self.f.variables[name][:, ys, xs] = data
for name in self.four_dim_vars:
varshape = self.f.variables[name].shape[1]
for i in pyrange(varshape):
sn = name + str(i)
self.f.variables[name][:, i, ys,
xs] = p.df[sn].values[self.slice]
for name in self.three_dim_vars:
yc = 0
dd = np.zeros(self.f.variables[name][:,ys,xs].shape)
for p in points:
dd[:,yc] = p.df[name].values[self.slice]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems like we're just writing the same data to all of these points.

yc = yc + 1
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Python allow you to enumerate your for loop. You can get rid of all the yc logic with this for loop syntax: for yc, p in enumerate(points):.


self.f.variables[name][:,ys,xs] = dd
del dd
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The python garbage collector will handle this for you. It is almost never necessary to use the del statement in python.


for name in self.four_dim_vars:
varshape = self.f.variables[name].shape[1]

for i in range(varshape):
yc = 0
dd = np.zeros(self.f.variables[name][:,i,ys,xs].shape)

for p in points:
sn = name + str(i)
dd[:,yc] = p.df[sn].values[self.slice]
yc = yc + 1

self.f.variables[name][:, i, ys,
xs] = dd
del dd

def nc_write_data_from_array(self):
""" write completed data arrays to disk """
Expand Down