def __call__(self, lon, lat, inverse=False): """ Calling a Proj class instance with the arguments lon, lat will convert lon/lat (in degrees) to x/y native map projection coordinates (in meters). If optional keyword 'inverse' is True (default is False), the inverse transformation from x/y to lon/lat is performed. For cylindrical equidistant projection ('cyl'), this does nothing (i.e. x,y == lon,lat). lon,lat can be either scalar floats or N arrays. """ if self.projection == 'cyl': # for cyl x,y == lon,lat return lon, lat # if inputs are numarray arrays, get shape and typecode. try: shapein = lon.shape lontypein = lon.typecode() lattypein = lat.typecode() except: shapein = False # make sure inputs have same shape. if shapein and lat.shape != shapein: raise ValueError, 'lon, lat must be scalars or numarrays with the same shape' if shapein: x = N.ravel(lon).tolist() y = N.ravel(lat).tolist() if inverse: outx, outy = self._inv(x, y) else: outx, outy = self._fwd(x, y) outx = N.reshape(N.array(outx, lontypein), shapein) outy = N.reshape(N.array(outy, lattypein), shapein) else: if inverse: outx, outy = self._inv(lon, lat) else: outx, outy = self._fwd(lon, lat) return outx, outy
def __call__(self,lon,lat,inverse=False): """ Calling a Proj class instance with the arguments lon, lat will convert lon/lat (in degrees) to x/y native map projection coordinates (in meters). If optional keyword 'inverse' is True (default is False), the inverse transformation from x/y to lon/lat is performed. For cylindrical equidistant projection ('cyl'), this does nothing (i.e. x,y == lon,lat). lon,lat can be either scalar floats or N arrays. """ if self.projection == 'cyl': # for cyl x,y == lon,lat return lon,lat # if inputs are numarray arrays, get shape and typecode. try: shapein = lon.shape lontypein = lon.typecode() lattypein = lat.typecode() except: shapein = False # make sure inputs have same shape. if shapein and lat.shape != shapein: raise ValueError, 'lon, lat must be scalars or numarrays with the same shape' if shapein: x = N.ravel(lon).tolist() y = N.ravel(lat).tolist() if inverse: outx, outy = self._inv(x,y) else: outx, outy = self._fwd(x,y) outx = N.reshape(N.array(outx,lontypein),shapein) outy = N.reshape(N.array(outy,lattypein),shapein) else: if inverse: outx,outy = self._inv(lon,lat) else: outx,outy = self._fwd(lon,lat) return outx,outy
def _h_arrows(self, length): ''' length is in arrow width units ''' minsh = self.minshaft * self.headlength N = len(length) length = nx.reshape(length, (N,1)) x = nx.array([0, -self.headaxislength, -self.headlength, 0], nx.Float64) x = x + nx.array([0,1,1,1]) * length y = 0.5 * nx.array([1, 1, self.headwidth, 0], nx.Float64) y = nx.repeat(y[nx.newaxis,:], N) x0 = nx.array([0, minsh-self.headaxislength, minsh-self.headlength, minsh], nx.Float64) y0 = 0.5 * nx.array([1, 1, self.headwidth, 0], nx.Float64) ii = [0,1,2,3,2,1,0] X = nx.take(x, ii, 1) Y = nx.take(y, ii, 1) Y[:, 3:] *= -1 X0 = nx.take(x0, ii) Y0 = nx.take(y0, ii) Y0[3:] *= -1 shrink = length/minsh X0 = shrink * X0[nx.newaxis,:] Y0 = shrink * Y0[nx.newaxis,:] short = nx.repeat(length < minsh, 7, 1) #print 'short', length < minsh X = nx.where(short, X0, X) Y = nx.where(short, Y0, Y) if self.pivot[:3] == 'mid': X -= 0.5 * X[:,3, nx.newaxis] elif self.pivot[:3] == 'tip': X = X - X[:,3, nx.newaxis] #numpy bug? using -= does not # work here unless we multiply # by a float first, as with 'mid'. tooshort = length < self.minlength if nx.any(tooshort): th = nx.arange(0,7,1, nx.Float64) * (nx.pi/3.0) x1 = nx.cos(th) * self.minlength * 0.5 y1 = nx.sin(th) * self.minlength * 0.5 X1 = nx.repeat(x1[nx.newaxis, :], N, 0) Y1 = nx.repeat(y1[nx.newaxis, :], N, 0) tooshort = nx.repeat(tooshort, 7, 1) X = nx.where(tooshort, X1, X) Y = nx.where(tooshort, Y1, Y) return X, Y
dim = 3 number = 5 args = sys.argv[1:] if len(args) > 3: sys.exit("invalid number of arguments") elif len(args) > 0: myshape = [int(x) for x in args] else: myshape = [3, 4, 8] # generate a data matrix of the given shape size = reduce(lambda x, y: x * y, myshape) #data = [ random.randrange(size - i) + 10 for i in xrange(size) ] data = [float(i) / 100.0 for i in xrange(size)] data = reshape(data, myshape) # setup some test bar charts if True: chart1 = BarChart() chart1.data = data chart1.xlabel = 'Benchmark' chart1.ylabel = 'Bandwidth (GBps)' chart1.legend = ['x%d' % x for x in xrange(myshape[-1])] chart1.xticks = ['xtick%d' % x for x in xrange(myshape[0])] chart1.title = 'this is the title' if len(myshape) > 2: chart1.xsubticks = ['%d' % x for x in xrange(myshape[1])] chart1.graph() chart1.savefig('/tmp/test1.png')
dim = 3 number = 5 args = sys.argv[1:] if len(args) > 3: sys.exit("invalid number of arguments") elif len(args) > 0: myshape = [int(x) for x in args] else: myshape = [3, 4, 8] # generate a data matrix of the given shape size = reduce(lambda x, y: x * y, myshape) # data = [ random.randrange(size - i) + 10 for i in xrange(size) ] data = [float(i) / 100.0 for i in xrange(size)] data = reshape(data, myshape) # setup some test bar charts if True: chart1 = BarChart() chart1.data = data chart1.xlabel = "Benchmark" chart1.ylabel = "Bandwidth (GBps)" chart1.legend = ["x%d" % x for x in xrange(myshape[-1])] chart1.xticks = ["xtick%d" % x for x in xrange(myshape[0])] chart1.title = "this is the title" if len(myshape) > 2: chart1.xsubticks = ["%d" % x for x in xrange(myshape[1])] chart1.graph() chart1.savefig("/tmp/test1.png")