[gradsusr] [Opengrads-devel] pygrads: galab sampleXY problems

Arlindo da Silva dasilva at alum.mit.edu
Sat Apr 28 17:03:52 EDT 2012


Lorenzo,

   Thank you for sending me this patch. Could you try version 1.1.6 from
here

      http://opengrads.org/devel/pygrads/

  I believe I have already fixed this bug, but have not released a new
version on sourceforge yet.

      Arlindo


On Wed, Apr 25, 2012 at 1:07 PM, Lorenzo Mentaschi <
lorenzo.mentaschi at unige.it> wrote:

> 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)
> #   ..................................................................
>
> #########################################
> #########################################
> #########################################
>
>
> ------------------------------------------------------------------------------
> Live Security Virtual Conference
> Exclusive live event will cover all the ways today's security and
> threat landscape has changed and how IT managers can respond. Discussions
> will include endpoint security, mobile security and the latest in malware
> threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
> _______________________________________________
> Opengrads-devel mailing list
> Opengrads-devel at lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/opengrads-devel
>



-- 
Arlindo da Silva
*dasilva at alum.mit.edu*
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://gradsusr.org/pipermail/gradsusr/attachments/20120428/b403018f/attachment-0003.html 


More information about the gradsusr mailing list