ri (a/d) idl routines

Last modified: Wed Oct 25 13:19:34 2017.


List of Routines


Routine Descriptions

RICROSS2DFIT - FIT 2D GAUSSIAN TO A CROSS PATTERN.

[Next Routine] [List of Routines]
NAME:
ricross2dfit - fit 2d gaussian to a cross pattern.
SYNTAX: coef=ricross2dfit(baz,bza,coefinit,azfit=azfit,zafit=zafit,$
             covar=covar,chisq=chisq,sigma=sigma,sigCoef=sigCoef,$
             trouble=trouble,weights=weights
ARGS:
   baz :{ricrossinp} azimuuth input info
   bza :{ricrossinp} za       input info
coefinit[10]:floats  initial values for coef.
              [0] - offset
              [1] - amplitude
              [2] - xoffset
              [3] - yoffset
              [4] - fwhm az (amin)
              [5] - fwhm za (amin)
              [6] - theta  rotate unprimed to primed aligned along ellipsoid 
                           of beam, degrees.
              [7] - linear term in za deltaTsys/deltaZa (K/Amin)
KEYWORDS:
   pol : int  0 (def) return polA, 1 --> return polB

RETURNS:
azfit[npts]: fit evaluated along az strip
zafit[npts]: fit evaluated along za strip
covar[n,n]:float covariance matrix
       chisq:float chisq of fit
      sigma :float sigma of fit
 sigCoef[n]:float sigmas for coefficients
 weights[npts,2]: weights to use az,za
                smaller number, less important
NOTES:
   Set fwhm az,za to slightly different values. The routine lets curvefit
(in idl) compute the derivatives). If the fwhm are the same, then the
rotation angle theta has no affect. The derivative comes out to be 0
and it divides by the partial derivative array when doing the fit..

 If you enter 8 coefinit values then it will all fit for a linear term in za

(See /pkg/rsi/local/libao/phil/ri/ricross2dfit.pro)


RICROSSCAL - COMPUTE THE CAL SCALING FACTOR FOR RI CROSS PATTERNS

[Previous Routine] [Next Routine] [List of Routines]
NAME:
ricrosscal - compute the cal scaling factor for ri cross patterns
SYNTAX: ncal=ricrosscal(bcal,bscale,calval)
ARGS:   bcal[n]:  {cross} cal scans input from ricrossinp.
RETURNS:
      bscale[2,n]:float  scale factor to convert counts to kelvins
      calval[2,n]:float  cal value used (pola,polB)used
      ncal       : int   number of cal records processed

DESCRIPTION:
   The ricrossinp routine returns the data and cal records for a cross
pattern. This routine will compute the conversion factor from a/d counts
to Kelvins using the cal record and the cal value (in kelvins).

   The input data structure returned from ricrossinp is:

        bcal.h[nrecs]     {hdr} header from each rec of strip
        bcal.don[npts,2]  float cal On samples 
        bcal.doff[npts,2] float cal off samples
        b.d[npts,2]  - the data polA,b

   Normally then second index is polA, or polB (since the ricrossinp
routine uses detected data).

   The routine will lookup the cal value using calget().
the conversion factor from kelevins

(See /pkg/rsi/local/libao/phil/ri/ricrosscal.pro)


RICROSSINP - GET 1 OR MORE RI CROSS PATTERNS

[Previous Routine] [Next Routine] [List of Routines]
NAME:
ricrossinp - get 1 or more ri cross patterns
SYNTAX: patInp=ricrossinp(lun,baz,bza,bcal,patreq,scan=scan)
ARGS:   lun : long  lun to read from
      patreq: long  the number of patterns to read in
RETURNS:
        baz : {} return az strips
        bza : {} return za strips
       bcal : {} return cals here if we find them
      patInp: long number of patterns input

DESCRIPTION:
   Read in 1 or more ricross patterns. The pattern has an az strip and 
a za strip. These are return in baz and bza. If cals were taken then they
will be returned in bcal. By default, the routine starts reading from the 
current position in the file. If the scan keyword is supplied then 
it will position to scan before reading the data. The format of the returned
data for a single pattern is (either baz or bza):
   b.h[nrecs]   - header from each rec of az or za strip
   b.d[npts,2]  - all the data for 1 strip. The second dimension is polA,B

(See /pkg/rsi/local/libao/phil/ri/ricrossinp.pro)


RICROSSINP1 - GET 1 STRIP OF A CROSS PATTERN

[Previous Routine] [Next Routine] [List of Routines]
NAME:
ricrossinp1 - get 1 strip of a cross pattern
SYNTAX: istat=ricrossinp1(lun,b)
ARGS:   lun : long lun to read from
        b.{ }: structure from the cross pattern (either az or za strip)
        b.d[npts,2]  - the data polA,b
DESCRIPTION:
   This routine is call by ricrossinp to input a single strip of the
ricross pattern.

(See /pkg/rsi/local/libao/phil/ri/ricrossinp1.pro)


RICROSSPLT - PLOT THE DATA FROM A CROSS

[Previous Routine] [Next Routine] [List of Routines]
NAME:
ricrossplt - plot the data from a cross
SYNTAX: ricrossplt,baz,bza,az=az,za=za,step=step,pol=pol
ARGS:
   baz[n]: {anoncross} hold az info
   bza[n]: {anoncross} hold za info
KEYWORDS:
   az   if set then include az in plots        
   za   if set then include za in plots        
  pol:  string "a", or "b" if not provided, then plot both
step=step  if n>1 then do a strip plot with this step between strips
           default is 0.
DESCRIPTION:
   plot the data input from ricrossinp. The default is to plot
both az and za. If only az is set or only za is set, then
just that axis will be plotted. If n is > 1 then the strips will be
overplotted with a step between each strip.

(See /pkg/rsi/local/libao/phil/ri/ricrossplt.pro)


RIGETHDR - INPUT AN RI HEADER

[Previous Routine] [Next Routine] [List of Routines]
NAME:
rigethdr - input an ri header
SYNTAX: istat=rigethdr(lun,hdr,scan=scan,pos=pos)
ARGS:   lun    : unit number for file (already opened)
        hdr    : {hdr} return data here.
KEYWORDS:
       scan    : long . position to start of this scan before reading
       pos     : int  . 1 - position to start of this header before returning
RETURNS:
        istat  : int
           1 - gotit
           0 - hit eof
          -1 - could not position to requested scan
          -2 -  bad data in hdr
DESCRIPTION:
   Read the next ri header and return it. Optionally position to the start
of this header before returning. This routine is used to peak at the
header to decide how to process the record before calling riget.

   The caller should have already defined the {hdr} structure  before calling
this routine (usually done in the xxriinit routine for the particular 
datataking program). 

(See /pkg/rsi/local/libao/phil/ri/rigethdr.pro)


RIMONIMG - MONITOR RI DATA

[Previous Routine] [Next Routine] [List of Routines]
NAME:
rimonimg - monitor ri data
SYNTAX: img=rimonimg(fbase,num,lun=lun,tmtoavg=tmtoavg,
                   numx=numx,numy=numy,usefifo2=usefifo2,d=d,val=val,
                   pixwin=pixwin,ilim=ilim)
ARGS:
  fbase: string Base filename to read from (eg '/share/aeron5/24jul03').
                Do not include the . or file number.
   num : int    file number of file to start on. 

KEYWORDS:
   lun : int    If provided, then process this file from the current 
                position. When done with the file return. In this case
                fbase and num are ignored. You also can not jump to other 
                files from the internal menu.
ipptoavg:long   number of ipps to average together. The default is none
tmtoavg: long   number of time points to average. default is none
numDisp: long   The number of averaged ipps to display in the image. The
                default is 900 averaged ipps.
usefifo2:       If set then use fifo 2. The default is fifo 1.
 val[2]: float  Clip the  power (a/d levels squared) to [min,max] and
                then scale to the full range of the display device (
                0 to 255). The default is to clip the power at 6 sigma
                (as measured from the first image).

 pixwin:        if set then use a pixwin when drawing a new image. This
                cuts down on the flashing. It is useful when you are
                averaging only 1 or 2 ipps.
 ilim  : long   if supplied then limit image to these indices of the 
                data rec (0 based).
RETURNS:
   img[m,numDisp]:float    the last image displayed.
   d[n]         if this keyword is provided then the data read
                for the last image is returned here.
DESCRIPTION:
   rimonimg will make continuous images of meteor data. The mean is removed from
the voltages, power is computed, and then toavg ipps are averaged together.
numDisp averaged ipps are then displayed as height versus time. When 
the end of file is hit, the routine will advance to the next filenumber.
If no data is available, the routine will wait until it becomes available.
   The user can modify things by hitting any key and bringing up an
internal menu:

Cmd CurVal   function
 a dome      antenna ch, dome
 f   70      move to new fileNum
 l           list all files
 n           next file (or quit if 1 file)
 q           to quit
 r           rewind current file
 s  0        single step 0,1 (off,on)
 otherkey    continue

The commands are:

 a  dome/ch  This lets you switch between dome and carriage house display

 f  filenum  You can start displaying at the start of a different 
             filenumber. If the new filenumber is illegal then no 
             change is made.

 l           This will list all of the available files starting with
             fbase. The last file will also contain its size.

 n           move to the next file number.

 q           quit the routine.

 r           rewind and start over in the current file.

 s  0,1      turn on,off single step mode.When it is on, the routine
             will pause after every image waiting for the user to
             enter return.

 otherKey    any other key will cause the display to continue.
             This allows you to pause the display to look at it for
             a while.

(See /pkg/rsi/local/libao/phil/ri/rimonimg.pro)


RISPC - INPUT AND COMPUTE SPECTRA FROM RI DATA

[Previous Routine] [Next Routine] [List of Routines]
NAME:
rispc - input and compute spectra from ri data
SYNTAX: istat=rispc(lun,freqRes,spc,dc=dc,pwrof2=pwrof2,hdr=hdr,chan=chan,
                    rawd=rawd,freq=freq)

ARGS:   lun    : unit number for file (already opened)
     freqRes   : float freq resolution Hz we want in the spectra
KEYWORDS:
     pwrOf2    :       if set then force the output spectra to be the closest
                       power of 2
       hdr     : {hdr} pass in a header for this file so we don't have
                       to read the first record to get 1.
       dc      : complex remove this before computing spectra 
      chan     : int   Which channel to use
      dec      : int   decimate input data by this amount. 0=1 is no
                       decimation

RETURNS:
  istat        :      1 got spectra
                      0 hit eof
                      -1 error
   spc[n]      : float spectra
rawd[]         : {ri}  return input records here.
 freq[n]       : float freq array for the spectra

DESCRIPTION:
   Read in ri data and compute the power spectra.  The routine will optionally
remove dc and smooth/decimate before computing the spectra. The computed
power spectra will be returned. The routine can also return a copy of the
 input raw data (keyword rawd=) and a freq array (freq=) that corresponds 
to the computed spectra.
   The routine assumes that the data is taken as complex data. If more
that 1 channel was taken, then the chan= keyword can select between
chan 1 and chan 2 (chan 1 is the default).  
   By default the routine will read the first record to get the header
info. To save time, you can pass in a header for this file using the
hdr=  keyword.
   The dec= keyword allows averaging/decimation in time before
computing the spectra. 

   The processing is:
 1. grab a header from the file if hdr= keyword not used..
 2. compute the spectral length: 
       1./(freqRes*smpTm*dec)
    make this the closest power of 2 if pwrof2 is set.
 3. compute the number of input recs needed for this data.
 4. input the data, smooth and decimate by dec if requested.
 5. remove dc if supplied
 6. compute the spectra: spc=abs(fft(d))^2
 7. rotate the spectra to put dc in the middle: spc=shift(spc,smpSpc/2)

Example:
   openr,lun,file,/get_lun

; compute dc first over the 1st 100 recs

   istat=riget(lun,d,numrecs=100)
   dc=total(d.d1)
   rew,lun             ; rewind file

;  use the header read in to pass to routine 
   
   hdr=d[0].h

;  decimate by 128, force spectra to be a power of 2
;  return the freq array on the first call
;  compute 100 spectra

   freqRes=1.              ; 1 hz resolution
   toSmo  =128L            ; decimate by 128..
   numSpc = 100
   for i=0,numSpc-1 do begin
      if i eq 0 then begin
         istat=rispc(lun,freqRes,spc,dec=toSmo,freq=freq,hdr=hdr,dc=dc)
         spcAr=fltarr(n_elements(spc),numSpc)  ; be sure you have mem for this.
      endif else begin
         istat=rispc(lun,freqRes,spc,dec=toSmo,hdr=hdr,dc=dc)
      endelse
     spcAr[*,i]=spc
   endfor

(See /pkg/rsi/local/libao/phil/ri/rispc.pro)


RISTRIPCH - STRIPCHART RECORDING OF TOTAL POWER

[Previous Routine] [List of Routines]
NAME:
ristripch - stripchart recording of total power
SYNTAX:   ristripch,lun,maxpnt=maxpnt,v1=v1,v2=v2,mean=mean,$
                   scan=scan,rec=rec,rdDelay=rdDelay,pltDelay=pltDelay,$
                   rdStep=rdStep,win=win
 ARGS:
   lun:    int     to read power from
KEYWORDS:
   maxpnt: long    max number of points to display at once. default: 1000
   v1[2] : float   min,max value for top plot
   v2[2] : float   min,max value for bottom plot (polA-polB)
   mean  : long    if set then remove mean from both plots.
   scan : long     position to scan before starting. The
                   default is the current position
   rec   : long    record of scan to position to before starting.
                   default: if scan present then:1 else current rec.
rdDelay: float     number of seconds to wait between reads if no new
                   data available.
pltDelay: float    number of seconds to wait after each plot. Use this
                   to slowly scan a file that already exists.
   rdStep: long    max number of points to try and read at a time. Plot
                   will increment by this amount when you read a file.
   win   : long    window number to plot in. Default is 0
DESCRIPTION:
   The routine makes a stripchart recording of the total power and power
difference polA-polB. It will step through the data file displaying
up to MAXPNT pnts on the screen. When this value is reached, the plot will
start scolling to the left. When the end of file is hit, the routine
will wait rdDelay seconds (default of 1 second) and then try to read
any new data in the file. This allows you to monitor data as it is 
being taken. If you are scrolling through a file offline, use PLTDELAY
to slow down the plotting rate (if it is too fast). At the end of the file
hit any key and the enter q to quit (see below).

   The top plot is the 0lag total power. The units are linear in power and the
definition is measured/optimum power (for statistics of 3/9level sampling).
You can change the vertical scale with the v1[min,max] keyword or from the
menu displayed you hit any key. The line colors correspond to the 8 
subcorrelators available on the interim correlator.

   The bottom plot is the power difference PolA-PolB for each correlator
board (NOTE: currently this only works if polA,polB are on the same board).
The vertical scale can be changed with the v2=v2[min,max] keyword or from
the menu displayed when you hit any key.

   You can stop the plotting by touching any key on the keyboard.
A menu will be presented that lets you modify some parameters and then
continue. The menu is:

command       function
q             to quit
r             rewind file
v1  min max   new min,max for top    window 
v2  min max   new min,max for bottom window 
blank line ..continue 

   You can quit, rewind the file and continue, change the vertical scale of
the top plot with v1 min max, or change the vertical scale of the bottom
plot. Any other inputline will let you continue from where you are
(unlike cormonall, you have to enter return for the program to read the
inputline.

EXAMPLES:
1. monitor the online datataking:
   lun=coronl()
   corstripch,lun

2. set fewer points per plot for better resolution. Set the top vertical
   scale to .8,2. and the bottom plot to -.4,.4.
   corstripch,lun,maxpnt=600,v1=[.8,2],v2=[-.4,.4]

3. If you want to restart from the begining of the file:
   hit any character
   r 
   and it will rewind an continue

4. If you want to monitor a file offline, with no wait between
   updates, and 500 points plotted:
   openr,lun,'/share/olcor/corfile.30apr03.x102.1',/get_lun
   corstripch,lun,maxpnt=500,v1=[.5,3]

5. Do the same thing but wait 1 second between plots and read 200 points at
   a time:
   corstripch,lun,maxpnt=500,v1=[.5,3],pltDelay=1,rdstep=200

NOTE:
   You can change the size of the plot by expanding or contracting the
plot window. The plot will rescale itself.

(See /pkg/rsi/local/libao/phil/ri/ristripch.pro)