Skip to content

Commit

Permalink
netcdf bug
Browse files Browse the repository at this point in the history
  • Loading branch information
jaapschellekens committed Apr 6, 2016
1 parent f3194e5 commit 0d88e1f
Showing 1 changed file with 25 additions and 4 deletions.
29 changes: 25 additions & 4 deletions wflow-py/wflow/wf_netcdfio.py
Original file line number Diff line number Diff line change
Expand Up @@ -441,18 +441,35 @@ def __init__(self, netcdffile, logging, vars=[]):
a = pcr2numpy(cover(0.0), 0.0).flatten()
# Determine steps to load in mem based on estimated memory usage
floatspermb = 1048576 / 4
maxmb = 4000
self.maxsteps = maxmb * len(a) / floatspermb + 1
maxmb = 40

maxlentime = len(self.dataset.variables['time'])
self.maxsteps = minimum(maxmb * len(a) / floatspermb + 1,maxlentime - 1)
self.fstep = 0
self.lstep = self.fstep + self.maxsteps


# Now check Y values to see if we must flip the data
try:
self.y = self.dataset.variables['lat'][:]
except:
self.y = self.dataset.variables['y'][:]

if self.y[0] > self.y[-1]:
self.flip = False
else:
self.flip = True


for var in vars:
try:
self.alldat[var] = self.dataset.variables[var][self.fstep:self.maxsteps]
except:
self.alldat.pop(var, None)
logging.warn("Variable " + var + " not found in netcdf file: " + netcdffile)



def gettimestep(self, timestep, logging, var='P', shifttime=False):
"""
Gets a map for a single timestep. reads data in blocks assuming sequential access
Expand All @@ -476,8 +493,12 @@ def gettimestep(self, timestep, logging, var='P', shifttime=False):
self.fstep = ncindex
self.lstep = ncindex + self.maxsteps
np_step = self.alldat[var][ncindex - self.fstep, :, :]

miss = float(self.dataset.variables[var]._FillValue)
return numpy2pcr(Scalar, np_step, miss), True
if self.flip:
return numpy2pcr(Scalar, flipud(np_step).copy(), miss), True
else:
return numpy2pcr(Scalar, np_step, miss), True
else:
#logging.debug("Var (" + var + ") not found returning 0")
return cover(scalar(0.0)), False
Expand Down Expand Up @@ -505,7 +526,7 @@ def __init__(self, netcdffile, logging, vars=[]):
a = pcr2numpy(cover(0.0), 0.0).flatten()
# Determine steps to load in mem based on estimated memory usage
floatspermb = 1048576 / 4
maxmb = 4000
maxmb = 40
self.maxsteps = maxmb * len(a) / floatspermb + 1
self.fstep = 0
self.lstep = self.fstep + self.maxsteps
Expand Down

0 comments on commit 0d88e1f

Please sign in to comment.