Mike Wiltberger wrote:
>
> Hello,
> I would like to make a vector field plot of some 2d electric field
> data. The problem is that the data was computed on an irregular grid
> and the routines within idl only allow for regular grids. Has anyone
> written a routine to do this with irregular grids?
>
I wrote this for PV-Wave some time ago, but I don't think I used
anything that won't also work in IDL. I should also warn you that
you may have to experiment with the SymSize option as this routine
does not do any pre-scaling of the input data...
Correction: There is one section of this program that uses PV-Wave
Date/Time structures. If you are using IDL, you should
comment out this part...
**** cut here ****
; TO DO:
; - Legends (hard)
;
; PROCEDURE STICKPLOT, U, V
; PROCEDURE STICKPLOT, X, U, V
; PROCEDURE STICKPLOT, X, Y, U, V
; PROCEDURE STICKPLOT, DT, U, V (Eliminate this part if you're using
IDL)
;
; The best method for plotting vectors is to make a user-defined
; symbol for each vector that is plotted... This is the only way
; I have found to insure that the vectors' angle is preserved
; no matter how the plot is scaled...
;
; This procedure can be called in one of two ways:
; - for plotting a vector time-series, or
; - for plotting vectors in a 2-D plane
;
; Plotting Vector Time-Series:
; STICKPLOT, dates, u, v
; The 'dates' variable is an array of date/time structures, and
'u', 'v'
; are the two components of the vector. The horizontal axis will
be
; a standard PV-Wave date/time axis and my plans are to support
all
; options relating to these types of plots.
;
; Plotting Vector Fields:
; STICKPLOT, X, Y, U, V
;
; INPUTS:
; DT An array of Date/Time structures...
; X The X coordinate for the vectors' starting point.
; Y The Y coordinate for the vectors' starting point.
; U The U component of the vector (east/west).
; V The V component of the vector (north/south).
;
; KEYWORDS:
; Many of the standard plotting keywords are implemented in this
routine.
; The keywords that are currently implemented are:
; Symsize
; DT_Range
; XRange
; YRange
; Title
; XTitle
; YTitle
PRO STICKPLOT, X, Y, U, V, $
Symsize=mySymsize, $
DT_Range=myDT_Range, $
XRange=myXRange, $
YRange=myYRange, $
Title=myTitle, $
XTitle=myXTitle, $
YTitle=myYTitle
; Some keywords should just modify system variables.
; Old values are restored at the end of this routine...
IF KEYWORD_SET(myTitle) THEN BEGIN
oldTitle = !P.Title
!P.Title = myTitle
ENDIF
IF KEYWORD_SET(myXTitle) THEN BEGIN
oldXTitle = !X.Title
!X.Title = myXTitle
ENDIF
IF KEYWORD_SET(myYTitle) THEN BEGIN
oldYTitle = !Y.Title
!Y.Title = myYTitle
ENDIF
Nm1 = N_ELEMENTS(X)-1
IF NOT KEYWORD_SET(mySymsize) THEN mySymsize = 1.0
x_info = SIZE(X)
x_dims = x_info(0)
x_type = x_info( n_elements(x_info) - 2)
IF ( x_type EQ 8 ) THEN BEGIN
; The independent variable is a date/time structure...
IF (n_params() NE 3) THEN BEGIN
PRINT, 'stickplot error: need exactly 3 parameters when plotting
versus date/time.'
RETALL
ENDIF
IF NOT KEYWORD_SET(myDT_Range) THEN BEGIN
myDT_Range = [X(0).julian, X(Nm1).julian]
ENDIF
; Okay, this is going to be a vector diagram
; with a date/time horizontal axis...
; Need the magnitude for future scaling...
Mag = sqrt(Y*Y + U*U)
Xhat = Y / Mag
Yhat = U / Mag
; Create a little unit vector...
USERSYM, [0,Xhat(0)], [0,Yhat(0)]
PLOT, X(0), [0], $
XStyle=1, YRange=[-1,1], $
YTickLen=1.E-8, YTicks=2, YTickname = REPLICATE(' ',30), $
DT_Range=myDT_Range, $
Psym = 8, Symsize=Mag(0)*mySymsize
FOR i = 1,Nm1 DO BEGIN
USERSYM, [0,Xhat(i)], [0,Yhat(i)]
OPLOT, X(i), [0], $
Psym = 8, Symsize=Mag(i)*mySymsize
ENDFOR
ENDIF ELSE BEGIN
; The independent variable is an array of real numbers (doubles, or
integers)
IF (N_PARAMS() EQ 2) THEN BEGIN
IF NOT KEYWORD_SET(myXRange) THEN BEGIN
myXRange = [0, Nm1]
ENDIF
; This case handles
; STICKPLOT, X, Y
; where 'X', and 'Y' are the components of the vector...
Mag = sqrt(X*X + Y*Y)
Xhat = X / Mag
Yhat = Y / Mag
; Create a little unit vector...
USERSYM, [0,Xhat(0)], [0,Yhat(0)]
PLOT, [0], [0], $
XRange=myXRange, YRange=[-1,+1], $
YTickLen=1.E-8, YTicks=2, YTickname = REPLICATE(' ',30), $
Psym = 8, Symsize=Mag(0)*mySymsize
FOR i = 1,Nm1 DO BEGIN
USERSYM, [0,Xhat(i)], [0,Yhat(i)]
OPLOT, [i], [0], $
Psym = 8, Symsize=Mag(i)*mySymsize
ENDFOR
ENDIF ELSE IF (N_PARAMS() EQ 3) THEN BEGIN
; This case handles
; STICKPLOT, X, U, V
; where 'U', and 'V' are the components of the vector,
; and 'X' is the independent variable on the horizontal axis.
Mag = sqrt(Y*Y+U*U)
Xhat = Y / Mag
Yhat = U / Mag
IF NOT KEYWORD_SET(myXRange) THEN BEGIN
myXRange = [min(X), max(X)]
ENDIF
IF NOT KEYWORD_SET(myYRange) THEN BEGIN
myYRange = [-1, +1]
ENDIF
; Create a little unit vector...
USERSYM, [0,Xhat(0)], [0,Yhat(0)]
PLOT, [X(0)], [0], $
XRange=myXRange, YRange=myYRange, $
YTickLen=1.E-8, YTicks=2, YTickname = REPLICATE(' ',30), $
Psym = 8, Symsize=Mag(0)*mySymsize
FOR i = 1,Nm1 DO BEGIN
USERSYM, [0,Xhat(i)], [0,Yhat(i)]
OPLOT, [X(i)], [0], $
Psym = 8, Symsize=Mag(i)*mySymsize
ENDFOR
ENDIF ELSE IF (N_PARAMS() EQ 4) THEN BEGIN
Mag = sqrt(U*U + V*V)
IF NOT KEYWORD_SET(myXRange) THEN BEGIN
myXRange = [min(X), max(X)]
ENDIF
IF NOT KEYWORD_SET(myYRange) THEN BEGIN
myYRange = [min(Y), max(Y)]
ENDIF
; Create a little unit vector...
ang = atan(v(0), u(0))
Xtmp = [ 0, 0.8, 0.8, 1.0, 0.8, 0.8, 0 ]
Ytmp = [ 0, 0, 0.05, 0, -0.05, 0, 0 ]
Xhat = cos(ang) * Xtmp + sin(ang)*Ytmp
Yhat = cos(ang) * Ytmp - sin(ang)*Xtmp
USERSYM, Xhat, Yhat
PLOT, [X(0)], [Y(0)], $
XRange=myXRange, YRange=myYRange, $
Psym = 8, Symsize=Mag(0)*mySymsize
FOR i = 1,Nm1 DO BEGIN
ang = atan(v(i), u(i))
Xhat = cos(ang) * Xtmp + sin(ang)*Ytmp
Yhat = cos(ang) * Ytmp - sin(ang)*Xtmp
USERSYM, Xhat, Yhat
OPLOT, [X(i)], [Y(i)], $
Psym = 8, Symsize=Mag(i)*mySymsize
ENDFOR
ENDIF ELSE BEGIN
PRINT, 'stickplot error: incorrect number of parameters.'
RETALL
ENDELSE
ENDELSE
IF KEYWORD_SET(myTitle) THEN BEGIN
!P.Title = oldTitle
ENDIF
IF KEYWORD_SET(myXTitle) THEN BEGIN
!X.Title = oldXTitle
ENDIF
IF KEYWORD_SET(myYTitle) THEN BEGIN
!Y.Title = oldYTitle
ENDIF
RETURN
END
**** cut here ****
===
Randy Zagar E-Mail: zagar@udel.edu
Sr. Scientific Programmer E-Mail: zagar@newark.cms.udel.edu
College of Marine Studies Voice: (302) 831-1139
University of Delaware FAX: (302) 831-6838
Newark, DE 19716
|