dustem_fillup_systvar_from_fits.pro 3.61 KB
PRO dustem_fillup_systvar_from_fits,syst_var,str_input_SED,used_pol

	Nsed=n_elements(str_input_SED)
	sed=dustem_initialize_internal_sed(Nsed)

	(syst_var).sed=ptr_new(sed)

	(*syst_var.sed).instru_names=dustem_filter2instru(str_input_SED.filter)
	(*syst_var.sed).filt_names=strtrim(str_input_SED.filter,2)
	(*syst_var.sed).wav=str_input_SED.wavelength
	(*syst_var.sed).values=str_input_SED.STOKESI
	(*syst_var.sed).sigma=la_power(str_input_SED.varianceII,0.5)

	IF used_pol THEN BEGIN
		;stop
		;===== note: those should include only points with polarization data, not all sed points
		indq=where(str_input_SED.STOKESQ NE la_undef(),Nqsed)
        indu=where(str_input_SED.STOKESU NE la_undef(),Nused)
        qsed=dustem_initialize_internal_sed(Nqsed)
        used=dustem_initialize_internal_sed(Nused)
        indpolar=where(str_input_SED.STOKESU NE la_undef() AND str_input_SED.STOKESQ NE la_undef(),Npolar)
        
        psi_sed=dustem_initialize_internal_sed(Npolar)
        smallp_sed=dustem_initialize_internal_sed(Npolar)
        largep_sed=dustem_initialize_internal_sed(Npolar)

		syst_var.qsed=ptr_new(qsed)
		syst_var.used=ptr_new(used)
		(*syst_var.qsed).instru_names=dustem_filter2instru(str_input_SED[indq].filter)
		(*syst_var.qsed).filt_names=strtrim(str_input_SED[indq].filter,2)
		(*syst_var.qsed).wav=str_input_SED[indq].wavelength
		(*syst_var.qsed).values=str_input_SED[indq].STOKESQ
		(*syst_var.qsed).sigma=la_power(str_input_SED[indq].varianceQQ,0.5)
		;now U
		(*syst_var.used).instru_names=dustem_filter2instru(str_input_SED[indu].filter)
		(*syst_var.used).filt_names=strtrim(str_input_SED[indu].filter,2)
		(*syst_var.used).wav=str_input_SED[indu].wavelength
		(*syst_var.used).values=str_input_SED[indu].STOKESU
		(*syst_var.used).sigma=la_power(str_input_SED[indu].varianceUU,0.5)
		;=== add up dependent fields
        syst_var.psi_em=ptr_new(psi_sed)
        syst_var.polfrac=ptr_new(smallp_sed)
        syst_var.polsed=ptr_new(largep_sed)
		polar_iqu2ippsi,str_input_SED[indpolar].STOKESI,str_input_SED[indpolar].STOKESQ,str_input_SED[indpolar].STOKESU,p,psi,largep=largep
		(*syst_var.psi_em).values=psi
		(*syst_var.polfrac).values=p
		(*syst_var.polsed).values=largep
		CIQ=str_input_SED[indpolar].VARIANCEII & CIQ[*]=0.   ;because input SEDs don't include covariances, yet
		CIU=str_input_SED[indpolar].VARIANCEII & CIU[*]=0.   ;because input SEDs don't include covariances, yet
		CQU=str_input_SED[indpolar].VARIANCEII & CQU[*]=0.   ;because input SEDs don't include covariances, yet
		polar_variance_iqu2ippsi,str_input_SED[indpolar].STOKESI $
								,str_input_SED[indpolar].STOKESQ $
								,str_input_SED[indpolar].STOKESU $
								,str_input_SED[indpolar].VARIANCEII $
								,str_input_SED[indpolar].VARIANCEQQ $
								,str_input_SED[indpolar].VARIANCEUU $
								,CIQ,CIU,CQU,variance_smallp,variance_psi,variance_largep,/lac,snr_largeP=snr_largeP
		
		(*syst_var.psi_em).instru_names=dustem_filter2instru(str_input_SED[indpolar].filter)
		(*syst_var.psi_em).filt_names=strtrim(str_input_SED[indpolar].filter,2)
		(*syst_var.psi_em).wav=str_input_SED[indpolar].wavelength
		
		(*syst_var.polfrac).instru_names = (*syst_var.psi_em).instru_names
		(*syst_var.polfrac).filt_names =  (*syst_var.psi_em).filt_names
		(*syst_var.polfrac).wav = (*syst_var.psi_em).wav
		
		(*syst_var.polsed).instru_names = (*syst_var.psi_em).instru_names
		(*syst_var.polsed).filt_names =  (*syst_var.psi_em).filt_names
		(*syst_var.polsed).wav = (*syst_var.psi_em).wav

		(*syst_var.psi_em).sigma=la_power(variance_psi,0.5)
        (*syst_var.polfrac).sigma=la_power(variance_smallp,0.5)
        (*syst_var.polsed).sigma=la_power(variance_largep,0.5)
	ENDIF
END