pro thm_load_esa_pot,sc=sc,probe=probe,themishome=themishome,datatype=datatype,efi_datatype=efi_datatype,pot_scale=pot_scale,offset=offset,min_pot=min_pot,make_plot=make_plot,trange=trange,min_pot_trange=min_pot_trange, use_vaf_offset=use_vaf_offset
if ~undefined(datatype) && undefined(efi_datatype) then begin
dprint,'Warning: "datatype" keyword being deprecated. Use "efi_datatype" keyword in the future'
efi_datatype = datatype
endif
thm_init
boom_deploy_time=time_double(['08-01-13','07-11-21','07-05-15','07-06-06','07-06-06'])
mom_pot_adjust=dblarr(5,3)
mom_pot_adjust[*,0]=time_double(['07-11-17/19:03:49','07-11-18/03:12:17','07-11-18/07:12:01','07-11-18/00:02:15','07-11-18/01:55:32'])
mom_pot_adjust[*,1]=time_double(['08-09-10/16:00:00','08-10-10/23:00:00','08-02-05/06:00:00','08-09-06/17:00:00','08-04-04/23:00:00'])
mom_pot_adjust[*,2]=time_double(['09-06-04/20:17:45','09-06-08/21:51:00','09-06-09/22:48:00','09-06-08/21:25:00','09-06-08/22:57:00'])
mom_tim_adjust=time_double(['07-11-29/20:51:26','07-12-03/18:43:24','07-12-03/18:23:03','07-11-27/18:34:23','07-11-29/17:49:10'])
tshft_mom=[1.6028,0.667]
probe_order=['a','b','c','d','e','f']
if keyword_set(probe) then sc=probe
if not keyword_set(sc) then begin
dprint, 'S/C number not set, default = all probes'
sc=['a','b','c','d','e']
endif
if not keyword_set(themishome) then themishome=!themis.local_data_dir
nsc = n_elements(sc)
probes=strarr(1)
if nsc eq 1 then probes[0]=sc
if nsc ne 1 then probes=sc
isc = intarr(nsc)
for i=0,nsc-1 do isc[i]=where(probes(i) eq probe_order)
def_scale = 1.15
def_offset = 1.0
def_min_pot = 1.0
if not keyword_set(min_pot) then min_pot=def_min_pot
if not keyword_set(pot_scale) then scale=def_scale else scale=pot_scale
if not keyword_set(offset) then offset=def_offset
if keyword_set(min_pot_trange) then begin
if n_elements(min_pot_trange) ne 2 then begin
dprint, 'min_pot_trange keyword must be 2 element array'
return
endif
tr2=time_double(min_pot_trange)
if tr2[0] gt tr2[1] then tr2=reverse(tr2)
for i=0,nsc-1 do begin
if probes[i] eq 'a' then begin
common tha_454,tha_454_ind,tha_454_dat
if size(/type, tha_454_dat) eq 8 then begin
ind=where(tha_454_dat.time ge tr2[0] and tha_454_dat.time le tr2[1])
if ind[0] ne -1 then tha_454_dat.sc_pot[ind]=min_pot
store_data,'tha_peif_sc_pot',data={x:(tha_454_dat.time+tha_454_dat.end_time)/2.,y:tha_454_dat.sc_pot}
endif
common tha_455,tha_455_ind,tha_455_dat
if size(/type, tha_455_dat) eq 8 then begin
ind=where(tha_455_dat.time ge tr2[0] and tha_455_dat.time le tr2[1])
if ind[0] ne -1 then tha_455_dat.sc_pot[ind]=min_pot
store_data,'tha_peir_sc_pot',data={x:(tha_455_dat.time+tha_455_dat.end_time)/2.,y:tha_455_dat.sc_pot}
endif
common tha_456,tha_456_ind,tha_456_dat
if size(/type, tha_456_dat) eq 8 then begin
ind=where(tha_456_dat.time ge tr2[0] and tha_456_dat.time le tr2[1])
if ind[0] ne -1 then tha_456_dat.sc_pot[ind]=min_pot
store_data,'tha_peib_sc_pot',data={x:(tha_456_dat.time+tha_456_dat.end_time)/2.,y:tha_456_dat.sc_pot}
endif
common tha_457,tha_457_ind,tha_457_dat
if size(/type, tha_457_dat) eq 8 then begin
ind=where(tha_457_dat.time ge tr2[0] and tha_457_dat.time le tr2[1])
if ind[0] ne -1 then tha_457_dat.sc_pot[ind]=min_pot
store_data,'tha_peef_sc_pot',data={x:(tha_457_dat.time+tha_457_dat.end_time)/2.,y:tha_457_dat.sc_pot}
endif
common tha_458,tha_458_ind,tha_458_dat
if size(/type, tha_458_dat) eq 8 then begin
ind=where(tha_458_dat.time ge tr2[0] and tha_458_dat.time le tr2[1])
if ind[0] ne -1 then tha_458_dat.sc_pot[ind]=min_pot
store_data,'tha_peer_sc_pot',data={x:(tha_458_dat.time+tha_458_dat.end_time)/2.,y:tha_458_dat.sc_pot}
endif
common tha_459,tha_459_ind,tha_459_dat
if size(/type, tha_459_dat) eq 8 then begin
ind=where(tha_459_dat.time ge tr2[0] and tha_459_dat.time le tr2[1])
if ind[0] ne -1 then tha_459_dat.sc_pot[ind]=min_pot
store_data,'tha_peeb_sc_pot',data={x:(tha_459_dat.time+tha_459_dat.end_time)/2.,y:tha_459_dat.sc_pot}
endif
endif else if probes[i] eq 'b' then begin
common thb_454,thb_454_ind,thb_454_dat
if size(/type, thb_454_dat) eq 8 then begin
ind=where(thb_454_dat.time ge tr2[0] and thb_454_dat.time le tr2[1])
if ind[0] ne -1 then thb_454_dat.sc_pot[ind]=min_pot
store_data,'thb_peif_sc_pot',data={x:(thb_454_dat.time+thb_454_dat.end_time)/2.,y:thb_454_dat.sc_pot}
endif
common thb_455,thb_455_ind,thb_455_dat
if size(/type, thb_455_dat) eq 8 then begin
ind=where(thb_455_dat.time ge tr2[0] and thb_455_dat.time le tr2[1])
if ind[0] ne -1 then thb_455_dat.sc_pot[ind]=min_pot
store_data,'thb_peir_sc_pot',data={x:(thb_455_dat.time+thb_455_dat.end_time)/2.,y:thb_455_dat.sc_pot}
endif
common thb_456,thb_456_ind,thb_456_dat
if size(/type, thb_456_dat) eq 8 then begin
ind=where(thb_456_dat.time ge tr2[0] and thb_456_dat.time le tr2[1])
if ind[0] ne -1 then thb_456_dat.sc_pot[ind]=min_pot
store_data,'thb_peib_sc_pot',data={x:(thb_456_dat.time+thb_456_dat.end_time)/2.,y:thb_456_dat.sc_pot}
endif
common thb_457,thb_457_ind,thb_457_dat
if size(/type, thb_457_dat) eq 8 then begin
ind=where(thb_457_dat.time ge tr2[0] and thb_457_dat.time le tr2[1])
if ind[0] ne -1 then thb_457_dat.sc_pot[ind]=min_pot
store_data,'thb_peef_sc_pot',data={x:(thb_457_dat.time+thb_457_dat.end_time)/2.,y:thb_457_dat.sc_pot}
endif
common thb_458,thb_458_ind,thb_458_dat
if size(/type, thb_458_dat) eq 8 then begin
ind=where(thb_458_dat.time ge tr2[0] and thb_458_dat.time le tr2[1])
if ind[0] ne -1 then thb_458_dat.sc_pot[ind]=min_pot
store_data,'thb_peer_sc_pot',data={x:(thb_458_dat.time+thb_458_dat.end_time)/2.,y:thb_458_dat.sc_pot}
endif
common thb_459,thb_459_ind,thb_459_dat
if size(/type, thb_459_dat) eq 8 then begin
ind=where(thb_459_dat.time ge tr2[0] and thb_459_dat.time le tr2[1])
if ind[0] ne -1 then thb_459_dat.sc_pot[ind]=min_pot
store_data,'thb_peeb_sc_pot',data={x:(thb_459_dat.time+thb_459_dat.end_time)/2.,y:thb_459_dat.sc_pot}
endif
endif else if probes[i] eq 'c' then begin
common thc_454,thc_454_ind,thc_454_dat
if size(/type, thc_454_dat) eq 8 then begin
ind=where(thc_454_dat.time ge tr2[0] and thc_454_dat.time le tr2[1])
if ind[0] ne -1 then thc_454_dat.sc_pot[ind]=min_pot
store_data,'thc_peif_sc_pot',data={x:(thc_454_dat.time+thc_454_dat.end_time)/2.,y:thc_454_dat.sc_pot}
endif
common thc_455,thc_455_ind,thc_455_dat
if size(/type, thc_455_dat) eq 8 then begin
ind=where(thc_455_dat.time ge tr2[0] and thc_455_dat.time le tr2[1])
if ind[0] ne -1 then thc_455_dat.sc_pot[ind]=min_pot
store_data,'thc_peir_sc_pot',data={x:(thc_455_dat.time+thc_455_dat.end_time)/2.,y:thc_455_dat.sc_pot}
endif
common thc_456,thc_456_ind,thc_456_dat
if size(/type, thc_456_dat) eq 8 then begin
ind=where(thc_456_dat.time ge tr2[0] and thc_456_dat.time le tr2[1])
if ind[0] ne -1 then thc_456_dat.sc_pot[ind]=min_pot
store_data,'thc_peib_sc_pot',data={x:(thc_456_dat.time+thc_456_dat.end_time)/2.,y:thc_456_dat.sc_pot}
endif
common thc_457,thc_457_ind,thc_457_dat
if size(/type, thc_457_dat) eq 8 then begin
ind=where(thc_457_dat.time ge tr2[0] and thc_457_dat.time le tr2[1])
if ind[0] ne -1 then thc_457_dat.sc_pot[ind]=min_pot
store_data,'thc_peef_sc_pot',data={x:(thc_457_dat.time+thc_457_dat.end_time)/2.,y:thc_457_dat.sc_pot}
endif
common thc_458,thc_458_ind,thc_458_dat
if size(/type, thc_458_dat) eq 8 then begin
ind=where(thc_458_dat.time ge tr2[0] and thc_458_dat.time le tr2[1])
if ind[0] ne -1 then thc_458_dat.sc_pot[ind]=min_pot
store_data,'thc_peer_sc_pot',data={x:(thc_458_dat.time+thc_458_dat.end_time)/2.,y:thc_458_dat.sc_pot}
endif
common thc_459,thc_459_ind,thc_459_dat
if size(/type, thc_459_dat) eq 8 then begin
ind=where(thc_459_dat.time ge tr2[0] and thc_459_dat.time le tr2[1])
if ind[0] ne -1 then thc_459_dat.sc_pot[ind]=min_pot
store_data,'thc_peeb_sc_pot',data={x:(thc_459_dat.time+thc_459_dat.end_time)/2.,y:thc_459_dat.sc_pot}
endif
endif else if probes[i] eq 'd' then begin
common thd_454,thd_454_ind,thd_454_dat
if size(/type, thd_454_dat) eq 8 then begin
ind=where(thd_454_dat.time ge tr2[0] and thd_454_dat.time le tr2[1])
if ind[0] ne -1 then thd_454_dat.sc_pot[ind]=min_pot
store_data,'thd_peif_sc_pot',data={x:(thd_454_dat.time+thd_454_dat.end_time)/2.,y:thd_454_dat.sc_pot}
endif
common thd_455,thd_455_ind,thd_455_dat
if size(/type, thd_455_dat) eq 8 then begin
ind=where(thd_455_dat.time ge tr2[0] and thd_455_dat.time le tr2[1])
if ind[0] ne -1 then thd_455_dat.sc_pot[ind]=min_pot
store_data,'thd_peir_sc_pot',data={x:(thd_455_dat.time+thd_455_dat.end_time)/2.,y:thd_455_dat.sc_pot}
endif
common thd_456,thd_456_ind,thd_456_dat
if size(/type, thd_456_dat) eq 8 then begin
ind=where(thd_456_dat.time ge tr2[0] and thd_456_dat.time le tr2[1])
if ind[0] ne -1 then thd_456_dat.sc_pot[ind]=min_pot
store_data,'thd_peib_sc_pot',data={x:(thd_456_dat.time+thd_456_dat.end_time)/2.,y:thd_456_dat.sc_pot}
endif
common thd_457,thd_457_ind,thd_457_dat
if size(/type, thd_457_dat) eq 8 then begin
ind=where(thd_457_dat.time ge tr2[0] and thd_457_dat.time le tr2[1])
if ind[0] ne -1 then thd_457_dat.sc_pot[ind]=min_pot
store_data,'thd_peef_sc_pot',data={x:(thd_457_dat.time+thd_457_dat.end_time)/2.,y:thd_457_dat.sc_pot}
endif
common thd_458,thd_458_ind,thd_458_dat
if size(/type, thd_458_dat) eq 8 then begin
ind=where(thd_458_dat.time ge tr2[0] and thd_458_dat.time le tr2[1])
if ind[0] ne -1 then thd_458_dat.sc_pot[ind]=min_pot
store_data,'thd_peer_sc_pot',data={x:(thd_458_dat.time+thd_458_dat.end_time)/2.,y:thd_458_dat.sc_pot}
endif
common thd_459,thd_459_ind,thd_459_dat
if size(/type, thd_459_dat) eq 8 then begin
ind=where(thd_459_dat.time ge tr2[0] and thd_459_dat.time le tr2[1])
if ind[0] ne -1 then thd_459_dat.sc_pot[ind]=min_pot
store_data,'thd_peeb_sc_pot',data={x:(thd_459_dat.time+thd_459_dat.end_time)/2.,y:thd_459_dat.sc_pot}
endif
endif else if probes[i] eq 'e' then begin
common the_454,the_454_ind,the_454_dat
if size(/type, the_454_dat) eq 8 then begin
ind=where(the_454_dat.time ge tr2[0] and the_454_dat.time le tr2[1])
if ind[0] ne -1 then the_454_dat.sc_pot[ind]=min_pot
store_data,'the_peif_sc_pot',data={x:(the_454_dat.time+the_454_dat.end_time)/2.,y:the_454_dat.sc_pot}
endif
common the_455,the_455_ind,the_455_dat
if size(/type, the_455_dat) eq 8 then begin
ind=where(the_455_dat.time ge tr2[0] and the_455_dat.time le tr2[1])
if ind[0] ne -1 then the_455_dat.sc_pot[ind]=min_pot
store_data,'the_peir_sc_pot',data={x:(the_455_dat.time+the_455_dat.end_time)/2.,y:the_455_dat.sc_pot}
endif
common the_456,the_456_ind,the_456_dat
if size(/type, the_456_dat) eq 8 then begin
ind=where(the_456_dat.time ge tr2[0] and the_456_dat.time le tr2[1])
if ind[0] ne -1 then the_456_dat.sc_pot[ind]=min_pot
store_data,'the_peib_sc_pot',data={x:(the_456_dat.time+the_456_dat.end_time)/2.,y:the_456_dat.sc_pot}
endif
common the_457,the_457_ind,the_457_dat
if size(/type, the_457_dat) eq 8 then begin
ind=where(the_457_dat.time ge tr2[0] and the_457_dat.time le tr2[1])
if ind[0] ne -1 then the_457_dat.sc_pot[ind]=min_pot
store_data,'the_peef_sc_pot',data={x:(the_457_dat.time+the_457_dat.end_time)/2.,y:the_457_dat.sc_pot}
endif
common the_458,the_458_ind,the_458_dat
if size(/type, the_458_dat) eq 8 then begin
ind=where(the_458_dat.time ge tr2[0] and the_458_dat.time le tr2[1])
if ind[0] ne -1 then the_458_dat.sc_pot[ind]=min_pot
store_data,'the_peer_sc_pot',data={x:(the_458_dat.time+the_458_dat.end_time)/2.,y:the_458_dat.sc_pot}
endif
common the_459,the_459_ind,the_459_dat
if size(/type, the_459_dat) eq 8 then begin
ind=where(the_459_dat.time ge tr2[0] and the_459_dat.time le tr2[1])
if ind[0] ne -1 then the_459_dat.sc_pot[ind]=min_pot
store_data,'the_peeb_sc_pot',data={x:(the_459_dat.time+the_459_dat.end_time)/2.,y:the_459_dat.sc_pot}
endif
endif else if probes[i] eq 'f' then begin
common thf_454,thf_454_ind,thf_454_dat
if size(/type, thf_454_dat) eq 8 then begin
ind=where(thf_454_dat.time ge tr2[0] and thf_454_dat.time le tr2[1])
if ind[0] ne -1 then thf_454_dat.sc_pot[ind]=min_pot
store_data,'thf_peif_sc_pot',data={x:(thf_454_dat.time+thf_454_dat.end_time)/2.,y:thf_454_dat.sc_pot}
endif
common thf_455,thf_455_ind,thf_455_dat
if size(/type, thf_455_dat) eq 8 then begin
ind=where(thf_455_dat.time ge tr2[0] and thf_455_dat.time le tr2[1])
if ind[0] ne -1 then thf_455_dat.sc_pot[ind]=min_pot
store_data,'thf_peir_sc_pot',data={x:(thf_455_dat.time+thf_455_dat.end_time)/2.,y:thf_455_dat.sc_pot}
endif
common thf_456,thf_456_ind,thf_456_dat
if size(/type, thf_456_dat) eq 8 then begin
ind=where(thf_456_dat.time ge tr2[0] and thf_456_dat.time le tr2[1])
if ind[0] ne -1 then thf_456_dat.sc_pot[ind]=min_pot
store_data,'thf_peib_sc_pot',data={x:(thf_456_dat.time+thf_456_dat.end_time)/2.,y:thf_456_dat.sc_pot}
endif
common thf_457,thf_457_ind,thf_457_dat
if size(/type, thf_457_dat) eq 8 then begin
ind=where(thf_457_dat.time ge tr2[0] and thf_457_dat.time le tr2[1])
if ind[0] ne -1 then thf_457_dat.sc_pot[ind]=min_pot
store_data,'thf_peef_sc_pot',data={x:(thf_457_dat.time+thf_457_dat.end_time)/2.,y:thf_457_dat.sc_pot}
endif
common thf_458,thf_458_ind,thf_458_dat
if size(/type, thf_458_dat) eq 8 then begin
ind=where(thf_458_dat.time ge tr2[0] and thf_458_dat.time le tr2[1])
if ind[0] ne -1 then thf_458_dat.sc_pot[ind]=min_pot
store_data,'thf_peer_sc_pot',data={x:(thf_458_dat.time+thf_458_dat.end_time)/2.,y:thf_458_dat.sc_pot}
endif
common thf_459,thf_459_ind,thf_459_dat
if size(/type, thf_459_dat) eq 8 then begin
ind=where(thf_459_dat.time ge tr2[0] and thf_459_dat.time le tr2[1])
if ind[0] ne -1 then thf_459_dat.sc_pot[ind]=min_pot
store_data,'thf_peeb_sc_pot',data={x:(thf_459_dat.time+thf_459_dat.end_time)/2.,y:thf_459_dat.sc_pot}
endif
endif
endfor
endif else begin
for i=0,nsc-1 do begin
if probes[i] ne 'f' then begin
scpot=[-offset,-offset]
if keyword_set(trange) then begin
if n_elements(trange) ne 2 then begin
dprint, dlevel=0, 'Trange keyword must be two-element array.'
return
endif
time = time_double(trange)
endif else begin
time = timerange()
endelse
if time[1] le boom_deploy_time[isc[i]] then begin
if keyword_set(min_pot) then min_pot2=min_pot else min_pot2=0.
scpot=[min_pot2,min_pot2]
store_data,'th'+probes[i]+'_esa_pot',data={x:time,y:scpot}
dprint, 'Booms not deployed, loading sc_pot=min_pot'
endif else if not keyword_set(efi_datatype) then begin
thm_load_mom,probe=probes[i], trange=trange
get_data,'th'+probes[i]+'_pxxm_pot',data=tmp,index=index
if index ne 0 then begin
npts=n_elements(tmp.x)
if tmp.x[npts-1] lt mom_pot_adjust[isc[i],0] then begin
endif else if tmp.x[npts-1] lt mom_pot_adjust[isc[i],1] then begin
ind=where(tmp.x gt mom_pot_adjust[isc[i],0],count)
if count gt 0 then tmp.y[ind]=(tmp.y[ind]-1.215)/1.15
endif else if tmp.x[npts-1] lt mom_pot_adjust[isc[i],2] then begin
ind=where(tmp.x lt mom_pot_adjust[isc[i],1],count)
if count gt 0 then tmp.y[ind]=(tmp.y[ind]-1.215)/1.15
ind=where(tmp.x gt mom_pot_adjust[isc[i],1],count)
if count gt 0 then tmp.y[ind]=(tmp.y[ind]-1.215)
endif else begin
ind=where(tmp.x lt mom_pot_adjust[isc[i],2],count)
if count gt 0 then tmp.y[ind]=(tmp.y[ind]-1.215)
ind=where(tmp.x gt mom_pot_adjust[isc[i],2],count)
if count gt 0 then tmp.y[ind]=(tmp.y[ind]-1.215)/1.15
endelse
get_data,'th'+probes[i]+'_state_spinper',data=spinper
if not keyword_set(spinper) then begin
thm_load_state,/get_support_data,probe=probes[i], trange=trange
get_data,'th'+probes[i]+'_state_spinper',data=spinper
if not keyword_set(spinper) then begin
dprint, 'No state data available for probe ',probes[i]
dprint, 'Using default 3 sec spin period'
spin_period=replicate(3.,n_elements(tmp.x))
endif else spin_period = interp(spinper.y,spinper.x,tmp.x)
endif else spin_period = interp(spinper.y,spinper.x,tmp.x)
if tmp.x[0] ge mom_tim_adjust[isc[i]] then time=tmp.x-tshft_mom[1]*spin_period else $
if tmp.x[npts-1] le mom_tim_adjust[isc[i]] then time=tmp.x-tshft_mom[0]*spin_period else begin
min_tim=min(abs(tmp.x-mom_tim_adjust[isc[i]]),ind)
if tmp.x[ind] gt mom_tim_adjust[isc[i]] then ind=ind-1
time=tmp.x
time[0:ind]=time[0:ind]-tshft_mom[0]*spin_period[0:ind]
time[ind+1:npts-1]=time[ind+1:npts-1]-tshft_mom[1]*spin_period[ind+1:npts-1]
endelse
scpot=tmp.y
endif else begin
dprint, 'No moment data available for probe ',probes[i]
endelse
if index eq 0 then begin
get_data,'th'+probes[i]+'_state_spinper',data=spinper
if not keyword_set(spinper) then begin
thm_load_state,/get_support_data,probe=probes[i], trange=trange
get_data,'th'+probes[i]+'_state_spinper',data=spinper
if not keyword_set(spinper) then begin
dprint, 'No state data available for probe ',probes[i]
dprint, 'Using default 3 sec spin period'
spin_period=3.
npts=1
endif else begin
spin_period = spinper.y
npts=n_elements(spinper.x)
endelse
endif else begin
spin_period = spinper.y
npts=n_elements(spinper.x)
endelse
endif
avg_spin_period=total(spin_period)/npts
thm_load_efi,probe=probes[i],datatype='vaf',level=1, trange=trange
get_data,'th'+probes[i]+'_vaf',data=tmp1,index=index2
if index2 ne 0 then begin
bad_frac=1.05
vaf1 = -1.*reform(tmp1.y[*,0])
vaf2 = -1.*reform(tmp1.y[*,1])
vaf3 = -1.*reform(tmp1.y[*,2])
vaf4 = -1.*reform(tmp1.y[*,3])
ok_pts = where(3.*vaf1/(vaf2+vaf3+vaf4) Lt bad_frac And 3.*vaf2/(vaf1+vaf3+vaf4) Lt bad_frac And $
3.*vaf3/(vaf4+vaf1+vaf2) Lt bad_frac And 3.*vaf4/(vaf3+vaf1+vaf2) Lt bad_frac, nok)
dprint, 'Ok point count = ', nok, ' of total =', n_elements(vaf1)
If(nok Gt 0) then Begin
vaf1234 = (vaf1[ok_pts]+vaf2[ok_pts]+vaf3[ok_pts]+vaf4[ok_Pts])/4.0
t1234 = tmp1.x[ok_pts]
Endif Else Begin
dprint, 'No good VAF data'
vaf1234 = vaf1 & vaf1234[*] = min_pot
t1234 = tmp1.x
Endelse
vaf1234_3s=smooth_in_time(vaf1234, t1234, avg_spin_period)
if keyword_set(make_plot) then store_data,'th'+sc+'_vaf1234_3s_pot',data={x:t1234,y:vaf1234_3s}
if keyword_set(make_plot) then store_data,'th'+sc+'_mom_pot',data={x:time,y:scpot}
if index ne 0 then begin
t3 = [time, t1234]
d3 = [scpot, vaf1234_3s]
source3 = [1+bytarr(n_elements(time)), bytarr(n_elements(t1234))]
s = bsort(t3)
time = t3[s]
scpot = d3[s]
source = source3[s]
nsource = n_elements(source)
If(nsource Gt 3) Then Begin
keep = bytarr(nsource)+1
s1 = where(source Eq 1, ns1)
If(keyword_set(use_vaf_offset)) Then nvaf_offset = 0
For j = 0, ns1-1 Do Begin
s1j = s1[j]
If(s1j Eq 0) Then Begin
If(source[s1j+1] Eq 0 && (time[s1j+1]-time[s1j]) Lt 120.0) Then keep[s1j] = 0b
Endif Else If(s1j Eq nsource-1) Then begin
If(source[s1j-1] Eq 0 && (time[s1j]-time[s1j-1]) Lt 120.0) Then keep[s1j] = 0b
Endif Else Begin
If(source[s1j+1] Eq 0 && source[s1j-1] Eq 0 && $
(time[s1j+1]-time[s1j]) Lt 120.0 && (time[s1j]-time[s1j-1]) Lt 120.0) Then Begin
keep[s1j] = 0b
If(keyword_set(use_vaf_offset)) Then Begin
aa = (time[s1j]-time[s1j-1])/(time[s1j+1]-time[s1j-1])
scp_test = scpot[s1j-1]*(1.0-aa)+scpot[s1j+1]*aa-scpot[s1j]
If(nvaf_offset Eq 0) Then Begin
vaf_offset = scp_test
tvaf_offset = time[s1j]
Endif Else Begin
vaf_offset = [vaf_offset, scp_test]
tvaf_offset = [tvaf_offset, time[s1j]]
Endelse
nvaf_offset = nvaf_offset+1
Endif
Endif
Endelse
Endfor
Endif
ok_source = where(keep Eq 1, nok_source)
If(nok_source Gt 0) Then Begin
time = time[ok_source]
scpot = scpot[ok_source]
source = source[ok_source]
If(keyword_set(use_vaf_offset) && nvaf_offset Gt 0) Then Begin
s11 = where(source Eq 1, ns11)
If(ns11 Gt 0) Then Begin
If(nvaf_offset Gt 10 && use_vaf_offset[0] Ne 2) Then Begin
vaf_offset0 = vaf_offset
vaf_offset = simple_despike_1d(vaf_offset, threshold = 1.0)
vaf_offset = smooth_in_time(vaf_offset, tvaf_offset, 300.0)
store_data, 'temp_vaf_offset', data = {x:tvaf_offset, y:vaf_offset}
vaf_offset_s11 = interpol(vaf_offset, tvaf_offset, time[s11])
temp_time = where(time[s11] Lt min(tvaf_offset), ntemp_time)
If(ntemp_time Gt 0) Then vaf_offset_s11[temp_time] = vaf_offset[0]
temp_time = where(time[s11] Gt max(tvaf_offset), ntemp_time)
If(ntemp_time Gt 0) Then vaf_offset_s11[temp_time] = vaf_offset[n_elements(vaf_offset)-1]
store_data, 'temp_vaf_offset_s11', data = {x:time[s11], y:vaf_offset_s11}
scpot[s11] = scpot[s11]+vaf_offset_s11
Endif Else scpot[s11]=scpot[s11]+median(vaf_offset)
Endif
Endif
Endif Else Begin
dprint, 'No good scpot points after source check'
Endelse
endif else begin
time = t1234
scpot=vaf1234_3s
endelse
endif
scpot=(scale*(scpot+offset)) > min_pot
store_data,'th'+probes[i]+'_esa_pot',data={x:time,y:scpot}
endif else if string(efi_datatype) eq 'mom' then begin
thm_load_mom,probe=probes[i], trange=trange
get_data,'th'+probes[i]+'_pxxm_pot',data=tmp,index=index
if index ne 0 then begin
npts=n_elements(tmp.x)
if tmp.x[npts-1] lt mom_pot_adjust[isc[i],0] then begin
endif else if tmp.x[npts-1] lt mom_pot_adjust[isc[i],1] then begin
ind=where(tmp.x gt mom_pot_adjust[isc[i],0],count)
if count gt 0 then tmp.y[ind]=(tmp.y[ind]-1.215)/1.15
endif else if tmp.x[npts-1] lt mom_pot_adjust[isc[i],2] then begin
ind=where(tmp.x lt mom_pot_adjust[isc[i],1],count)
if count gt 0 then tmp.y[ind]=(tmp.y[ind]-1.215)/1.15
ind=where(tmp.x gt mom_pot_adjust[isc[i],1],count)
if count gt 0 then tmp.y[ind]=(tmp.y[ind]-1.215)
endif else begin
ind=where(tmp.x lt mom_pot_adjust[isc[i],2],count)
if count gt 0 then tmp.y[ind]=(tmp.y[ind]-1.215)
ind=where(tmp.x gt mom_pot_adjust[isc[i],2],count)
if count gt 0 then tmp.y[ind]=(tmp.y[ind]-1.215)/1.15
endelse
get_data,'th'+probes[i]+'_state_spinper',data=spinper
if not keyword_set(spinper) then begin
thm_load_state,/get_support_data,probe=probes[i], trange=trange
get_data,'th'+probes[i]+'_state_spinper',data=spinper
if not keyword_set(spinper) then begin
dprint, 'No state data available for probe ',probes[i]
dprint, 'Using default 3 sec spin period'
spin_period=replicate(3.,n_elements(tmp.x))
endif else spin_period = interp(spinper.y,spinper.x,tmp.x)
endif else spin_period = interp(spinper.y,spinper.x,tmp.x)
if tmp.x[0] ge mom_tim_adjust[isc[i]] then time=tmp.x-tshft_mom[1]*spin_period else $
if tmp.x[npts-1] le mom_tim_adjust[isc[i]] then time=tmp.x-tshft_mom[0]*spin_period else begin
min_tim=min(abs(tmp.x-mom_tim_adjust[isc[i]]),ind)
if tmp.x[ind] gt mom_tim_adjust[isc[i]] then ind=ind-1
time=tmp.x
time[0:ind]=time[0:ind]-tshft_mom[0]*spin_period[0:ind]
time[ind+1:npts-1]=time[ind+1:npts-1]-tshft_mom[1]*spin_period[ind+1:npts-1]
endelse
scpot=tmp.y
endif else begin
dprint, 'No moment data available for probe ',probes[i]
endelse
if keyword_set(make_plot) then store_data,'th'+sc+'_mom_pot',data={x:time,y:scpot}
scpot=(scale*(tmp.y+offset)) > min_pot
store_data,'th'+probes[i]+'_esa_pot',data={x:time,y:scpot}
endif else begin
get_data,'th'+probes[i]+'_state_spinper',data=spinper
if not keyword_set(spinper) then begin
thm_load_state,/get_support_data,probe=probes[i], trange=trange
get_data,'th'+probes[i]+'_state_spinper',data=spinper
if not keyword_set(spinper) then begin
dprint, 'No state data available for probe ',probes[i]
dprint, 'Using default 3 sec spin period'
spin_period=3.
npts=1
endif else begin
spin_period = spinper.y
npts=n_elements(spinper.x)
endelse
endif else begin
spin_period = spinper.y
npts=n_elements(spinper.x)
endelse
avg_spin_period=total(spin_period)/npts
thm_load_efi,probe=probes[i],datatype='vaf',level=1, trange=trange
get_data,'th'+probes[i]+'_vaf',data=tmp1,index=index2
if index2 ne 0 then begin
bad_frac=1.05
vaf1 = -1.*reform(tmp1.y[*,0])
vaf2 = -1.*reform(tmp1.y[*,1])
vaf3 = -1.*reform(tmp1.y[*,2])
vaf4 = -1.*reform(tmp1.y[*,3])
ind1 = where(bad_frac lt 3.*vaf1/(vaf2+vaf3+vaf4),cnt1)
ind2 = where(bad_frac lt 3.*vaf2/(vaf1+vaf3+vaf4),cnt2)
ind3 = where(bad_frac lt 3.*vaf3/(vaf4+vaf1+vaf2),cnt3)
ind4 = where(bad_frac lt 3.*vaf4/(vaf3+vaf1+vaf2),cnt4)
if cnt1 gt 0 then vaf1[ind1]=vaf2[ind1]
if cnt2 gt 0 then vaf2[ind2]=vaf1[ind2]
if cnt3 gt 0 then vaf3[ind3]=vaf4[ind3]
if cnt4 gt 0 then vaf4[ind4]=vaf3[ind4]
vaf12 = (vaf1+vaf2)/2.
vaf34 = (vaf3+vaf4)/2.
ind5 = where(vaf12/vaf34 gt bad_frac and vaf34 gt 1.,cnt5)
if cnt5 gt 0 then vaf12[ind5]=vaf34[ind5]
ind6 = where(vaf34/vaf12 gt bad_frac and vaf12 gt 1.,cnt6)
if cnt6 gt 0 then vaf34[ind6]=vaf12[ind6]
vaf1234 = (vaf12+vaf34)/2.
dprint, 'Bad point counts=',cnt1,cnt2,cnt3,cnt4,cnt5,cnt6
vaf1234=smooth_in_time(vaf1234,tmp1.x,avg_spin_period)
vaf1234_3s=time_average(tmp1.x,vaf1234,resolution=avg_spin_period,newtime=newtime)
if keyword_set(make_plot) then store_data,'th'+probes[i]+'_vaf1234',data={x:tmp1.x,y:vaf1234}
if keyword_set(make_plot) then store_data,'th'+probes[i]+'_v1234_3s',data={x:newtime,y:vaf1234_3s}
vaf3s = vaf1234_3s
vaf12_3s=time_average(tmp1.x,vaf12,resolution=avg_spin_period,newtime=newtime)
if keyword_set(make_plot) then store_data,'th'+probes[i]+'_v12_3s',data={x:newtime,y:vaf12_3s}
if string(efi_datatype) eq 'v12' then vaf3s = vaf12_3s
vaf34_3s=time_average(tmp1.x,vaf34,resolution=avg_spin_period,newtime=newtime)
if keyword_set(make_plot) then store_data,'th'+probes[i]+'_v34_3s',data={x:newtime,y:vaf34_3s}
if string(efi_datatype) eq 'v34' then vaf3s = vaf34_3s
if keyword_set(make_plot) then store_data,'th'+probes[i]+'_vaf_3s',data={x:newtime,y:vaf3s}
time=newtime
scpot=vaf3s
endif
scpot=(scale*(scpot+offset)) > min_pot
store_data,'th'+probes[i]+'_esa_pot',data={x:time,y:scpot}
endelse
endif
if probes[i] eq 'a' then begin
common tha_454,tha_454_ind,tha_454_dat
if size(/type, tha_454_dat) eq 8 then begin
if tha_454_ind ne -1 then begin
tt=(tha_454_dat.time+tha_454_dat.end_time)/2.
tha_454_dat.sc_pot=interp(scpot,time,tt)
store_data,'tha_peif_sc_pot',data={x:tt,y:tha_454_dat.sc_pot}
endif
endif
common tha_455,tha_455_ind,tha_455_dat
if size(/type, tha_455_dat) eq 8 then begin
if tha_455_ind ne -1 then begin
tt=(tha_455_dat.time+tha_455_dat.end_time)/2.
tha_455_dat.sc_pot=interp(scpot,time,tt)
store_data,'tha_peir_sc_pot',data={x:tt,y:tha_455_dat.sc_pot}
endif
endif
common tha_456,tha_456_ind,tha_456_dat
if size(/type, tha_456_dat) eq 8 then begin
if tha_456_ind ne -1 then begin
tt=(tha_456_dat.time+tha_456_dat.end_time)/2.
tha_456_dat.sc_pot=interp(scpot,time,tt)
store_data,'tha_peib_sc_pot',data={x:tt,y:tha_456_dat.sc_pot}
endif
endif
common tha_457,tha_457_ind,tha_457_dat
if size(/type, tha_457_dat) eq 8 then begin
if tha_457_ind ne -1 then begin
tt=(tha_457_dat.time+tha_457_dat.end_time)/2.
tha_457_dat.sc_pot=interp(scpot,time,tt)
store_data,'tha_peef_sc_pot',data={x:tt,y:tha_457_dat.sc_pot}
endif
endif
common tha_458,tha_458_ind,tha_458_dat
if size(/type, tha_458_dat) eq 8 then begin
if tha_458_ind ne -1 then begin
tt=(tha_458_dat.time+tha_458_dat.end_time)/2.
tha_458_dat.sc_pot=interp(scpot,time,tt)
store_data,'tha_peer_sc_pot',data={x:tt,y:tha_458_dat.sc_pot}
endif
endif
common tha_459,tha_459_ind,tha_459_dat
if size(/type, tha_459_dat) eq 8 then begin
if tha_459_ind ne -1 then begin
tt=(tha_459_dat.time+tha_459_dat.end_time)/2.
tha_459_dat.sc_pot=interp(scpot,time,tt)
store_data,'tha_peeb_sc_pot',data={x:tt,y:tha_459_dat.sc_pot}
endif
endif
endif else if probes[i] eq 'b' then begin
common thb_454,thb_454_ind,thb_454_dat
if size(/type, thb_454_dat) eq 8 then begin
if thb_454_ind ne -1 then begin
tt=(thb_454_dat.time+thb_454_dat.end_time)/2.
thb_454_dat.sc_pot=interp(scpot,time,tt)
store_data,'thb_peif_sc_pot',data={x:tt,y:thb_454_dat.sc_pot}
endif
endif
common thb_455,thb_455_ind,thb_455_dat
if size(/type, thb_455_dat) eq 8 then begin
if thb_455_ind ne -1 then begin
tt=(thb_455_dat.time+thb_455_dat.end_time)/2.
thb_455_dat.sc_pot=interp(scpot,time,tt)
store_data,'thb_peir_sc_pot',data={x:tt,y:thb_455_dat.sc_pot}
endif
endif
common thb_456,thb_456_ind,thb_456_dat
if size(/type, thb_456_dat) eq 8 then begin
if thb_456_ind ne -1 then begin
tt=(thb_456_dat.time+thb_456_dat.end_time)/2.
thb_456_dat.sc_pot=interp(scpot,time,tt)
store_data,'thb_peib_sc_pot',data={x:tt,y:thb_456_dat.sc_pot}
endif
endif
common thb_457,thb_457_ind,thb_457_dat
if size(/type, thb_457_dat) eq 8 then begin
if thb_457_ind ne -1 then begin
tt=(thb_457_dat.time+thb_457_dat.end_time)/2.
thb_457_dat.sc_pot=interp(scpot,time,tt)
store_data,'thb_peef_sc_pot',data={x:tt,y:thb_457_dat.sc_pot}
endif
endif
common thb_458,thb_458_ind,thb_458_dat
if size(/type, thb_458_dat) eq 8 then begin
if thb_458_ind ne -1 then begin
tt=(thb_458_dat.time+thb_458_dat.end_time)/2.
thb_458_dat.sc_pot=interp(scpot,time,tt)
store_data,'thb_peer_sc_pot',data={x:tt,y:thb_458_dat.sc_pot}
endif
endif
common thb_459,thb_459_ind,thb_459_dat
if size(/type, thb_459_dat) eq 8 then begin
if thb_459_ind ne -1 then begin
tt=(thb_459_dat.time+thb_459_dat.end_time)/2.
thb_459_dat.sc_pot=interp(scpot,time,tt)
store_data,'thb_peeb_sc_pot',data={x:tt,y:thb_459_dat.sc_pot}
endif
endif
endif else if probes[i] eq 'c' then begin
common thc_454,thc_454_ind,thc_454_dat
if size(/type, thc_454_dat) eq 8 then begin
if thc_454_ind ne -1 then begin
tt=(thc_454_dat.time+thc_454_dat.end_time)/2.
thc_454_dat.sc_pot=interp(scpot,time,tt)
store_data,'thc_peif_sc_pot',data={x:tt,y:thc_454_dat.sc_pot}
endif
endif
common thc_455,thc_455_ind,thc_455_dat
if size(/type, thc_455_dat) eq 8 then begin
if thc_455_ind ne -1 then begin
tt=(thc_455_dat.time+thc_455_dat.end_time)/2.
thc_455_dat.sc_pot=interp(scpot,time,tt)
store_data,'thc_peir_sc_pot',data={x:tt,y:thc_455_dat.sc_pot}
endif
endif
common thc_456,thc_456_ind,thc_456_dat
if size(/type, thc_456_dat) eq 8 then begin
if thc_456_ind ne -1 then begin
tt=(thc_456_dat.time+thc_456_dat.end_time)/2.
thc_456_dat.sc_pot=interp(scpot,time,tt)
store_data,'thc_peib_sc_pot',data={x:tt,y:thc_456_dat.sc_pot}
endif
endif
common thc_457,thc_457_ind,thc_457_dat
if size(/type, thc_457_dat) eq 8 then begin
if thc_457_ind ne -1 then begin
tt=(thc_457_dat.time+thc_457_dat.end_time)/2.
thc_457_dat.sc_pot=interp(scpot,time,tt)
store_data,'thc_peef_sc_pot',data={x:tt,y:thc_457_dat.sc_pot}
endif
endif
common thc_458,thc_458_ind,thc_458_dat
if size(/type, thc_458_dat) eq 8 then begin
if thc_458_ind ne -1 then begin
tt=(thc_458_dat.time+thc_458_dat.end_time)/2.
thc_458_dat.sc_pot=interp(scpot,time,tt)
store_data,'thc_peer_sc_pot',data={x:tt,y:thc_458_dat.sc_pot}
endif
endif
common thc_459,thc_459_ind,thc_459_dat
if size(/type, thc_459_dat) eq 8 then begin
if thc_459_ind ne -1 then begin
tt=(thc_459_dat.time+thc_459_dat.end_time)/2.
thc_459_dat.sc_pot=interp(scpot,time,tt)
store_data,'thc_peeb_sc_pot',data={x:tt,y:thc_459_dat.sc_pot}
endif
endif
endif else if probes[i] eq 'd' then begin
common thd_454,thd_454_ind,thd_454_dat
if size(/type, thd_454_dat) eq 8 then begin
if thd_454_ind ne -1 then begin
tt=(thd_454_dat.time+thd_454_dat.end_time)/2.
thd_454_dat.sc_pot=interp(scpot,time,tt)
store_data,'thd_peif_sc_pot',data={x:tt,y:thd_454_dat.sc_pot}
endif
endif
common thd_455,thd_455_ind,thd_455_dat
if size(/type, thd_455_dat) eq 8 then begin
if thd_455_ind ne -1 then begin
tt=(thd_455_dat.time+thd_455_dat.end_time)/2.
thd_455_dat.sc_pot=interp(scpot,time,tt)
store_data,'thd_peir_sc_pot',data={x:tt,y:thd_455_dat.sc_pot}
endif
endif
common thd_456,thd_456_ind,thd_456_dat
if size(/type, thd_456_dat) eq 8 then begin
if thd_456_ind ne -1 then begin
tt=(thd_456_dat.time+thd_456_dat.end_time)/2.
thd_456_dat.sc_pot=interp(scpot,time,tt)
store_data,'thd_peib_sc_pot',data={x:tt,y:thd_456_dat.sc_pot}
endif
endif
common thd_457,thd_457_ind,thd_457_dat
if size(/type, thd_457_dat) eq 8 then begin
if thd_457_ind ne -1 then begin
tt=(thd_457_dat.time+thd_457_dat.end_time)/2.
thd_457_dat.sc_pot=interp(scpot,time,tt)
store_data,'thd_peef_sc_pot',data={x:tt,y:thd_457_dat.sc_pot}
endif
endif
common thd_458,thd_458_ind,thd_458_dat
if size(/type, thd_458_dat) eq 8 then begin
if thd_458_ind ne -1 then begin
tt=(thd_458_dat.time+thd_458_dat.end_time)/2.
thd_458_dat.sc_pot=interp(scpot,time,tt)
store_data,'thd_peer_sc_pot',data={x:tt,y:thd_458_dat.sc_pot}
endif
endif
common thd_459,thd_459_ind,thd_459_dat
if size(/type, thd_459_dat) eq 8 then begin
if thd_459_ind ne -1 then begin
tt=(thd_459_dat.time+thd_459_dat.end_time)/2.
thd_459_dat.sc_pot=interp(scpot,time,tt)
store_data,'thd_peeb_sc_pot',data={x:tt,y:thd_459_dat.sc_pot}
endif
endif
endif else if probes[i] eq 'e' then begin
common the_454,the_454_ind,the_454_dat
if size(/type, the_454_dat) eq 8 then begin
if the_454_ind ne -1 then begin
tt=(the_454_dat.time+the_454_dat.end_time)/2.
the_454_dat.sc_pot=interp(scpot,time,tt)
store_data,'the_peif_sc_pot',data={x:tt,y:the_454_dat.sc_pot}
endif
endif
common the_455,the_455_ind,the_455_dat
if size(/type, the_455_dat) eq 8 then begin
if the_455_ind ne -1 then begin
tt=(the_455_dat.time+the_455_dat.end_time)/2.
the_455_dat.sc_pot=interp(scpot,time,tt)
store_data,'the_peir_sc_pot',data={x:tt,y:the_455_dat.sc_pot}
endif
endif
common the_456,the_456_ind,the_456_dat
if size(/type, the_456_dat) eq 8 then begin
if the_456_ind ne -1 then begin
tt=(the_456_dat.time+the_456_dat.end_time)/2.
the_456_dat.sc_pot=interp(scpot,time,tt)
store_data,'the_peib_sc_pot',data={x:tt,y:the_456_dat.sc_pot}
endif
endif
common the_457,the_457_ind,the_457_dat
if size(/type, the_457_dat) eq 8 then begin
if the_457_ind ne -1 then begin
tt=(the_457_dat.time+the_457_dat.end_time)/2.
the_457_dat.sc_pot=interp(scpot,time,tt)
store_data,'the_peef_sc_pot',data={x:tt,y:the_457_dat.sc_pot}
endif
endif
common the_458,the_458_ind,the_458_dat
if size(/type, the_458_dat) eq 8 then begin
if the_458_ind ne -1 then begin
tt=(the_458_dat.time+the_458_dat.end_time)/2.
the_458_dat.sc_pot=interp(scpot,time,tt)
store_data,'the_peer_sc_pot',data={x:tt,y:the_458_dat.sc_pot}
endif
endif
common the_459,the_459_ind,the_459_dat
if size(/type, the_459_dat) eq 8 then begin
if the_459_ind ne -1 then begin
tt=(the_459_dat.time+the_459_dat.end_time)/2.
the_459_dat.sc_pot=interp(scpot,time,tt)
store_data,'the_peeb_sc_pot',data={x:tt,y:the_459_dat.sc_pot}
endif
endif
endif
endfor
endelse
end