;+ ; This procedure retrieves a total power scan. This code should ; be used as a template for the user who may wish to develop more sophisticated ; calibration schemes. ; ; The required parameter is the scan number. Arguments to identify the IF number, ; polarization number and feed number are optional. The ; program calculates Tsys based on the Tcal values, and cal_on/cal_off phases. ; ;

; All averaging is done using dcaccum ; and accumave. This means that integrations ; are weighted using the default weight given in dcaccum. To turn off this weighting ; so that all integrations have equal weight in the average, use the /noweight flag. ; ; @param scan {in}{required}{type=integer} M&C scan number ; @keyword ifnum {in}{optional}{type=integer} IF number (starting with 0) ; @keyword intnum {in}{optional}{type=integer} integration number (starting with 0) ; @keyword plnum {in}{optional}{type=integer} polarization number (0 or 1) ; @keyword fdnum {in}{optional}{type=integer} feed number (default 0) ; @keyword noweight {in}{optional}{type=flag} if set, the default ; weighting is turned off and all integrations are averaged with the ; same weight (1.0). ; ; @version $Id: gettp.pro,v 1.7 2005/05/30 04:03:43 bgarwood Exp $ ;- pro gettp,scan,ifnum=ifnum,intnum=intnum,plnum=plnum,fdnum=fdnum,noweight=noweight compile_opt idl2 if (n_elements(scan) eq 0 ) then begin message, 'The scan number is required', /info return endif if not !g.lineio->is_data_loaded() then begin message,'No line data is attached yet, use filein or dirin.',/info return endif ; set defaults if n_elements(ifnum) eq 0 then ifnum = 0 if n_elements(plnum) eq 0 then plnum = 0 if n_elements(fdnum) eq 0 then fdnum = 0 if keyword_set(noweight) then weight = 1.0 ; else undefined and use default weight ; Check if scan number is valid validscans = get_scan_numbers() if total(validscans eq scan, /integer) gt 1 then $ message,"Warning: More than one scan with that scan number is in the data file.",/info if total(validscans eq scan, /integer) eq 0 then begin message,"That scan is not available.",/info return endif ; check parameters info = scan_info(scan) if info.n_switching_states ne 2 then begin message,string("This does not appear to be a total power scan."),/info return endif if ifnum lt 0 or ifnum gt (info.n_ifs-1) then begin sifnum = strcompress(string(ifnum),/remove_all) snif = strcompress(string(info.n_ifs),/remove_all) message,"Illegal IF identifier: " + sifnum + ". This scan has " + snif + " IFs, zero-indexed.", /info return endif if plnum lt 0 or plnum gt (info.n_polarizations-1) then begin spol = strcompress(string(plnum),/remove_all) snpol = strcompress(string(info.n_polarizations),/remove_all) message, "Invalid polarization identifier: " + spol + ". This scan has " + snpol + " polarizations, zero-indexed.", /info return endif if fdnum lt 0 or fdnum gt (info.n_feeds-1) then begin message,"Invalid feed: " + strcompress(string(fdnum),/remove_all) + $ ". This scan has " + strcompress(string(info.n_feeds),/remove_all) + " feeds, zero-indexed.",/info return endif thispol = info.polarizations[plnum] thisfeed = info.feeds[fdnum] ; Retrieve all the data necessary to satisfy this request singleInt = n_elements(intnum) eq 1 expectedCount = singleInt ? 1 : info.n_integrations if singleInt then begin if intnum ge 0 and intnum le (info.n_integrations-1) then begin data = !g.lineio->get_spectra(count,scan=scan,feed=thisfeed,ifnum=ifnum,pol=thispol,int=intnum) endif else begin message,"Integration number out of range",/info return endelse endif else begin data = !g.lineio->get_spectra(count,scan=scan,feed=thisfeed,ifnum=ifnum,pol=thispol) endelse if count le 0 then begin message,"No data found, this should never happen, can not continue.",/info return endif sigoff = where(data.cal_state eq 0, countOff) sigon = where(data.cal_state eq 1, countOn) if (countOff ne expectedCount or countOff ne countOn) then begin message,"Unexpected number of spectra retrieved for some or all of the switching phases, can not continue.",/info data_free, data return endif ; copy first element into !g.s[0] as template to hold the result old_frozen = !g.frozen freeze set_data_container,data[0] if singleInt then begin dotpint,data[sigoff],data[sigon],ret_tsys endif else begin thisaccum = {accum_struct} for i = 0,(info.n_integrations-1) do begin dotpint,data[sigoff[i]],data[sigon[i]],ret_tsys dcaccum,thisaccum,!g.s[0],weight=weight endfor naccum1 = thisaccum.n accumave,thisaccum, thisave, /quiet if naccum1 ne info.n_integrations then begin message,'unexpected problems in obtaining the average over integrations, can not continue',/info ; clean up if old_frozen eq 1 then freeze else unfreeze data_free, thisave accumclear, thisaccum data_free, data return endif set_data_container,thisave accumclear, thisaccum data_free, thisave endelse print,scan,ret_tsys,format='("Scan: ",i5," Tsys: ",f7.2)' data_free,data if old_frozen eq 1 then freeze else unfreeze if !g.frozen eq 0 then show end ;+ ; This procedure calibrates a single integration from a total power scan. ; This is currently an internal function used only by getps. ; ; @param sig_off {in}{required}{type=spectrum} An uncalibrated ; spectrum from with the cal off. ; @param sig_on {in}{required}{type=spectrum} An uncalibrated ; spectrum from with the cal on. ; ; @private ; ; @version $Id: gettp.pro,v 1.7 2005/05/30 04:03:43 bgarwood Exp $ ;- pro dotpint,sig_off,sig_on,ret_tsys compile_opt idl2 Tsys_sig = *sig_off.data_ptr/(*sig_on.data_ptr - *sig_off.data_ptr)*sig_off.mean_tcal ; Use the inner 80% of data to calculate mean Tsys pct10 = 0.1*n_elements(Tsys_sig) pct90 = n_elements(Tsys_sig)-pct10 mean_Tsys_sig = mean(Tsys_sig[pct10:pct90]) sig = (*sig_off.data_ptr + *sig_on.data_ptr)/2.0 !g.s[0].tsys = mean_Tsys_sig *!g.s[0].data_ptr = sig ret_tsys = mean_Tsys_sig end