Hi all,
I'm not sure this is the right place to post about pygrads.
I found two problems using galab method sampleXY.
The first problem is that invoking it, I get the error
"NameError: global name 'lon' is not defined"
The second problem is that parameter dh is completely ignored.
I fixed the method in order to make it function for me, and I'm sending
you the patched version.
I hope it can be useful.
Lorenzo
#########################################
#########################################
#########################################
def sampleXY ( self, expr, lons, lats, levs=None, dh=None, **kwopts):
if len(lons.shape)!=1 or len(lats.shape)!=1:
raise GrADSError, "lons, lats, time must be 1D arrays"
# Retrieve dimension environment
# ------------------------------
######### I ADDED THE IF ###############
if not dh:
dh = self.query("dims", Quiet=True)
###########################################
# Loop over time, performing interpolation
# ----------------------------------------
g = GaGrid("sampleXY")
g.time = []
V = ma.masked_array(zeros((len(lons),dh.nt,dh.nz)),dtype=float32)
for t in dh.ti:
n = t - dh.ti[0]
self.cmd('set t %d'%t, Quiet=True)
######### I ADDED dh=dh #############
v, g.lev = self._interpXY ( expr, lons, lats,
levs=levs, dh=dh,
**kwopts)
###########################################
if len(v.shape)==1:
V[:,n,0] = v
else:
V[:,n,:] = v
qh =self.query("time",Quiet=True)
g.time.append(qh.t1)
g.dims = ['obs',]
if dh.nt>1:
g.dims.append('time')
if dh.nz>1:
g.dims.append('lev')
######### I GUESS THIS IS THE RIGHT ASSIGNMENT #############
g.lon, g.lat = (lons, lats) # "obs" coordinates
###################################################
g.tyme = array([gat2dt(t) for t in g.time])
# Restore dimension environment
# -----------------------------
self.setdim(dh)
V = V.squeeze()
return GaField(V.data, name=expr, grid=g,
mask=V.mask, dtype=float32)
# ..................................................................
#########################################
#########################################
#########################################
|