dustem_plugin_modify_dust_pol.pro 3.38 KB
FUNCTION dustem_plugin_modify_dust_pol, key=key, val=val, scope=scope, paramtag=paramtag, help=help

;+
; NAME:
;    dustem_plugin_modify_dust_pol
;  
; PURPOSE:
;    Replaces the emission in polarization (Stokes Q,U) with a fixed polarization angle and fraction
;    Q,U to be replaced are computed from the total intensity as:
;    Q=I*val[0]*p*cos(2*val[1])
;    U=I*val[0]*p*sin(2*val[1])
;    where I is the total intensity in the model and p is the polarization fraction in the model 
; CATEGORY:
;    DustEMWrap, Plugin, Mid-level, Distributed
;
; CALLING SEQUENCE:
;    a=dustem_plugin_modify_dust_pol([key=][val=][,scope=][,paramtag=][,paramdefault=][,/help])
;
; INPUTS:
;    st = dustem structure
;
; OPTIONAL INPUT PARAMETERS:
;    key  = input parameter numbers
;           first  = multiplication factor for the polarization fraction
;           second = polarization angle [deg], default=0.
;    val  = input parameter values
; OUTPUTS:
;    out  = array containing the stokes emission parameters associated to the dust/synchrotron component or a concatenated version for both
;
; OPTIONAL OUTPUT PARAMETERS:
;    scope = if set, returns only the scope of the pluggin
;    paramtag = if set, returns only the parameter tags
; ACCEPTED KEY-WORDS:
;    help                  = if set, print this help
; COMMON BLOCKS:
;    None
;
; SIDE EFFECTS:
;    None
;
; RESTRICTIONS:
;    The dustem fortran code must be installed
;    The dustem idl wrapper must be installed
;
; MODIFICATION HISTORY:
;    Written by IC 2022
;    Evolution details on the DustEMWrap gitlab.
;    See http://dustemwrap.irap.omp.eu/ for FAQ and help.  
;-

IF keyword_set(help) THEN BEGIN
  doc_library,'dustem_plugin_modify_dust_pol'
  out=0.
  GOTO,the_end
ENDIF
       
IF keyword_set(scope) THEN BEGIN
    ;scope='REPLACE_POLSED'
    scope='REPLACE_SED'
    out=0
    GOTO, the_end
ENDIF 

IF keyword_set(paramtag) THEN BEGIN
    paramtag=['p',textoidl('\psi')+' [deg]']
    out=0.
    GOTO, the_end
ENDIF 

;Retrieving this sytem variable  (dustem output)  
IF ~isa(!dustem_current) then begin
    out=0
    goto, the_end 
ENDIF ELSE BEGIN
    st=(*!dustem_current)
ENDELSE

;below are the default values for the plugin parameters
smallp_fact=1.     ;This is the default dust polarization factor
psi=0.             ;This is the default polarization angle

IF keyword_set(key) THEN BEGIN 
  ind1=where(key EQ 1,count1)
  ind2=where(key EQ 2,count2)
  IF count1 NE 0 THEN smallp_fact=val[ind1[0]] ; setting smallp from pd - this is another polarization fraction (constant) that is applied to the total dust emission
  IF count2 NE 0 THEN psi=val[ind2[0]]
  !dustem_psi = psi ; setting psi from pd.  !dustem_psi here helps for the plotting.   
ENDIF

fact = 1.e4*(*!dustem_HCD)/(4.*!pi)/(3.e8/1.e-6/((st.polsed).wav))*1.e20/1.e7
P=((st.polsed).em_tot)*fact   ; This is the polarized emission P currently in the model
I=((st.sed).em_tot)*fact      ; This is the total intensity emission I currently in the model
    
Nwaves=(size(I))[1]

;0/0 division in frac
;since we divide by I we only need to avoid its null indices 

frac_model=P*0.
indI = where(I ne 0, countI)
if countI ne 0 then frac_model[indI] = P[indI]/I[indI] ;This is the polarization fraction currently in the model

frac_used=frac_model*smallp_fact

psi_used = replicate(psi,Nwaves)

polar_ippsi2iqu,I,Q,U,frac_used,psi_used

out=fltarr(Nwaves,3)

out[*,0]=I
out[*,1]=Q
out[*,2]=U

RETURN, out

the_end:


END