pro rbsp_efw_dcfield_removal_crib,probe,no_spice_load=no_spice_load,noplot=noplot,model=model,ql=ql
rbsp_efw_init
!rbsp_efw.user_agent = ''
rbspx = 'rbsp'+probe
x = timerange()
date = strmid(time_string(x[0]),0,10)
if ~keyword_set(no_spice_load) then rbsp_load_spice_kernels
rbsp_load_state,probe=probe,/no_spice_load,datatype=['spinper','spinphase','mat_dsc','Lvec']
rbsp_efw_position_velocity_crib,/no_spice_load,/noplot
get_data,rbspx+'_spinaxis_direction_gse',data=wsc_GSE
if ~keyword_set(ql) then begin
rbsp_load_emfisis,probe=probe,coord='gse',cadence='4sec',level='l3'
get_data,rbspx+'_emfisis_l3_4sec_gse_Mag',data=dd
if ~is_struct(dd) then begin
print,'***** NO EMFISIS L3 DATA TO LOAD *****'
print,'exiting rbsp_efw_DCfield_removal_crib.pro'
return
endif
copy_data,rbspx+'_emfisis_l3_4sec_gse_Mag',rbspx+'_mag_gse'
get_data,rbspx+'_mag_gse',data=dd
wsc_GSE_tmp = [[interpol(wsc_GSE.y[*,0],wsc_GSE.x,dd.x)],$
[interpol(wsc_GSE.y[*,1],wsc_GSE.x,dd.x)],$
[interpol(wsc_GSE.y[*,2],wsc_GSE.x,dd.x)]]
rbsp_gse2mgse,rbspx+'_mag_gse',reform(wsc_GSE_tmp),newname=rbspx+'_mag_mgse'
endif
if keyword_set(ql) then begin
rbsp_load_emfisis,probe=probe,/quicklook
get_data,rbspx+'_emfisis_quicklook_Mag',data=dd
if ~is_struct(dd) then begin
print,'******NO QL MAG DATA TO LOAD.....rbsp_efw_DCfield_removal_crib.pro*******'
return
endif
t0 = time_double(date)
t1 = t0 + 86400.
ttst = tnames(rbspx+'_emfisis_quicklook_Mag',cnt)
if cnt eq 1 then time_clip,rbspx+'_emfisis_quicklook_Mag',t0,t1,replace=1,error=error,newname=rbspx+'_emfisis_quicklook_Mag'
ttst = tnames(rbspx+'_emfisis_quicklook_Magnitude',cnt)
if cnt eq 1 then time_clip,rbspx+'_emfisis_quicklook_Magnitude',t0,t1,replace=1,error=error,newname=rbspx+'_emfisis_quicklook_Magnitude'
get_data,rbspx +'_emfisis_quicklook_Mag',data=datt
data_att = {coord_sys:'uvw'}
dlim = {data_att:data_att}
store_data,rbspx +'_emfisis_quicklook_Mag',data=datt,dlimits=dlim
rbsp_decimate,rbspx +'_emfisis_quicklook_Mag', upper = 2
rbsp_spinfit,rbspx +'_emfisis_quicklook_Mag', plane_dim = 0
rbsp_cotrans,rbspx +'_emfisis_quicklook_Mag_spinfit', rbspx + '_mag_mgse', /dsc2mgse
wsc_GSE_tmp = [[interpol(wsc_GSE.y[*,0],wsc_GSE.x,dd.x)],$
[interpol(wsc_GSE.y[*,1],wsc_GSE.x,dd.x)],$
[interpol(wsc_GSE.y[*,2],wsc_GSE.x,dd.x)]]
rbsp_mgse2gse,rbspx + '_mag_mgse',wsc_GSE_tmp,newname=rbspx+'_mag_gse',probe=probe,/no_spice_load
endif
rbsp_downsample,[rbspx+'_mag_gse',$
rbspx+'_magnitude_gse'],1/11.,/nochange
cotrans,rbspx+'_mag_gse',rbspx+'_mag_gsm',/GSE2GSM
copy_data,rbspx+'_mag_gsm',rbspx+'_mag_gsm_for_subtract'
copy_data,rbspx+'_mag_gse',rbspx+'_mag_gse_for_subtract'
copy_data,rbspx+'_mag_mgse',rbspx+'_mag_mgse_for_subtract'
copy_data,rbspx+'_state_pos_gsm','pos_gsm'
posname = 'pos_gsm'
if ~keyword_set(model) then model = 't89'
if model eq 't89' then par = 2.0D
if model eq 't96' then call_procedure,'t'+model,posname,pdyn=2.0D,dsti=-30.0D,$
yimf=0.0D,zimf=-5.0D
if model eq 't89' then call_procedure,'t'+model,posname,kp=2.0
copy_data,'pos_gsm_b'+model,rbspx+'_mag_gsm_'+model
get_data,posname,data=dd
dt = dd.x[1] - dd.x[0]
rbsp_detrend,rbspx+'_mag_gsm_'+model,dt/8.
store_data,rbspx+'_mag_gsm_'+model,/delete
copy_data,rbspx+'_mag_gsm_'+model+'_smoothed',rbspx+'_mag_gsm_'+model
cotrans,rbspx+'_mag_gsm_'+model,rbspx+'_mag_gse_'+model,/GSM2GSE
get_data,rbspx+'_mag_gse_'+model,data=tmpp
wsc_GSE_tmp3 = [[interpol(wsc_GSE.y[*,0],wsc_GSE.x,tmpp.x)],$
[interpol(wsc_GSE.y[*,1],wsc_GSE.x,tmpp.x)],$
[interpol(wsc_GSE.y[*,2],wsc_GSE.x,tmpp.x)]]
rbsp_gse2mgse,rbspx+'_mag_gse_'+model,reform(wsc_GSE_tmp3),newname=rbspx+'_mag_mgse_'+model
dif_data,rbspx+'_mag_gsm_for_subtract',rbspx+'_mag_gsm_'+model,newname=rbspx+'_mag_gsm_'+model+'_dif'
dif_data,rbspx+'_mag_mgse_for_subtract',rbspx+'_mag_mgse_'+model,newname=rbspx+'_mag_mgse_'+model+'_dif'
dif_data,rbspx+'_mag_gse_for_subtract',rbspx+'_mag_gse_'+model,newname=rbspx+'_mag_gse_'+model+'_dif'
options,rbspx+'_mag_gsm_for_subtract','colors',[2,4,6]
options,rbspx+'_mag_gse_for_subtract','colors',[2,4,6]
options,rbspx+'_mag_mgse_for_subtract','colors',[2,4,6]
options,rbspx+'_'+'mag'+'_gsm_for_subtract','labels',['gsm x','gsm y','gsm z']
options,rbspx+'_mag_gsm_'+model,'labels',['gsm x','gsm y','gsm z']
options,rbspx+'_mag_gsm_'+model+'_dif','labels',['gsm x','gsm y','gsm z']
options,rbspx+'_'+'mag'+'_mgse_for_subtract','labels',['mgse x','mgse y','mgse z']
options,rbspx+'_mag_mgse_'+model,'labels',['mgse x','mgse y','mgse z']
options,rbspx+'_mag_mgse_'+model+'_dif','labels',['mgse x','mgse y','mgse z']
options,rbspx+'_'+'mag'+'_gse_for_subtract','labels',['gse x','gse y','gse z']
options,rbspx+'_mag_gse_'+model,'labels',['gse x','gse y','gse z']
options,rbspx+'_mag_gse_'+model+'_dif','labels',['gse x','gse y','gse z']
ylim,rbspx+'_mag_gsm_'+model+'_dif',-100,100
ylim,rbspx+'_'+'mag'+'_gsm_for_subtract',-3d4,3d4
ylim,rbspx+'_mag_gsm_'+model,-3d4,3d4
ylim,rbspx+'_mag_mgse_'+model+'_dif',-100,100
ylim,rbspx+'_'+'mag'+'_mgse_for_subtract',-3d4,3d4
ylim,rbspx+'_mag_mgse_'+model,-3d4,3d4
ylim,rbspx+'_mag_gse_'+model+'_dif',-100,100
ylim,rbspx+'_'+'mag'+'_gse_for_subtract',-3d4,3d4
ylim,rbspx+'_mag_gse_'+model,-3d4,3d4
options,rbspx+'_mag_gsm_'+model+'_dif','ytitle','Bfield-model!C'+strupcase(model)+'!C[nT]'
options,rbspx+'_mag_gsm_'+model,'ytitle','Model field!C'+strupcase(model)+'!C[nT]'
options,rbspx+'_mag_gse_'+model+'_dif','ytitle','Bfield-model!C'+strupcase(model)+'!C[nT]'
options,rbspx+'_mag_gse_'+model,'ytitle','Model field!C'+strupcase(model)+'!C[nT]'
options,rbspx+'_mag_mgse_'+model+'_dif','ytitle','Bfield-model!C'+strupcase(model)+'!C[nT]'
options,rbspx+'_mag_mgse_'+model,'ytitle','Model field!C'+strupcase(model)+'!C[nT]'
if model ne 't89' then begin
kyoto_load_dst
wi_mfi_load,tplotnames=tn
wi_3dp_load,tplotnames=tn2
if (tn[0] ne '') and (tn2[0] ne '') then begin
cotrans,'wi_h0_mfi_B3GSE','wi_b3gsm',/GSE2GSM
get_tsy_params,'kyoto_dst','wi_b3gsm','wi_3dp_k0_ion_density','wi_3dp_k0_ion_vel',strupcase(model)
if model eq 'igrf' then call_procedure,'igrf',posname,parmod=model+'_par'$
else call_procedure,'t'+model,posname,parmod=model+'_par'
copy_data,'pos_gsm_bt96',rbspx+'_mag_gsm_'+model+'_wind'
tinterpol_mxn,rbspx+'_mag_gsm_'+model+'_wind',$
mag_gsm.x,$
newname=rbspx+'_mag_gsm_'+model+'_wind'
dif_data,rbspx+'_mag_gsm',$
rbspx+'_mag_gsm_'+model+'_wind',$
newname=rbspx + '_mag_gsm_' + model + '_wind_dif'
cotrans,rbspx+'_mag_gsm_'+model+'_wind',rbspx+'_mag_gse_'+model+'_wind',/GSM2GSE
dif_data,rbspx+'_mag_gse_for_subtract',$
rbspx+'_mag_gse_'+model+'_wind',$
newname=rbspx + '_mag_gse_' + model + '_wind_dif'
wsc_GSE_tmp = [[interpol(wsc_GSE[0,*],time_double(time3),mag_gsm.x)],$
[interpol(wsc_GSE[1,*],time_double(time3),mag_gsm.x)],$
[interpol(wsc_GSE[2,*],time_double(time3),mag_gsm.x)]]
rbsp_gse2mgse,rbspx+'_mag_gse_'+model+'_wind',reform(wsc_GSE_tmp),newname=rbspx+'_mag_mgse_'+model+'_wind'
dif_data,rbspx+'_mag_mgse_for_subtract',$
rbspx+'_mag_mgse_'+model+'_wind',$
newname=rbspx + '_mag_mgse_' + model + '_wind_dif'
endif else print,'==> NO WIND DATA AVAILABLE'
ace_mfi_load,tplotnames=tn
ace_swe_load,tplotnames=tn2
if (tn[0] ne '') and (tn2[0] ne '') then begin
cotrans,'ace_k0_mfi_BGSEc','ace_mag_Bgsm',/GSE2GSM
get_tsy_params,'kyoto_dst','ace_mag_Bgsm','ace_k0_swe_Np','ace_k0_swe_Vp',strupcase(model),/speed
if model eq 'igrf' then call_procedure,'igrf',posname,parmod=model+'_par' $
else call_procedure,'t'+model,posname,parmod=model+'_par'
copy_data,'pos_gsm_bt96',rbspx+'_mag_gsm_'+model+'_ace'
tinterpol_mxn,rbspx+'_mag_gsm_'+model+'_ace',$
mag_gsm.x,$
newname=rbspx+'_mag_gsm_'+model+'_ace'
dif_data,rbspx+'_mag_gsm',$
rbspx+'_mag_gsm_'+model+'_ace',$
newname=rbspx + '_mag_gsm_' + model + '_ace_dif'
cotrans,rbspx+'_mag_gsm_'+model+'_ace',rbspx+'_mag_gse_'+model+'_ace',/GSM2GSE
dif_data,rbspx+'_mag_gse_for_subtract',$
rbspx+'_mag_gse_'+model+'_ace',$
newname=rbspx + '_mag_gse_' + model + '_ace_dif'
wsc_GSE_tmp = [[interpol(wsc_GSE[0,*],time_double(time3),mag_gsm.x)],$
[interpol(wsc_GSE[1,*],time_double(time3),mag_gsm.x)],$
[interpol(wsc_GSE[2,*],time_double(time3),mag_gsm.x)]]
rbsp_gse2mgse,rbspx+'_mag_gse_'+model+'_ace',reform(wsc_GSE_tmp),newname=rbspx+'_mag_mgse_'+model+'_ace'
dif_data,rbspx+'_mag_mgse_for_subtract',$
rbspx+'_mag_mgse_'+model+'_ace',$
newname=rbspx + '_mag_mgse_' + model + '_ace_dif'
endif else print,'==> NO ACE DATA AVAILABLE'
omni_hro_load,tplotnames=tn
if tn[0] ne '' then begin
store_data,'omni_imf',data=['OMNI_HRO_1min_BY_GSM','OMNI_HRO_1min_BZ_GSM']
get_tsy_params,'kyoto_dst','omni_imf','OMNI_HRO_1min_proton_density','OMNI_HRO_1min_flow_speed',strupcase(model),/speed,/imf_yz
if model eq 'igrf' then call_procedure,'igrf',posname,parmod=model+'_par' $
else call_procedure,'t'+model,posname,parmod=model+'_par'
copy_data,'pos_gsm_bt96',rbspx+'_mag_gsm_'+model+'_omni'
tinterpol_mxn,rbspx+'_mag_gsm_'+model+'_omni',$
mag_gsm.x,$
newname=rbspx+'_mag_gsm_'+model+'_omni'
dif_data,rbspx+'_mag_gsm',$
rbspx+'_mag_gsm_'+model+'_omni',$
newname=rbspx + '_mag_gsm_' + model + '_omni_dif'
cotrans,rbspx+'_mag_gsm_'+model+'_omni',rbspx+'_mag_gse_'+model+'_omni',/GSM2GSE
dif_data,rbspx+'_mag_gse_for_subtract',$
rbspx+'_mag_gse_'+model+'_omni',$
newname=rbspx + '_mag_gse_' + model + '_omni_dif'
wsc_GSE_tmp = [[interpol(wsc_GSE[0,*],time_double(time3),mag_gsm.x)],$
[interpol(wsc_GSE[1,*],time_double(time3),mag_gsm.x)],$
[interpol(wsc_GSE[2,*],time_double(time3),mag_gsm.x)]]
rbsp_gse2mgse,rbspx+'_mag_gse_'+model+'_omni',reform(wsc_GSE_tmp),newname=rbspx+'_mag_mgse_'+model+'_omni'
dif_data,rbspx+'_mag_mgse_for_subtract',$
rbspx+'_mag_mgse_'+model+'_omni',$
newname=rbspx + '_mag_mgse_' + model + '_omni_dif'
endif else print,'==> NO OMNI DATA'
endif
store_data,['*OMNI_HRO*'],/delete
store_data,['*omni_imf*'],/delete
store_data,['*ace_k0*','ace_mag_Bgsm'],/delete
store_data,['*wi_3dp*','*wi_h0*','wi_b3gsm'],/delete
store_data,['*kyoto_dst*'],/delete
store_data,['t96_par','par_out'],/delete
options,rbspx + '_mag_mgse_' + model+'_wind','ytitle','Model field!C'+strupcase(model)+'!Cwith Wind input!C[nT]'
options,rbspx + '_mag_mgse_' + model+'_ace','ytitle','Model field!C'+strupcase(model)+'!Cwith ACE input!C[nT]'
options,rbspx + '_mag_mgse_' + model+'_omni','ytitle','Model field!C'+strupcase(model)+'!Cwith OMNI input!C[nT]'
options,rbspx + '_mag_mgse_' + model+'_wind_dif','ytitle','Bfield-model!C'+strupcase(model)+'!Cwith Wind input!C[nT]'
options,rbspx + '_mag_mgse_' + model+'_ace_dif','ytitle','Bfield-model!C'+strupcase(model)+'!Cwith ACE input!C[nT]'
options,rbspx + '_mag_mgse_' + model+'_omni_dif','ytitle','Bfield-model!C'+strupcase(model)+'!Cwith OMNI input!C[nT]'
options,rbspx + '_mag_mgse_' + model,'ysubtitle',''
options,rbspx + '_mag_mgse_' + model+'_wind','ysubtitle',''
options,rbspx + '_mag_mgse_' + model+'_ace','ysubtitle',''
options,rbspx + '_mag_mgse_' + model+'_omni','ysubtitle',''
options,rbspx + '_mag_mgse_' + model + '_dif','ysubtitle',''
options,rbspx + '_mag_mgse_' + model+'_wind_dif','ysubtitle',''
options,rbspx + '_mag_mgse_' + model+'_ace_dif','ysubtitle',''
options,rbspx + '_mag_mgse_' + model+'_omni_dif','ysubtitle',''
if model eq 'igrf' then begin
copy_data,rbspx+'_mag_bt89_original',rbspx+'_mag_bigrf_original'
store_data,[rbspx+'_mag_bt89_original'],/delete
endif
if ~keyword_set(noplot) then begin
ylim,[rbspx+'_mag_mgse_for_subtract',$
rbspx+'_mag_mgse_'+model+'_dif',$
rbspx+'_mag_mgse_'+model+'_wind_dif',$
rbspx+'_mag_mgse_'+model+'_ace_dif',$
rbspx+'_mag_mgse_'+model+'_omni_dif',$
rbspx+'_mag_mgse_'+model,$
rbspx+'_mag_mgse_'+model+'_wind',$
rbspx+'_mag_mgse_'+model+'_ace',$
rbspx+'_mag_mgse_'+model+'_omni'],-2d4,2d4
tplot_options,'title','RBSP-'+strupcase(probe)+' Mag model comparison'
tplot,[rbspx+'_mag_mgse_for_subtract',$
rbspx+'_mag_mgse_'+model,$
rbspx+'_mag_mgse_'+model+'_dif']
tplot_options,'title','RBSP-'+strupcase(probe)+' Mag model comparison!Cusing Wind input'
tplot,[rbspx+'_mag_mgse_for_subtract',$
rbspx+'_mag_mgse_'+model+'_wind',$
rbspx+'_mag_mgse_'+model+'_wind_dif']
tplot_options,'title','RBSP-'+strupcase(probe)+' Mag model comparison!Cusing ACE input'
tplot,[rbspx+'_mag_mgse_for_subtract',$
rbspx+'_mag_mgse_'+model+'_ace',$
rbspx+'_mag_mgse_'+model+'_ace_dif']
tplot_options,'title','RBSP-'+strupcase(probe)+' Mag model comparison!Cusing OMNI input'
tplot,[rbspx+'_mag_mgse_for_subtract',$
rbspx+'_mag_mgse_'+model+'_omni',$
rbspx+'_mag_mgse_'+model+'_omni_dif']
ylim,[rbspx+'_mag_mgse_for_subtract',$
rbspx+'_mag_mgse_'+model+'_dif',$
rbspx+'_mag_mgse_'+model+'_wind_dif',$
rbspx+'_mag_mgse_'+model+'_ace_dif',$
rbspx+'_mag_mgse_'+model+'_omni_dif',$
rbspx+'_mag_mgse_'+model,$
rbspx+'_mag_mgse_'+model+'_wind',$
rbspx+'_mag_mgse_'+model+'_ace',$
rbspx+'_mag_mgse_'+model+'_omni'],-200,200
tplot_options,'title','RBSP-'+strupcase(probe)+' Mag model comparison'
tplot,[rbspx+'_mag_mgse_for_subtract',$
rbspx+'_mag_mgse_'+model,$
rbspx+'_mag_mgse_'+model+'_dif']
tplot_options,'title','RBSP-'+strupcase(probe)+' Mag model comparison!Cusing Wind input'
tplot,[rbspx+'_mag_mgse_for_subtract',$
rbspx+'_mag_mgse_'+model+'_wind',$
rbspx+'_mag_mgse_'+model+'_wind_dif']
tplot_options,'title','RBSP-'+strupcase(probe)+' Mag model comparison!Cusing ACE input'
tplot,[rbspx+'_mag_mgse_for_subtract',$
rbspx+'_mag_mgse_'+model+'_ace',$
rbspx+'_mag_mgse_'+model+'_ace_dif']
tplot_options,'title','RBSP-'+strupcase(probe)+' Mag model comparison!Cusing OMNI input'
tplot,[rbspx+'_mag_mgse_for_subtract',$
rbspx+'_mag_mgse_'+model+'_omni',$
rbspx+'_mag_mgse_'+model+'_omni_dif']
ylim,[rbspx+'_mag_mgse_'+model+'_dif',$
rbspx+'_mag_mgse_'+model+'_wind_dif',$
rbspx+'_mag_mgse_'+model+'_ace_dif',$
rbspx+'_mag_mgse_'+model+'_omni_dif'],-100,100
tplot_options,'Comparison of four models'
tplot,[rbspx+'_mag_gsm_'+model+'_dif',$
rbspx+'_mag_gsm_'+model+'_wind_dif',$
rbspx+'_mag_gsm_'+model+'_ace_dif',$
rbspx+'_mag_gsm_'+model+'_omni_dif']
tplot_options,'Comparison of four models'
tplot,[rbspx+'_mag_gse_'+model+'_dif',$
rbspx+'_mag_gse_'+model+'_wind_dif',$
rbspx+'_mag_gse_'+model+'_ace_dif',$
rbspx+'_mag_gse_'+model+'_omni_dif']
tplot_options,'Comparison of four models'
tplot,[rbspx+'_mag_mgse_'+model+'_dif',$
rbspx+'_mag_mgse_'+model+'_wind_dif',$
rbspx+'_mag_mgse_'+model+'_ace_dif',$
rbspx+'_mag_mgse_'+model+'_omni_dif']
endif
end