;+ ;NAME: ; thm_sst_load_calibrate ;PURPOSE: ; Wrapper which loads SST data and performs various calibration tasks; providing a high level interface to sst data. ; As of 2013-03-11 this provides the most advanced SST calibrations. ; #1 GEANT4 modeled theoretical channel efficiencies.(provided by Drew Turner) ; #2 GEANT4 modeled theoretical energy boundaries.(provided by Drew Turner) ; #3 Empirical dead layers calculated through intercalibration with ESA.(provided by Drew Turner) ; #4 Empircal detector performance calculated through intercalibration with ESA. (provided by Drew Turner) ; #5 Interpolates energy channels to single energy grid. (So that moments & pitch angle distributions can be generated) ; #6 Interpolates energy channels with ESA to fill energy gap between instruments. ; ;Inputs: ; probe=probe: Default is "a" ; datatype=datatype: Default is "psif" ; trange=trange: Default is current(loading more than 2 hours could be very slow) ; energies=energies: The target energy interpolates for SST data in eV ; default: [26000.,28000., 31000.000, 42000.000, 55500.000, 68000.000, 95500.000, 145000.00, 206500.00, 295500.00, 420000.00, 652500.00,$ ; 1133500.0, 3976500.0] ; sun_bins=sun_bins: The SST look directions to remove due to sun contamination. ; default: [0,8,16,24,32,33,40,47,48,55,56,57] ; Set to -1 for no sun removal ;Outputs: ; dist_data=dist_data: ; dist_data pointer array(like the type returned by thm_part_dist_array.pro) ; dist_data can be used with standard particle routines like thm_part_moments.pro & thm_part_getspec.pro ; ; error=error: After completion, will be set 1 if error occured, zero otherwise ;NOTES: ; #1 As of now, this thing is extremely inefficient in processor & memory. This limits loads to only a few hours on machines with 2-4 Gb of RAM. ; Future iterations will window loading to reduce memory utilization at the expense of higher processing time. ; ; #2 Only intended for psif/psef, for now. Any other usages will produce unreliable results or errors. ; ; #3 Loads ESA data to perform intercalibration between instruments on the fly. ; ; #4 More detailed SST electrons calibration parameters are pending new ESA decontamination. ; ;Examples: ; #1 ; thm_sst_load_calibrate,probe='d',datatype='psif',trange=['2011-07-29/13:00:00','2011-07-29/14:00:00'],dist_data=dist_psif ; thm_part_moments,inst='psif',probe='d',dist_array=dist_psif ; thm_part_getspec,data_type='psif',probe='d',dist_array=dist_psif,angle='phi' ; ;See Also: ; thm_sst_interpolate_tests.pro ; thm_part_dist_array.pro ; ;$LastChangedBy: pcruce $ ;$LastChangedDate: 2013-03-11 17:32:36 -0700 (Mon, 11 Mar 2013) $ ;$LastChangedRevision: 11772 $ ;$URL: svn+ssh://thmsvn@ambrosia.ssl.berkeley.edu/repos/thmsoc/tags/tdas_8_00/idl/themis/spacecraft/particles/SST/SST_cal_workdir/thm_sst_load_calibrate.pro $ ;- pro thm_sst_load_calibrate,probe=probe,datatype=datatype,trange=trange,energies=energies,sun_bins=sun_bins,dist_data=dist_data,error=error,_extra=ex compile_opt idl2 error=1 heap_gc thm_init ;color table & stuffs if ~undefined(probe) then begin probe=probe endif else begin probe='a' endelse if ~undefined(datatype) then begin datatype=datatype endif else begin datatype='psif' endelse if ~undefined(trange) then begin trange=trange endif else begin trange=timerange() endelse if ~undefined(energies) then begin energies=energies endif else begin energies = [26000.,28000., 31000.000, 42000.000, 55500.000, 68000.000, 95500.000, 145000.00, 206500.00, 295500.00, 420000.00, 652500.00,$ 1133500.0, 3976500.0] endelse sun_mask = dblarr(64)+1 ;allocate variable for bins, with all bins selected if ~undefined(sun_bins) then begin if sun_bins[0] ne -1 then begin sun_mask[sun_bins]=0 endif endif else begin ;TBD: This decontamination set may be incorrect for electrons...need to confirm with Jim M(pcruce 2013-03-11) sun_mask[[0,8,16,24,32,33,40,47,48,55,56,57]] = 0 endelse start_time=systime(/sec) dprint,"Loading Raw Data",dlevel=2 dprint,"DATATYPE = " + datatype,dlevel=2 dprint,"PROBE = " + probe,dlevel=2 dprint,"TIMERANGE = " + time_string(trange),dlevel=2 dprint,"ENERGIES = " + strjoin(strtrim(energies,2),', '),dlevel=2 dprint,"SUN BINS = " + strjoin(strtrim(where(~sun_mask),2),', '),dlevel=2 ;Load raw data dist_sst = thm_part_dist_array(probe=probe,type=datatype,trange=trange,/sst_cal,method_clean='manual',sun_bins=sun_mask,_extra=ex) dist_esa = thm_part_dist_array(probe=probe,type='pe'+strmid(datatype,2,1)+'f',trange=trange,/bgnd_remove) dprint,"Converting to flux",dlevel=2 ; ;change into flux units so that data can be interpolated ;don't use eflux because energy variances in SST can make match between SST thetas more troublesome thm_part_conv_units,dist_sst,units='flux' thm_part_conv_units,dist_esa,units='flux' ;Interpolate ESA & SST data onto the same time grid dprint,"Interpolating ESA data to SST times",dlevel=2 thm_part_time_interpolate,dist_esa,dist_sst,error=time_interp_error if time_interp_error then begin dprint,'ERROR: performing ESA->SST time interpolation',dlevel=0 return endif ;spherical interpolation of ESA look directions to SST dprint,"Interpolating ESA data to SST look directions (This may take a while...)",dlevel=2 thm_part_sphere_interpolate,dist_esa,dist_sst,error=sphere_interp_error if sphere_interp_error then begin dprint,'ERROR: performing ESA->SST spherical interpolation',dlevel=0 return endif ;energy interpolation SST->ESA(fills gap) and SST->SST, so that all look directions share same energy grid dprint,"Interpolating SST energies to regular grid",dlevel=2 thm_part_energy_interpolate,dist_sst,dist_esa,energies,error=energy_interp_error if energy_interp_error then begin dprint,'ERROR: performing SST->ESA energy interpolation',dlevel=0 return endif end_time=systime(/sec) dprint,"SST Processing complete. Total runtime: " + strtrim(end_time-start_time) + ' secs',dlevel=2 ;cleanup dist_data=dist_sst undefine,dist_sst undefine,dist_esa ;set no error occurred state error=0 end