Blame view

src/idl/dustem_plugin_modify_dust_polx.pro 3.55 KB
ff75b39d   Ilyes Choubani   minor update
1
2
3
4
5
FUNCTION dustem_plugin_modify_dust_polx, key=key, val=val, scope=scope, paramtag=paramtag, help=help

;+
; NAME:
;    dustem_plugin_modify_dust_polx
6a523633   Annie Hughes   unknown
6
;
ff75b39d   Ilyes Choubani   minor update
7
; PURPOSE:
6a523633   Annie Hughes   unknown
8
9
;    modifies Extinction Stokes Q,U values for dust polarization in st according to the given keywords and values
;
ff75b39d   Ilyes Choubani   minor update
10
; CATEGORY:
6a523633   Annie Hughes   unknown
11
12
;    DustEMWrap, Plugin, Mid-level, Distributed
;
ff75b39d   Ilyes Choubani   minor update
13
14
; CALLING SEQUENCE:
;    a=dustem_plugin_modify_dust_polx(st,[key=][val=][,scope=][,paramtag=][,/help])
6a523633   Annie Hughes   unknown
15
;
ff75b39d   Ilyes Choubani   minor update
16
17
; INPUTS:
;    st = dustem structure
6a523633   Annie Hughes   unknown
18
;
ff75b39d   Ilyes Choubani   minor update
19
20
21
; OPTIONAL INPUT PARAMETERS:
;    key  = input parameter numbers (first = polarization fraction in %, default=1.%, second=polarization angle, default=0.)
;    val  = input parameter values
6a523633   Annie Hughes   unknown
22
;
ff75b39d   Ilyes Choubani   minor update
23
24
; OUTPUTS:
;    out = array containing the stokes emission parameters associated to the dust/synchrotron component or a concatenated version for both
6a523633   Annie Hughes   unknown
25
;
ff75b39d   Ilyes Choubani   minor update
26
27
28
; OPTIONAL OUTPUT PARAMETERS:
;    scope = if set, returns only the scope of the pluggin
;    paramtag = if set, returns only the parameter tags
6a523633   Annie Hughes   unknown
29
;
ff75b39d   Ilyes Choubani   minor update
30
31
; ACCEPTED KEY-WORDS:
;    help                  = if set, print this help
6a523633   Annie Hughes   unknown
32
;
ff75b39d   Ilyes Choubani   minor update
33
34
; COMMON BLOCKS:
;    None
6a523633   Annie Hughes   unknown
35
;
ff75b39d   Ilyes Choubani   minor update
36
37
; SIDE EFFECTS:
;    None
6a523633   Annie Hughes   unknown
38
;
ff75b39d   Ilyes Choubani   minor update
39
40
41
; RESTRICTIONS:
;    The dustem fortran code must be installed
;    The dustem idl wrapper must be installed
6a523633   Annie Hughes   unknown
42
43
44
45
46
;
; MODIFICATION HISTORY:
;    Written by IC 2022
;    Evolution details on the DustEMWrap gitlab.
;    See http://dustemwrap.irap.omp.eu/ for FAQ and help.  
ff75b39d   Ilyes Choubani   minor update
47
48
;-

6a523633   Annie Hughes   unknown
49

ff75b39d   Ilyes Choubani   minor update
50
51
52
53
54
55
IF keyword_set(help) THEN BEGIN
  doc_library,'dustem_plugin_modify_dust_polx'
  out=0.
  GOTO,the_end
ENDIF
       
01612ee4   Ilyes Choubani   General update: I...
56

ff75b39d   Ilyes Choubani   minor update
57
IF keyword_set(scope) THEN BEGIN
91e991b5   Ilyes Choubani   Applying correcti...
58
    
ff75b39d   Ilyes Choubani   minor update
59
    out=0.
91e991b5   Ilyes Choubani   Applying correcti...
60
    GOTO, the_end
ff75b39d   Ilyes Choubani   minor update
61
62
63
ENDIF 

IF keyword_set(paramtag) THEN BEGIN
91e991b5   Ilyes Choubani   Applying correcti...
64
    
ff75b39d   Ilyes Choubani   minor update
65
    out=0.
91e991b5   Ilyes Choubani   Applying correcti...
66
    GOTO, the_end
ff75b39d   Ilyes Choubani   minor update
67
68
ENDIF 

01612ee4   Ilyes Choubani   General update: I...
69
;Retrieving this system variable (dustem output) 
55275be6   Ilyes Choubani   allowing no_obj p...
70
71
72
73
if ~isa(!dustem_current) then begin
    out =0 
    goto, the_end 
ENDIF else st=(*!dustem_current)
01612ee4   Ilyes Choubani   General update: I...
74

ff75b39d   Ilyes Choubani   minor update
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
;below are the default values for the plugin parameters
smallp_fact=1.     ;This is the default multiplicative factore to the dust polarization
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_ext = psi ; setting psi from pd.  !dustem_psi here helps for the plotting.   
ENDIF

POLEXT_spec=((st.polext).ext_tot)* (*!dustem_HCD)/1.0e21 ;*fact   ; This is the polarized emission P
EXT_spec=((st.ext).ext_tot)* (*!dustem_HCD)/1.0e21 ;*fact      ; This is the total intensity emission I
    
Nwaves=(size(EXT_spec))[1]

IF !run_pol THEN BEGIN
    
    ;THIS FALSE CORRECT  IT USING POLEXT_spec
    ;POLEXT_spec.abs_grain[2,*]
    ind_ngtv_plxt = where (POLEXT_spec LT 0, ct_ngtv_plxt)
    
    IF ct_ngtv_plxt NE 0 THEN (POLEXT_spec)[ind_ngtv_plxt] = 0.
        
        
ENDIF

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

indx = where(EXT_spec ne 0, countx)
6a523633   Annie Hughes   unknown
106
107
frac_model = POLEXT_spec*0.
if countx ne 0 then frac_model[indx] = POLEXT_spec[indx]/EXT_spec[indx] ;This is the polarization fraction in the model
ff75b39d   Ilyes Choubani   minor update
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127


frac_used=frac_model*smallp_fact

psi_used = replicate(psi,Nwaves)

polar_ippsi2iqu,EXT_spec,QEXT_spec,UEXT_spec,frac_used,psi_used


out=fltarr(Nwaves,3) ; modified this. This is the only plugin that has this number of outputs.

;degtorad = !pi/180

out[*,0]=EXT_spec
out[*,1]=QEXT_spec
out[*,2]=UEXT_spec
; out[*,3]=frac_used
; ;out[*,4]=0.5*atan(U,Q)/degtorad
; out[*,4]=psi_used

ff75b39d   Ilyes Choubani   minor update
128
129
130
131

RETURN, out

the_end:
91e991b5   Ilyes Choubani   Applying correcti...
132
133
134
scope='REPLACE_POLEXT'
paramtag=['p','Psi (deg)']

ff75b39d   Ilyes Choubani   minor update
135
136

END