pro slice2d, dat, rotation=rotation, angle=angle, thirddirlim=thirddirlim, xrange=xrange, range=range, erange=erange, units=units, nozlog=nozlog, position=position, nofill=nofill, nlines=nlines, noolines=noolines, numolines=numolines, removezero=removezero, showdata=showdata, vel=vel, nogrid=nogrid, nosmooth=nosmooth, sundir=sundir, novelline=novelline, subtract=subtract, resolution=resolution, isotropic=isotropic
if not keyword_set(units) then units = 'df'
if not keyword_set(rotation) then rotation = 'xy'
if not keyword_set(angle) then angle = [-20.,20.]
if not keyword_set(nlines) then nlines = 60
if not keyword_set(nozlog) then zlog = 1 else zlog = 0
if not keyword_set(nofill) then fill = 1 else fill = 0
if not keyword_set(resolution) then resolution = 51
if resolution mod 2 eq 0 then resolution = resolution + 1
if not keyword_set(numolines) then numolines = 20
if not keyword_set(position) then begin
x_size = !d.x_size & y_size = !d.y_size
xsize = .77
yoffset = 0.
d = 1.
if y_size le x_size then $
position = [.13*d+.05,.13*d+yoffset,.05+.13*d + xsize * y_size/x_size,.13*d + xsize + yoffset] else $
position = [.13*d+.05,.13*d+yoffset,.05+.13*d + xsize,.13*d + xsize *x_size/y_size + yoffset]
endif
if dat.valid ne 1 then begin
dprint, 'Not valid data!!!'
return
endif
dat2 = conv_units(dat,units)
bins_2d = fltarr(dat2.nenergy,dat2.nbins)
sizeokay = 0
if tag_exist(dat2,'bins') eq 1 then begin
checksize = size(dat2.bins)
if checksize[0] eq 2 then begin
if checksize[1] eq dat2.nenergy and checksize[2] eq dat2.nbins then begin
sizeokay = 1
endif
endif
endif
if sizeokay eq 1 then begin
bins_2d[*,*] = dat2.bins[*,*]
endif else begin
bins_2d[*,*] = 1.
dprint,'No BINS tag or the BINS size does not match (Nene, Nsangle)'
dprint,'All bins are used'
endelse
if not keyword_set(erange) then begin
erange = [ min(dat2.energy) , max(dat2.energy) ]
endif else begin
idx = where( dat2.energy[*,0] ge erange[0] $
and dat2.energy[*,0] le erange[1] , idx_cnt )
if idx_cnt gt 0 then begin
erange = [ min(dat2.energy[idx,0]) , max(dat2.energy[idx,0]) ]
endif else begin
dprint,'No data points in that energy range!!!'
return
endelse
endelse
if tag_exist(dat2,'mass') eq 1 then begin
mass = dat2.mass
endif else begin
dprint,'No mass info in the 3D data!!!'
dprint,'Add a mass tag to the structure by using, e.g., str_element'
dprint,'for electrons:'
dprint,"> str_element,dat, 'MASS', 5.6856591e-6, /add"
dprint,'for protons, mass is 1836*5.6856591e-6 eV/(km/sec)^2'
return
endelse
if rotation ne 'xy' and rotation ne 'xz' and rotation ne 'yz' then begin
if tag_exist(dat2,'magf') eq 1 then begin
bvec = dat2.magf
if total(bvec^2) ne 0 then begin
dprint,'Magntic field is taken from MAGF tag in the data structure'
dprint,'bvec =',bvec
endif else begin
dprint,'MAGF tag in the data structure is [0,0,0]!!!'
dprint,'Set a valid magnetic field vector'
return
endelse
endif else begin
dprint,'No MAGF tag in the data structure!!!'
dprint,'Add a valid MAGF tag by using, e.g., extract_tags'
return
endelse
endif
totalx = fltarr(1) & totaly = fltarr(1) & totalz = fltarr(1)
ncounts = fltarr(1)
for i=0,dat2.nenergy-1 do begin
currbins = where( bins_2d[i,*] ne 0 $
and dat2.energy[i,*] le erange[1] $
and dat2.energy[i,*] ge erange[0] $
and finite(dat2.data[i,*]) eq 1 , nbins )
if nbins gt 0 then begin
x = fltarr(nbins) & y = fltarr(nbins) & z = fltarr(nbins)
sphere_to_cart,1,reform(dat2.theta[i,currbins]),reform(dat2.phi[i,currbins]), x,y,z
totalx = [totalx, x * reform(sqrt(2*dat2.energy[i,currbins]/mass))]
totaly = [totaly, y * reform(sqrt(2*dat2.energy[i,currbins]/mass))]
totalz = [totalz, z * reform(sqrt(2*dat2.energy[i,currbins]/mass))]
ncounts = [ncounts, reform(dat2.data[i, currbins])]
endif
endfor
totalx = totalx[1:*]
totaly = totaly[1:*]
totalz = totalz[1:*]
ncounts = ncounts[1:*]
newdata = {v:fltarr(n_elements(totalx),3), n:fltarr(n_elements(totalx))}
newdata.v[*,0] = totalx
newdata.v[*,1] = totaly
newdata.v[*,2] = totalz
newdata.n = ncounts
if keyword_set(vel) then begin
vvec = vel
dprint,'Velocity used for subtraction/rotation is '+vel
endif else begin
vvec = v_3d(dat2)
dprint,'Velocity used for subtraction/rotation is V_3D',vvec
endelse
if not keyword_set(subtract) then begin
dprint, 'No velocity subtraction'
endif else begin
newdata.v[*,0] = newdata.v[*,0] - vvec[0]
newdata.v[*,1] = newdata.v[*,1] - vvec[1]
newdata.v[*,2] = newdata.v[*,2] - vvec[2]
endelse
if rotation eq 'BV' then rot = thm_cal_rot( bvec, vvec )
if rotation eq 'BE' then rot = thm_cal_rot( bvec, crossp(bvec,vvec) )
if rotation eq 'xy' then rot = thm_cal_rot( [1,0,0], [0,1,0] )
if rotation eq 'xz' then rot = thm_cal_rot( [1,0,0], [0,0,1] )
if rotation eq 'yz' then rot = thm_cal_rot( [0,1,0], [0,0,1] )
if rotation eq 'perp' then begin
rot = thm_cal_rot( crossp(crossp(bvec,vvec),bvec), crossp(bvec,vvec) )
endif
if rotation eq 'perp_xy' then begin
rot = thm_cal_rot( crossp(crossp(bvec,[1,0,0]),bvec), crossp(crossp(bvec,[0,1,0]),bvec) )
endif
if rotation eq 'perp_xz' then begin
rot = thm_cal_rot( crossp(crossp(bvec,[1,0,0]),bvec), crossp(crossp(bvec,[0,0,1]),bvec) )
endif
if rotation eq 'perp_yz' then begin
rot = thm_cal_rot( crossp(crossp(bvec,[0,1,0]),bvec), crossp(crossp(bvec,[0,0,1]),bvec) )
endif
newdata.v = newdata.v # rot
vvec = vvec # rot
if keyword_set(sundir) then begin
sundir = sundir # rot
if sundir[1] ne 0 then $
ysun = sqrt( sundir[1]^2 + sundir[2]^2 )*sundir[1]/abs(sundir[1]) $
else ysun = 0.
xsun = sundir[0]
endif
xplot = newdata.v[*,0]
yplot = newdata.v[*,1]
zplot = newdata.v[*,2]
cntplot = newdata.n
if keyword_set(ThirdDirlim) then angle = [-90.,90.]
r = sqrt( xplot^2 + yplot^2 + zplot^2 )
eachangle = asin( zplot/r )
angle1 = min(angle)
angle2 = max(angle)
idx = where( eachangle*!radeg ge angle1 $
and eachangle*!radeg le angle2 , idx_cnt )
if idx_cnt gt 0 then begin
xplot = xplot[idx]
yplot = yplot[idx]
zplot = zplot[idx]
cntplot = cntplot[idx]
endif else begin
dprint,'No data points at that angle!!!'
return
endelse
if keyword_set(ThirdDirlim) then begin
idx = where( zplot ge min(ThirdDirLim) and zplot le max(ThirdDirLim) , idx_cnt )
if idx_cnt gt 0 then begin
xplot = xplot[idx]
yplot = yplot[idx]
zplot = zplot[idx]
cntplot = cntplot[idx]
endif else begin
dprint,'No data points at that third direction limit!!!'
return
endelse
endif
idx = where( cntplot ge 0 , idx_cnt )
if idx_cnt gt 0 then begin
xplot = xplot[idx]
yplot = yplot[idx]
zplot = zplot[idx]
cntplot = cntplot[idx]
endif else begin
dprint,'There are no data values >= 0!!!'
return
endelse
if keyword_set(removezero) then begin
idx = where( cntplot ne 0 , idx_cnt )
if idx_cnt gt 0 then begin
xplot = xplot[idx]
yplot = yplot[idx]
zplot = zplot[idx]
cntplot = cntplot[idx]
endif else begin
dprint,'There are only zero data values'
endelse
endif
yplot = yplot(sort(xplot))
cntplot = cntplot(sort(xplot))
xplot = xplot(sort(xplot))
uni2 = uniq(xplot)
uni1 = [ 0, uni2[0:n_elements(uni2)-2]+1 ]
kk = 0
for i=0,n_elements(uni2)-1 do begin
xploti = xplot[ uni1[i]:uni2[i] ]
yploti = yplot[ uni1[i]:uni2[i] ]
cntploti = cntplot[ uni1[i]:uni2[i] ]
xploti = xploti[ sort(yploti) ]
cntploti = cntploti[ sort(yploti) ]
yploti = yploti[ sort(yploti) ]
idx2 = uniq(yploti)
if n_elements(idx2) eq 1 then begin
idx1 = 0
endif else begin
idx1 = [ 0, idx2[0:n_elements(idx2)-2]+1 ]
endelse
for j=0,n_elements(idx2)-1 do begin
yplot[kk] = yploti[idx1[j]]
xplot[kk] = xploti[idx1[j]]
if idx1[j] eq idx2[j] then begin
cntplot[kk] = cntploti[idx1[j]]
endif else begin
cnt_mom = moment( cntploti[ idx1[j]:idx2[j] ] )
cntplot[kk] = cnt_mom[0]
endelse
kk = kk +1
endfor
endfor
xplot = xplot[0:kk-1]
yplot = yplot[0:kk-1]
cntplot = cntplot[0:kk-1]
if not keyword_set(xrange) then begin
xmax = max(abs([xplot,yplot]))
xrange = [ -1*xmax, xmax ]
endif else xmax = max(abs(xrange))
if not keyword_set(range) then begin
if not keyword_set(xrange) then begin
cntmax = max(cntplot)
cntmin = min(cntplot)
if cntmax ne 0 and cntmin eq 0 then $
cntmin = min( cntplot[where(cntplot ne 0)] )
endif else begin
cntmax = max(cntplot[ where( abs(xplot) le xmax and abs(yplot) le xmax ) ])
cntmin = min(cntplot[ where( abs(xplot) le xmax and abs(yplot) le xmax ) ])
if cntmax ne 0 and cntmin eq 0 then $
cntmin = min( cntplot[where( cntplot ne 0 and abs(xplot) le xmax and abs(yplot) le xmax )] )
endelse
endif else begin
cntmin = min(range)
cntmax = max(range)
endelse
if keyword_set(nozlog) then begin
levels = indgen(nlines)/float(nlines)*(cmtmax-cntmin) + cntmin
endif else begin
levels = 10.^( indgen(nlines)/float(nlines)*(alog10(cntmax)-alog10(cntmin)) + alog10(cntmin) )
endelse
if not keyword_set(noolines) then begin
if keyword_set(nozlog) then begin
levels2 = indgen(numolines)/float(numolines)*(cmtmax-cntmin) + cntmin
endif else begin
levels2 = 10.^( indgen(numolines)/float(numolines)*(alog10(cntmax)-alog10(cntmin)) + alog10(cntmin) )
endelse
endif
colors = round( (indgen(nlines)+1)*(!d.table_size-9)/nlines ) + 7
if rotation eq 'BV' then begin
xtitle = 'v_para [km/s]'
ytitle = 'v_perp_V [km/s]'
endif
if rotation eq 'BE' then begin
xtitle = 'v_para [km/s]'
ytitle = 'v_perp_E [km/s]'
endif
if rotation eq 'xy' then begin
xtitle = 'v_x [km/s]'
ytitle = 'v_y [km/s]'
endif
if rotation eq 'xz' then begin
xtitle = 'v_x [km/s]'
ytitle = 'v_z [km/s]'
endif
if rotation eq 'yz' then begin
xtitle = 'v_y [km/s]'
ytitle = 'v_z [km/s]'
endif
if rotation eq 'perp' then begin
xtitle = 'v_perp_V [km/s]'
ytitle = 'v_perp_E [km/s]'
endif
if rotation eq 'perp_xy' then begin
xtitle = 'v_perp_x [km/s]'
ytitle = 'v_perp_y [km/s]'
endif
if rotation eq 'perp_xz' then begin
xtitle = 'v_perp_x [km/s]'
ytitle = 'v_perp_z [km/s]'
endif
if rotation eq 'perp_yz' then begin
xtitle = 'v_perp_y [km/s]'
ytitle = 'v_perp_z [km/s]'
endif
title = dat2.data_name+' '+time_string(dat2.time) $
+'->'+strmid(time_string(dat2.end_time),11,8)
if not keyword_set(nogrid) then begin
spacing = (xrange[1]-xrange[0])/(resolution-1)
triangulate, xplot, yplot, tr, b
idx = where( ( xplot[tr[0,*]] + xplot[tr[1,*]] + xplot[tr[2,*]] )^2 $
+ ( yplot[tr[0,*]] + yplot[tr[1,*]] + yplot[tr[2,*]] )^2 $
gt min( xplot^2 + yplot^2 ) , idx_cnt )
if idx_cnt gt 0 then tr = tr[*,idx]
surf = trigrid( xplot, yplot, cntplot, tr, [spacing,spacing], $
[ xrange[0], xrange[0], xrange[1], xrange[1] ], $
xgrid=xg, ygrid=yg )
if not keyword_set(nosmooth) then surf = smooth(surf,3)
if n_elements(xg) mod 2 ne 1 then $
dprint, 'The line plots are invalid', n_elements(xg)
contour,surf,xg,yg, $
/closed, levels=levels, c_color=colors, fill=fill, $
ticklen=-0.01, isotropic=isotropic, $
xstyle=1, xrange=xrange, xtitle=xtitle,$
ystyle=1, yrange=xrange, ytitle=ytitle, $
title=title, position=position
if not keyword_set(noolines) then begin
contour,surf,xg,yg, $
/closed, /noerase, levels=levels2, $
ticklen=0, isotropic=isotropic, color=0, $
xstyle=5, xrange=xrange,$
ystyle=5, yrange=xrange, position=position
endif
endif else begin
contour,cntplot,xplot,yplot, /irregular, $
/closed, levels=levels, c_color=colors, fill=fill, $
ticklen=-0.01, isotropic=isotropic, $
xstyle=1, xrange=xrange, xtitle=xtitle,$
ystyle=1, yrange=xrange, ytitle=ytitle, $
title=title, position=position
if not keyword_set(noolines) then begin
contour,cntplot,xplot,yplot, /irregular, $
/closed, /noerase, levels=levels2, $
ticklen=0, isotropic=isotropic, color=0, $
xstyle=5, xrange=xrange,$
ystyle=5, yrange=xrange, position=position
endif
endelse
if keyword_set(sundir) then oplot,[0,xsun*max(xrange)],[0,ysun*max(xrange)]
if not keyword_set(subtract) then begin
if not keyword_set(novelline) then oplot,[0,vvec[0]],[0,vvec[1]],col= !d.table_size-9
circx = cos(findgen(361)*!dtor)*sqrt(2.*erange[0]/mass)
circy = sin(findgen(361)*!dtor)*sqrt(2.*erange[0]/mass)
oplot,circx,circy,thick=2
circx = cos(findgen(361)*!dtor)*sqrt(2.*erange[1]/mass)
circy = sin(findgen(361)*!dtor)*sqrt(2.*erange[1]/mass)
oplot,circx,circy,thick=2
endif
draw_color_scale, range=[cntmin,cntmax], log=zlog, yticks=10, title =units_string(dat2.units_name)
if keyword_set(showdata) then oplot,xplot,yplot,psym=1
end