Exemple #1
0
def lineplot(data, panel=None, color=None, width=400, height=400, title="Line Plot"):
  """
  Quick plot of a line plot from <data>.  <panel> is the name of a
  panel to put this into (default= make a new one), <color> is the
  color to use, <width> and <height> are the dimensions, <title> is
  the phrase for the title bar.  Returns a reference to the display.
  """

  if isinstance(data,PyTuple) or isinstance(data,PyList):
    data = field(data)

  domt = domainType(data)
  rngt = rangeType(data)
  xaxis = ScalarMap(domt[0], Display.XAxis)
  if isinstance(rngt,RealTupleType):
    yaxis = ScalarMap(rngt[0], Display.YAxis)
  else:
    yaxis = ScalarMap(rngt, Display.YAxis)

  axes = (xaxis, yaxis)

  disp = subs.makeDisplay( axes )
  constmap = subs.makeColorMap(color)

  dr=subs.addData("Lineplot", data, disp, constmap)
  subs.setBoxSize(disp, .70)
  showAxesScales(disp, 1)
  setAxesScalesFont(axes, Font("Monospaced", Font.PLAIN, 18))

  subs.setAspectRatio(disp, float(width)/float(height))
  subs.showDisplay(disp,width,height,title,None,None,panel)
  
  return disp
Exemple #2
0
def colorimage(red_data,
               green_data,
               blue_data,
               panel=None,
               colortable=None,
               width=400,
               height=400,
               title="VisAD Color Image"):
    """
  Display a color image, from three images <red_data>, <green_data>
  and <blue_data>.  <panel> is the name of a panel to put this into
  (default= make a new one), <colortable> is a color table to use (def
  = gray scale), <width> and <height> are the dimensions.  <title> is
  the phrase for the title bar.  Returns a reference to the display.

  """

    _comb_image = FieldImpl.combine([red_data, green_data, blue_data])
    dom_1 = RealType.getRealType(domainType(_comb_image, 0))
    dom_2 = RealType.getRealType(domainType(_comb_image, 1))
    rng = rangeType(_comb_image)
    maps = subs.makeMaps(dom_1, 'x', dom_2, 'y', rng[0], 'red', rng[1],
                         'green', rng[2], 'blue')

    disp = subs.makeDisplay(maps)
    subs.addData('comb', _comb_image, disp)
    subs.setBoxSize(disp, .80)
    subs.setAspectRatio(disp, float(width) / float(height))
    subs.showDisplay(disp, width, height, title, None, None, panel)
    return disp
Exemple #3
0
def scatter(data_1, data_2, panel=None, pointsize=None, width=400, height=400, xlabel=None, ylabel=None, title="VisAD Scatter", bottom=None, top=None, color=None):
  """
  Quick plot of a scatter diagram between <data_1> and <data_2>.
  <panel> is the name of a panel to put this into (default= make a new
  one), <pointsize> is the size of the scatter points (def = 1),
  <width> and <height> are the dimensions, <xlabel> and <ylabel> are
  the axes labels to use (def = names of data objects).  <title> is
  the phrase for the title bar.  Returns a reference to the display.
  """

  if isinstance(data_1,PyList) or isinstance(data_1,PyTuple):
    data_1 = field('data_1',data_1)

  if isinstance(data_2,PyList) or isinstance(data_2,PyTuple):
    data_2 = field('data_2',data_2)

  rng_1 = data_1.getType().getRange().toString()
  rng_2 = data_2.getType().getRange().toString()
  data = FieldImpl.combine((data_1,data_2))
  maps = subs.makeMaps(getRealType(rng_1),"x", getRealType(rng_2),"y")
  disp = subs.makeDisplay(maps)
  subs.addData("data", data, disp, constantMaps=subs.makeColorMap(color))
  subs.setBoxSize(disp, .70)
  showAxesScales(disp,1)
  #setAxesScalesFont(maps, Font("Monospaced", Font.PLAIN, 18))
  if pointsize is not None: subs.setPointSize(disp, pointsize)

  subs.setAspectRatio(disp, float(width)/float(height))
  subs.showDisplay(disp,width,height,title,bottom,top,panel)
  setAxesScalesLabel(maps, [xlabel, ylabel])
  return disp
Exemple #4
0
def histogram(data, bins=20, width=400, height=400, title="VisAD Histogram", color=None, bottom=None, top=None, panel=None, clip=1):

  """
  Quick plot of a histogram from <data>.  <bins> is the number of bins
  to use (def = 20), <panel> is the name of a panel to put this into
  (default= make a new one), <color> is the color to use, <width> and
  <height> are the dimensions, <title> is the phrase for the title
  bar.  Returns a reference to the display.
  """
  if isinstance(data,PyList) or isinstance(data,PyTuple):
    data = field(data)

  from java.lang.Math import abs

  x=[]
  y=[]

  h = hist(data, [0], [bins])
  dom = getDomain(h)
  d = dom.getSamples()
  step2 = dom.getStep()/2

  hmin = h[0].getValue()
  hmax = hmin

  for i in range(0,len(h)):
    hval = h[i].getValue()
    if hval < hmin: hmin = hval
    if hval > hmax: hmax = hval

  for i in range(0,len(h)):
    xm = d[0][i]-step2
    xp = d[0][i]+step2
    x.append(xm)
    y.append(hmin)
    x.append(xm)
    hval = h[i].getValue()
    y.append(hval)
    x.append(xp)
    y.append(hval)
    x.append(xp)
    y.append(hmin)
  
  domt = domainType(h)
  rngt = rangeType(h)

  xaxis = ScalarMap(domt[0], Display.XAxis)
  yaxis = ScalarMap(rngt, Display.YAxis)

  yaxis.setRange(hmin, hmax + abs(hmax * .05))

  disp = subs.makeDisplay( (xaxis, yaxis) )
  subs.drawLine(disp, (x,y), mathtype=(domt[0],rngt), color=color)
  showAxesScales(disp,1)
  subs.setBoxSize(disp,.65,clip)
  subs.setAspectRatio(disp, float(width)/float(height))
  subs.showDisplay(disp,width,height,title,bottom,top,panel)

  return disp
Exemple #5
0
def contour(data,
            panel=None,
            enableLabels=1,
            interval=None,
            width=400,
            height=400,
            title="VisAD Contour Plot"):
    """
  Quick plot of a contour (isopleth) from <data>.  <panel> is the name
  of a panel to put this into (default= make a new one),
  <enableLabels> controls whether the contour lines will be labelled,
  <interval[4]> is a list containing the contour interval info
  (interval, minimum, maximum, base), <width> and <height> are the
  dimensions, <title> is the phrase for the title bar.  Returns a
  reference to the display.

  """
    if isinstance(data, PyList) or isinstance(data, PyTuple):
        data = field(data)

    ndom = domainDimension(data)
    if ndom != 2:
        print "domain dimension must be 2!"
        return None

    dom_1 = RealType.getRealType(domainType(data, 0))
    dom_2 = RealType.getRealType(domainType(data, 1))
    rng = RealType.getRealType(rangeType(data, 0))
    rngMap = ScalarMap(rng, Display.IsoContour)
    xMap = ScalarMap(dom_1, Display.XAxis)
    yMap = ScalarMap(dom_2, Display.YAxis)
    maps = (xMap, yMap, rngMap)

    disp = subs.makeDisplay(maps)
    ci = rngMap.getControl()
    ci.enableLabels(enableLabels)
    if interval is not None:
        ci.setContourInterval(interval[0], interval[1], interval[2],
                              interval[3])

    dr = subs.addData("contours", data, disp)
    subs.setBoxSize(disp, .80)
    subs.setAspectRatio(disp, float(width) / float(height))
    subs.showDisplay(disp, width, height, title, None, None, panel)

    return disp
Exemple #6
0
def scatter(data_1,
            data_2,
            panel=None,
            pointsize=None,
            width=400,
            height=400,
            xlabel=None,
            ylabel=None,
            title="VisAD Scatter",
            bottom=None,
            top=None,
            color=None):
    """
  Quick plot of a scatter diagram between <data_1> and <data_2>.
  <panel> is the name of a panel to put this into (default= make a new
  one), <pointsize> is the size of the scatter points (def = 1),
  <width> and <height> are the dimensions, <xlabel> and <ylabel> are
  the axes labels to use (def = names of data objects).  <title> is
  the phrase for the title bar.  Returns a reference to the display.
  """

    if isinstance(data_1, PyList) or isinstance(data_1, PyTuple):
        data_1 = field('data_1', data_1)

    if isinstance(data_2, PyList) or isinstance(data_2, PyTuple):
        data_2 = field('data_2', data_2)

    rng_1 = data_1.getType().getRange().toString()
    rng_2 = data_2.getType().getRange().toString()
    data = FieldImpl.combine((data_1, data_2))
    maps = subs.makeMaps(getRealType(rng_1), "x", getRealType(rng_2), "y")
    disp = subs.makeDisplay(maps)
    subs.addData("data", data, disp, constantMaps=subs.makeColorMap(color))
    subs.setBoxSize(disp, .70)
    showAxesScales(disp, 1)
    #setAxesScalesFont(maps, Font("Monospaced", Font.PLAIN, 18))
    if pointsize is not None: subs.setPointSize(disp, pointsize)

    subs.setAspectRatio(disp, float(width) / float(height))
    subs.showDisplay(disp, width, height, title, bottom, top, panel)
    setAxesScalesLabel(maps, [xlabel, ylabel])
    return disp
Exemple #7
0
def image(data,
          panel=None,
          colortable=None,
          width=400,
          height=400,
          title="VisAD Image"):
    """
  Display an image with a gray scale color mapping.  <data> contains
  the image, <panel> is the name of a panel to put this into (default=
  make a new one), <colortable> is a color table to use (def = gray
  scale), <width> and <height> are the dimensions.  <title> is the
  phrase for the title bar.  Returns a reference to the display.
  """
    if isinstance(data, PyList) or isinstance(data, PyTuple):
        data = field(data)

    dom_1 = RealType.getRealType(domainType(data, 0))
    dom_2 = RealType.getRealType(domainType(data, 1))
    rng = RealType.getRealType(rangeType(data, 0))
    rngMap = ScalarMap(rng, Display.RGB)
    xMap = ScalarMap(dom_1, Display.XAxis)
    yMap = ScalarMap(dom_2, Display.YAxis)
    maps = (xMap, yMap, rngMap)

    #disp = subs.makeDisplay2D(maps)
    disp = subs.makeDisplay(maps)

    if colortable is None:
        # make a gray-scale table
        gray = []
        for i in range(0, 255):
            gray.append(float(i) / 255.)
        colortable = (gray, gray, gray)

    rngMap.getControl().setTable(colortable)

    dr = subs.addData("brightness", data, disp)
    subs.setBoxSize(disp, .80)
    subs.setAspectRatio(disp, float(width) / float(height))
    subs.showDisplay(disp, width, height, title, None, None, panel)
    return disp
Exemple #8
0
def contour(data, panel=None, enableLabels=1, interval=None, width=400, height=400, title="VisAD Contour Plot"):

  """
  Quick plot of a contour (isopleth) from <data>.  <panel> is the name
  of a panel to put this into (default= make a new one),
  <enableLabels> controls whether the contour lines will be labelled,
  <interval[4]> is a list containing the contour interval info
  (interval, minimum, maximum, base), <width> and <height> are the
  dimensions, <title> is the phrase for the title bar.  Returns a
  reference to the display.

  """
  if isinstance(data,PyList) or isinstance(data,PyTuple):
    data = field(data)

  ndom = domainDimension(data)
  if ndom != 2:
    print "domain dimension must be 2!"
    return None

  dom_1 = RealType.getRealType(domainType(data,0) )
  dom_2 = RealType.getRealType(domainType(data,1)) 
  rng = RealType.getRealType(rangeType(data,0))
  rngMap = ScalarMap(rng, Display.IsoContour)
  xMap = ScalarMap(dom_1, Display.XAxis)
  yMap = ScalarMap(dom_2, Display.YAxis)
  maps = (xMap, yMap, rngMap)

  disp = subs.makeDisplay(maps)
  ci = rngMap.getControl()
  ci.enableLabels(enableLabels)
  if interval is not None:
    ci.setContourInterval(interval[0], interval[1], interval[2], interval[3])

  dr=subs.addData("contours", data, disp)
  subs.setBoxSize(disp, .80)
  subs.setAspectRatio(disp, float(width)/float(height))
  subs.showDisplay(disp,width,height,title,None,None,panel)

  return disp
Exemple #9
0
def lineplot(data,
             panel=None,
             color=None,
             width=400,
             height=400,
             title="Line Plot"):
    """
  Quick plot of a line plot from <data>.  <panel> is the name of a
  panel to put this into (default= make a new one), <color> is the
  color to use, <width> and <height> are the dimensions, <title> is
  the phrase for the title bar.  Returns a reference to the display.
  """

    if isinstance(data, PyTuple) or isinstance(data, PyList):
        data = field(data)

    domt = domainType(data)
    rngt = rangeType(data)
    xaxis = ScalarMap(domt[0], Display.XAxis)
    if isinstance(rngt, RealTupleType):
        yaxis = ScalarMap(rngt[0], Display.YAxis)
    else:
        yaxis = ScalarMap(rngt, Display.YAxis)

    axes = (xaxis, yaxis)

    disp = subs.makeDisplay(axes)
    constmap = subs.makeColorMap(color)

    dr = subs.addData("Lineplot", data, disp, constmap)
    subs.setBoxSize(disp, .70)
    showAxesScales(disp, 1)
    setAxesScalesFont(axes, Font("Monospaced", Font.PLAIN, 18))

    subs.setAspectRatio(disp, float(width) / float(height))
    subs.showDisplay(disp, width, height, title, None, None, panel)

    return disp
Exemple #10
0
def colorimage(red_data, green_data, blue_data, panel=None, colortable=None, width=400, height=400, title="VisAD Color Image"):
  """
  Display a color image, from three images <red_data>, <green_data>
  and <blue_data>.  <panel> is the name of a panel to put this into
  (default= make a new one), <colortable> is a color table to use (def
  = gray scale), <width> and <height> are the dimensions.  <title> is
  the phrase for the title bar.  Returns a reference to the display.

  """


  _comb_image = FieldImpl.combine( [red_data, green_data, blue_data])
  dom_1 = RealType.getRealType(domainType(_comb_image,0))
  dom_2 = RealType.getRealType(domainType(_comb_image,1))
  rng = rangeType(_comb_image)
  maps = subs.makeMaps(dom_1,'x', dom_2, 'y', rng[0], 'red',
     rng[1], 'green', rng[2], 'blue')

  disp = subs.makeDisplay(maps)
  subs.addData('comb',_comb_image,disp)
  subs.setBoxSize(disp, .80)
  subs.setAspectRatio(disp, float(width)/float(height))
  subs.showDisplay(disp,width,height,title,None,None,panel)
  return disp
Exemple #11
0
def image(data, panel=None, colortable=None, width=400, height=400, title="VisAD Image"):
  """
  Display an image with a gray scale color mapping.  <data> contains
  the image, <panel> is the name of a panel to put this into (default=
  make a new one), <colortable> is a color table to use (def = gray
  scale), <width> and <height> are the dimensions.  <title> is the
  phrase for the title bar.  Returns a reference to the display.
  """
  if isinstance(data,PyList) or isinstance(data,PyTuple):
    data = field(data)

  dom_1 = RealType.getRealType(domainType(data,0) )
  dom_2 = RealType.getRealType(domainType(data,1)) 
  rng = RealType.getRealType(rangeType(data,0))
  rngMap = ScalarMap(rng, Display.RGB)
  xMap = ScalarMap(dom_1, Display.XAxis)
  yMap = ScalarMap(dom_2, Display.YAxis)
  maps = (xMap, yMap, rngMap)

  #disp = subs.makeDisplay2D(maps)
  disp = subs.makeDisplay(maps)

  if colortable is None:
    # make a gray-scale table
    gray = []
    for i in range(0,255):
      gray.append( float(i)/255.)
    colortable = (gray, gray, gray)

  rngMap.getControl().setTable(colortable)

  dr=subs.addData("brightness", data, disp)
  subs.setBoxSize(disp, .80)
  subs.setAspectRatio(disp, float(width)/float(height))
  subs.showDisplay(disp,width,height,title,None,None,panel)
  return disp
Exemple #12
0
def mapimage(imagedata,
             mapfile="outlsupw",
             panel=None,
             colortable=None,
             width=400,
             height=400,
             lat=None,
             lon=None,
             title="VisAD Image and Map"):
    """
  Display an image with a basemap.  <imagedata> is the image object,
  <mapfile> is the name of the map file to use (def = outlsupw).
  <panel> is the name of a panel to put this into (default= make a new
  one), <colortable> is a color table to use (def = gray scale),
  <width> and <height> are the dimensions.  <lat> and <lon> are
  lists/tuples of the range (min->max) of the domain (def = compute
  them). <title> is the phrase for the title bar.  Returns a reference
  to the display.
  """

    rng = RealType.getRealType(rangeType(imagedata, 0))
    rngMap = ScalarMap(rng, Display.RGB)
    xMap = ScalarMap(RealType.Longitude, Display.XAxis)
    yMap = ScalarMap(RealType.Latitude, Display.YAxis)
    maps = (xMap, yMap, rngMap)
    dom = getDomain(imagedata)
    xc = dom.getX()
    yc = dom.getY()
    xl = len(xc)
    yl = len(yc)
    if xl > 1024 or yl > 1024:
        print "Resampling image from", yl, "x", xl, "to", min(yl,
                                                              1024), "x", min(
                                                                  xl, 1024)
        imagedata = resample(
            imagedata,
            makeDomain(dom.getType(), xc.getFirst(), xc.getLast(),
                       min(xl,
                           1024), yc.getFirst(), yc.getLast(), min(yl, 1024)))

    if lat is None or lon is None:
        c = dom.getCoordinateSystem()
        ll = c.toReference(((0, 0, xl, xl), (0, yl, 0, yl)))
        import java.lang.Double.NaN as missing

        if (min(ll[0]) == missing) or (min(ll[1]) == missing) or (min(
                ll[1]) == max(ll[1])) or (min(ll[0]) == max(ll[0])):
            # compute delta from mid-point...as an estimate
            xl2 = xl / 2.0
            yl2 = yl / 2.0
            ll2 = c.toReference(((xl2, xl2, xl2, xl2 - 10, xl2 + 10),
                                 (yl2, yl2 - 10, yl2 + 10, yl2, yl2)))
            dlon = abs((ll2[1][4] - ll2[1][3]) * xl / 40.) + abs(
                (ll2[0][4] - ll2[0][3]) * yl / 40.)

            dlat = abs((ll2[0][2] - ll2[0][1]) * yl / 40.) + abs(
                (ll2[1][2] - ll2[1][1]) * xl / 40.)

            lonmin = max(-180., min(ll2[1][0] - dlon, min(ll[1])))
            lonmax = min(360., max(ll2[1][0] + dlon, max(ll[1])))

            latmin = max(-90., min(ll2[0][0] - dlat, min(ll[0])))
            latmax = min(90., max(ll2[0][0] + dlat, min(ll[0])))

            xMap.setRange(lonmin, lonmax)
            yMap.setRange(latmin, latmax)
            print "computed lat/lon bounds=", latmin, latmax, lonmin, lonmax

        else:
            xMap.setRange(min(ll[1]), max(ll[1]))
            yMap.setRange(min(ll[0]), max(ll[0]))

    else:
        yMap.setRange(lat[0], lat[1])
        xMap.setRange(lon[0], lon[1])

    disp = subs.makeDisplay(maps)

    if colortable is None:
        # make a gray-scale table
        gray = []
        for i in range(0, 255):
            gray.append(float(i) / 255.)
        colortable = (gray, gray, gray)

    rngMap.getControl().setTable(colortable)
    mapdata = load(mapfile)
    drm = subs.addData("basemap", mapdata, disp)
    dr = subs.addData("addeimage", imagedata, disp)
    subs.setBoxSize(disp, .80, clip=1)
    subs.setAspectRatio(disp, float(width) / float(height))
    subs.showDisplay(disp, width, height, title, None, None, panel)
    return disp
Exemple #13
0
    slice_set = Gridded3DSet(d, [xs, ys, zs], len(xv), len(yv), cs, units,
                             errors)
    # resample our original 3-D grid to the 2-D grid
    return grid.resample(slice_set)


# add an initial slice to the display
slice = subs.addData("slice", makeSlice(zv[0]), display)


# a little program to run whenever the user moves the slider
#   it displays a 2-D grid at the height defined by the slider
class MyCell(CellImpl):
    def doAction(this):
        z = level.getData().getValue()
        slice.setData(makeSlice(z))


# connect the slider to the little program
cell = MyCell()
cell.addReference(level)

# turn on axis scales in the display
showAxesScales(display, 1)

# show the display on the screen, along with the slider
subs.showDisplay(display, top=slider, bottom=contourwidget)

# ordinary plot of the 3-D grid for comparison
plot(grid)
Exemple #14
0
    slice_set = Gridded3DSet(d, [xs, ys, zs], len(xv), len(yv), cs, units,
                             errors)
    # resample our original 3-D grid to the 2-D grid
    return grid.resample(slice_set)


# add an initial slice to the display
slice = subs.addData("slice", makeSlice(zv[0]), display)


# a little program to run whenever the user moves the slider
#   it displays a 2-D grid at the height defined by the slider
class MyCell(CellImpl):
    def doAction(this):
        z = level.getData().getValue()
        slice.setData(makeSlice(z))


# connect the slider to the little program
cell = MyCell()
cell.addReference(level)

# turn on axis scales in the display
showAxesScales(display, 1)

# show the display on the screen, along with the slider
subs.showDisplay(display, top=slider)

# ordinary plot of the 3-D grid for comparison
plot(grid)
Exemple #15
0
def mapimage(imagedata, mapfile="outlsupw", panel=None, colortable=None, width=400, height=400, lat=None, lon=None, title="VisAD Image and Map"):
  """
  Display an image with a basemap.  <imagedata> is the image object,
  <mapfile> is the name of the map file to use (def = outlsupw).
  <panel> is the name of a panel to put this into (default= make a new
  one), <colortable> is a color table to use (def = gray scale),
  <width> and <height> are the dimensions.  <lat> and <lon> are
  lists/tuples of the range (min->max) of the domain (def = compute
  them). <title> is the phrase for the title bar.  Returns a reference
  to the display.
  """

  rng = RealType.getRealType(rangeType(imagedata,0))
  rngMap = ScalarMap(rng, Display.RGB)
  xMap = ScalarMap(RealType.Longitude, Display.XAxis)
  yMap = ScalarMap(RealType.Latitude, Display.YAxis)
  maps = (xMap, yMap, rngMap)
  dom = getDomain(imagedata)
  xc = dom.getX()
  yc = dom.getY()
  xl = len(xc)
  yl = len(yc)
  if xl > 1024 or yl > 1024:
    print "Resampling image from",yl,"x",xl,"to",min(yl,1024),"x",min(xl,1024)
    imagedata = resample(imagedata, makeDomain(dom.getType(),
                         xc.getFirst(), xc.getLast(), min(xl, 1024),
                         yc.getFirst(), yc.getLast(), min(yl, 1024) ) )

  if lat is None or lon is None:
    c=dom.getCoordinateSystem()
    ll = c.toReference( ( (0,0,xl,xl),(0,yl,0,yl) ) )
    import java.lang.Double.NaN as missing

    if (min(ll[0]) == missing) or (min(ll[1]) == missing) or (min(ll[1]) == max(ll[1])) or (min(ll[0]) == max(ll[0])):
      # compute delta from mid-point...as an estimate
      xl2 = xl/2.0
      yl2 = yl/2.0
      ll2 = c.toReference( ( 
                (xl2,xl2,xl2,xl2-10, xl2+10),(yl2,yl2-10,yl2+10,yl2,yl2)))
      dlon = abs((ll2[1][4] - ll2[1][3])*xl/40.) + abs((ll2[0][4] - ll2[0][3])*yl/40.)

      dlat = abs((ll2[0][2] - ll2[0][1])*yl/40.) + abs((ll2[1][2] - ll2[1][1])*xl/40.)

      lonmin = max( -180., min(ll2[1][0] - dlon, min(ll[1])))
      lonmax = min( 360., max(ll2[1][0] + dlon, max(ll[1])))

      latmin = max(-90., min(ll2[0][0] - dlat, min(ll[0])))
      latmax = min(90., max(ll2[0][0] + dlat, min(ll[0])))

      xMap.setRange(lonmin, lonmax)
      yMap.setRange(latmin, latmax)
      print "computed lat/lon bounds=",latmin,latmax,lonmin,lonmax

    else:
      xMap.setRange(min(ll[1]), max(ll[1]))
      yMap.setRange(min(ll[0]), max(ll[0]))

  else:
    yMap.setRange(lat[0], lat[1])
    xMap.setRange(lon[0], lon[1])

  disp = subs.makeDisplay(maps)

  if colortable is None:
    # make a gray-scale table
    gray = []
    for i in range(0,255):
      gray.append( float(i)/255.)
    colortable = (gray, gray, gray)

  rngMap.getControl().setTable(colortable)
  mapdata = load(mapfile)
  drm = subs.addData("basemap", mapdata, disp)
  dr=subs.addData("addeimage", imagedata, disp)
  subs.setBoxSize(disp, .80, clip=1)
  subs.setAspectRatio(disp, float(width)/float(height))
  subs.showDisplay(disp,width,height,title,None,None,panel)
  return disp
Exemple #16
0
      # zs.append(z + 0.04 * ((x-xv[9])*(x-xv[9])+(y-yv[9])*(y-yv[9])))
  # create a 2-D grid embedded at height 'z' in 3-D space
  slice_set = Gridded3DSet(d, [xs, ys, zs], len(xv), len(yv),
                           cs, units, errors)
  # resample our original 3-D grid to the 2-D grid
  return grid.resample(slice_set)

# add an initial slice to the display
slice = subs.addData("slice", makeSlice(zv[0]), display)

# a little program to run whenever the user moves the slider
#   it displays a 2-D grid at the height defined by the slider
class MyCell(CellImpl):
  def doAction(this):
    z = level.getData().getValue()
    slice.setData(makeSlice(z))

# connect the slider to the little program
cell = MyCell();
cell.addReference(level)

# turn on axis scales in the display
showAxesScales(display, 1)

# show the display on the screen, along with the slider
subs.showDisplay(display, top=slider, bottom=rgbwidget)

# ordinary plot of the 3-D grid for comparison
plot(grid)

Exemple #17
0
def histogram(data,
              bins=20,
              width=400,
              height=400,
              title="VisAD Histogram",
              color=None,
              bottom=None,
              top=None,
              panel=None,
              clip=1):
    """
  Quick plot of a histogram from <data>.  <bins> is the number of bins
  to use (def = 20), <panel> is the name of a panel to put this into
  (default= make a new one), <color> is the color to use, <width> and
  <height> are the dimensions, <title> is the phrase for the title
  bar.  Returns a reference to the display.
  """
    if isinstance(data, PyList) or isinstance(data, PyTuple):
        data = field(data)

    from java.lang.Math import abs

    x = []
    y = []

    h = hist(data, [0], [bins])
    dom = getDomain(h)
    d = dom.getSamples()
    step2 = dom.getStep() / 2

    hmin = h[0].getValue()
    hmax = hmin

    for i in range(0, len(h)):
        hval = h[i].getValue()
        if hval < hmin: hmin = hval
        if hval > hmax: hmax = hval

    for i in range(0, len(h)):
        xm = d[0][i] - step2
        xp = d[0][i] + step2
        x.append(xm)
        y.append(hmin)
        x.append(xm)
        hval = h[i].getValue()
        y.append(hval)
        x.append(xp)
        y.append(hval)
        x.append(xp)
        y.append(hmin)

    domt = domainType(h)
    rngt = rangeType(h)

    xaxis = ScalarMap(domt[0], Display.XAxis)
    yaxis = ScalarMap(rngt, Display.YAxis)

    yaxis.setRange(hmin, hmax + abs(hmax * .05))

    disp = subs.makeDisplay((xaxis, yaxis))
    subs.drawLine(disp, (x, y), mathtype=(domt[0], rngt), color=color)
    showAxesScales(disp, 1)
    subs.setBoxSize(disp, .65, clip)
    subs.setAspectRatio(disp, float(width) / float(height))
    subs.showDisplay(disp, width, height, title, bottom, top, panel)

    return disp
Exemple #18
0
      # zs.append(z + 0.04 * ((x-xv[9])*(x-xv[9])+(y-yv[9])*(y-yv[9])))
  # create a 2-D grid embedded at height 'z' in 3-D space
  slice_set = Gridded3DSet(d, [xs, ys, zs], len(xv), len(yv),
                           cs, units, errors)
  # resample our original 3-D grid to the 2-D grid
  return grid.resample(slice_set)

# add an initial slice to the display
slice = subs.addData("slice", makeSlice(zv[0]), display)

# a little program to run whenever the user moves the slider
#   it displays a 2-D grid at the height defined by the slider
class MyCell(CellImpl):
  def doAction(this):
    z = level.getData().getValue()
    slice.setData(makeSlice(z))

# connect the slider to the little program
cell = MyCell();
cell.addReference(level)

# turn on axis scales in the display
showAxesScales(display, 1)

# show the display on the screen, along with the slider
subs.showDisplay(display, top=slider, bottom=contourwidget)

# ordinary plot of the 3-D grid for comparison
plot(grid)

Exemple #19
0
      # zs.append(z + 0.04 * ((x-xv[9])*(x-xv[9])+(y-yv[9])*(y-yv[9])))
  # create a 2-D grid embedded at height 'z' in 3-D space
  slice_set = Gridded3DSet(d, [xs, ys, zs], len(xv), len(yv),
                           cs, units, errors)
  # resample our original 3-D grid to the 2-D grid
  return grid.resample(slice_set)

# add an initial slice to the display
slice = subs.addData("slice", makeSlice(zv[0]), display)

# a little program to run whenever the user moves the slider
#   it displays a 2-D grid at the height defined by the slider
class MyCell(CellImpl):
  def doAction(this):
    z = level.getData().getValue()
    slice.setData(makeSlice(z))

# connect the slider to the little program
cell = MyCell();
cell.addReference(level)

# turn on axis scales in the display
showAxesScales(display, 1)

# show the display on the screen, along with the slider
subs.showDisplay(display, top=slider)

# ordinary plot of the 3-D grid for comparison
plot(grid)

Exemple #20
0
    slice_set = Gridded3DSet(d, [xs, ys, zs], len(xv), len(yv), cs, units,
                             errors)
    # resample our original 3-D grid to the 2-D grid
    return grid.resample(slice_set)


# add an initial slice to the display
slice = subs.addData("slice", makeSlice(zv[0]), display)


# a little program to run whenever the user moves the slider
#   it displays a 2-D grid at the height defined by the slider
class MyCell(CellImpl):
    def doAction(this):
        z = level.getData().getValue()
        slice.setData(makeSlice(z))


# connect the slider to the little program
cell = MyCell()
cell.addReference(level)

# turn on axis scales in the display
showAxesScales(display, 1)

# show the display on the screen, along with the slider
subs.showDisplay(display, top=slider, bottom=rgbwidget)

# ordinary plot of the 3-D grid for comparison
plot(grid)
Exemple #21
0
                   rangetype[0], "text")
disp=subs.makeDisplay3D(maps)

pcontrol = disp.getProjectionControl()
dzoom = DiscoverableZoom()
pcontrol.addControlListener(dzoom)

tcontrol = maps[2].getControl()
tcontrol.setAutoSize(1)

rends = []

for i in range (ydim/2, ydim/2 + 20):
  for j in range (xdim/2, xdim/2 + 20):

    ref = DataReferenceImpl("data")
    latlon = cs.toReference( ( (j,), (i,) ))
    tuple = RealTuple( ( 
           a[i * xdim + j][0], 
           Real( RealType.Latitude, latlon[0][0]), 
           Real( RealType.Longitude, latlon[1][0]) ) )

    ref.setData(tuple)
    rend = DefaultRendererJ3D()
    rends.append(rend)
    disp.addReferences(rend, ref, None)

dzoom.setRenderers(rends, .1)
subs.showDisplay(disp)

Exemple #22
0
rangetype = a.getType().getRange()
maps = subs.makeMaps(RealType.Latitude, "y", RealType.Longitude, "x",
                     rangetype[0], "text")
disp = subs.makeDisplay3D(maps)

pcontrol = disp.getProjectionControl()
dzoom = DiscoverableZoom()
pcontrol.addControlListener(dzoom)

tcontrol = maps[2].getControl()
tcontrol.setAutoSize(1)

rends = []

for i in range(ydim / 2, ydim / 2 + 20):
    for j in range(xdim / 2, xdim / 2 + 20):

        ref = DataReferenceImpl("data")
        latlon = cs.toReference(((j, ), (i, )))
        tuple = RealTuple(
            (a[i * xdim + j][0], Real(RealType.Latitude, latlon[0][0]),
             Real(RealType.Longitude, latlon[1][0])))

        ref.setData(tuple)
        rend = DefaultRendererJ3D()
        rends.append(rend)
        disp.addReferences(rend, ref, None)

dzoom.setRenderers(rends, .1)
subs.showDisplay(disp)