HG primer

QUESTIONS

  • 1. What are the useful data structures from the HG package?
  • 2. What is in the HG?
  • 3. What is in the AF?
  • 4. What is in the PT?
  • 5. What is in the PGSTATE?
  • 6. How do I make and define these things?
  • 7. How do I find out all the commands that work on these things?
  • 8. How about a simple example of plotting a HG?
  • 9. How would I print a copy of this histogram?
  • 10. How do I plot values of members on a chain?
  • 11. How do I talk to saoDisplay?
  • ANSWERS

    1. What are the useful data structures from the HG package? There are 4 data structures defined in the HG package: HG A Histogram AF An Array of Floats PT A point PGSTATE The state of the pgplot display This package provides C and TCL interfaces to manipulate these structures and set their values from chains. It also plots HG and AF structures and allows selections from the plot to be drawn on the saoDisplay window. 2. The HG structure contains: - next, prev, and id so it can be on a chain - a name, xLabel, and yLabel, printed on the plots - nbin, the number of bins in the histogram - minimum, the lower edge of the first bin - maximum, the upper edge of the last bin - contents, the number of entries of each bin - error, the error in contents for each bin - overflow and underflow, for entries not in the bins 3. The AF structure contains: - next, prev, and id so it can be on a chain - a name, for plotting - nValue, the "length" of the array - value and error, the members of the array 4. The PT structure contains: - next, prev, and id so it can be on a chain - row, col to indicate location - radius, one additional parameter, usually used to define the size of a marker plotted on saoDisplay. 5. The PGSTATE structure holds information about the plotting, such as the device, number of windows, etc. The command pgstatePrint gives the complete list. 6. How do I make and define these things? In general, the command **New gives you a new, empty thing, and **Define makes it useful. **Del gets rid of it and its handle: Struct Creation Definition Destruction HG hgNew hgDefine hgDel AF afNew afDefine afDel PT ptNew ptDefine ptDel PGSTATE pgstateNew pgstateSet pgstateClose, pgstateDel 7. How do I find out all the commands that work on these things? Inside dervish, or any program derived from it, the command dervish> help -facil=hg will give you the complete list. You can then get help on specific commands. 8. How about a simple example of plotting a HG? First, make the empty histogram dervish> set hg [hgNew] h1 dervish> hgDefine $hg -name "Simple Example" -min 10 -max 20 -nbin 5 Simple Example Now, fill some of the bins dervish> hgFill $hg 15 dervish> hgFill $hg 16 dervish> hgFill $hg 17 Get ready to plot: dervish> set pg [pgstateNew] h2 dervish> pgstateOpen $pg Open /XWINDOW (The empty PGPLOT Window appears) dervish> hgPlot $pg $hg (The plot appears) dervish> pgstateClose $pg Close /XWINDOW In the graphics window: click any mouse button or type to continue (Kill the window) 9. How would I print a copy of this histogram? After the pgstateNew command, do the following: dervish> pgstateSet $pg -device /PS Then proceed as before. After the pgstateClose command, print the file pgplot.ps to your favorite printer. 10. How do I plot values of members on a chain? Do this in a two step process. First, project the member to plot to and AF. Then use afPlot to plot the two AFs. #===>Create a chain with three PTs on it. Check the size at the end. dervish> set chain [chainNew PT] h1 dervish> set pt [ptNew] h2 dervish> ptDefine $pt 1 1 30 h2 dervish> chainElementAddByPos $chain $pt dervish> set pt [ptNew] h3 dervish> ptDefine $pt 2 2 40 h3 dervish> chainElementAddByPos $chain $pt dervish> set pt [ptNew] h4 dervish> ptDefine $pt 3 4 50 h4 dervish> chainElementAddByPos $chain $pt dervish> chainSize $chain 3 #==> Now turn that into a couple of AFs. We will want to plot #==> col vs. radius, so make TWO AFs. dervish> set afCol [afFromChain $chain col] h5 dervish> set afRadius [afFromChain $chain radius] h6 #==> Take a look at one of these. (Warning: do not do this if the size #==> of your AF is very big or it will take forever to scroll!) dervish> afPrint $afCol position, value, error: 0 1.000000 0.000000 position, value, error: 1 2.000000 0.000000 position, value, error: 2 4.000000 0.000000 h5 #==> Get ready to plot dervish> set pg [pgstateNew] h7 dervish> pgstateOpen $pg Open /XWINDOW #==> Now do the actual plot. Note the order is Y vs. X. dervish> afPlot $pg $afCol $afRadius
  • 11. How do I talk to saoDisplay? Sorry this example depends on obsolete features of Dervish. We are working out a better example. First of all, you have to open the saoDisplay window BEFORE you create any pgplot windows. Here is an example. Note that I am now using eagphot since that is where the OBJ2 structure is defined. #==> Read in and display the region eagphot> set reg [regReadAsFits [regNew] Nov11C-200.fits] h1 eagphot> saoDisplay $reg 1 #==> Read in the dump file; get the size of $chain to make sure it is alive. eagphot> dumpOpen run/Nov11-3/Nov11C-200.dump r eagphot> dumpHandleRead h2 eagphot> dumpHandleRead h3 eagphot> dumpHandleRead h4 eagphot> dumpHandleRead h5 eagphot> dumpClose Error: shDumpNextRead: can't get next type eagphot> set chain h5 h5 eagphot> chainSize $chain 189 #==> Plot FWHM vs magnitude eagphot> set afFWHM [afFromChain $chain avgFWHM] h7 eagphot> set afMagnitude [afFromChain $chain magnitude] h8 eagphot> set pg [pgstateNew] h9 eagphot> pgstateOpen $pg Open /XWINDOW eagphot> afPlot $pg $afFWHM $afMagnitude #==>Note that this plot is messed up by one point with a huge FWHM. You #==>can exclude it by setting y limits in the plot command: eagphot> afPlot $pg $afFWHM $afMagnitude -ymax=20 #==>Now select one point from the plot and circle it on saoDisplay. #==>This involves two steps (done in the same line here). First, #==>create a chain FROM the plot, and then send this chain TO saoDisplay: eagphot> chainToSao [chainFromPlot $pg $chain] Waiting for cursor input in shChainToSao: Number of elements to draw is 1 h10 #==>When you get the "waiting for cursor input" line, move the cursor #==>into the plot and click with the LEFT button at the point you want. #==> Get the full story for this point: eagphot> chainToHandleArray h10 h12 eagphot> linkStructPrint h12 type OBJ2 next 0x1114c530 prev 0x0 id 0 row 1512.45987402 . . . #==> If you want to plot a group of points, choose two corners of the #==> rectangle with the MIDDLE mouse button. The RIGHT mouse button #==> chooses nothing. #==> Turn off labels with: eagphot> saoLabel off #==> Erase what you have drawn with: eagphot> saoReset (sorry, the command to resize the plot using the cursor is broken)