Blame view

LabTools/IRAP/JPB/phangs_smooth_muse_isrf.pro 5.58 KB
9b0b6d7e   Jean-Philippe Bernard   finished implemen...
1
2
3
4
PRO phangs_smooth_muse_isrf,source_name $
					       ,resolution_filter=resolution_filter $
					       ,save=save $
					       ,test=test
26556ecf   Jean-Philippe Bernard   First commit
5

9b0b6d7e   Jean-Philippe Bernard   finished implemen...
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
;+
; NAME:
;    phangs_smooth_muse_isrf
; PURPOSE:
;    Smoothes ISRF to a given resolution
; CATEGORY:
;    PHANGS ISRF
; CALLING SEQUENCE:
;    phangs_smooth_muse_isrf,source_name[,resolution_filter=][,/save][,/test]=
; INPUTS:
;    source_name            : source name
; OPTIONAL INPUT PARAMETERS:
;    resolution_filter      :resolution of the filter to be used for smoothing (defaults=)
; OUTPUTS:
;    None
; OPTIONAL OUTPUT PARAMETERS:
;    None
; ACCEPTED KEY-WORDS:
;    save      = If set, saves results
;    help      = If set, print this help
; COMMON BLOCKS:
;    None
; SIDE EFFECTS:
;    The following files are written, if they do not already exist:
;    _isrf_min_prediction_*.sav
; RESTRICTIONS:
;    None
; PROCEDURE:
;    
; EXAMPLES
;	phangs_smooth_muse_isrf,'ngc0628',reso_filter='SPIRE3'
; MODIFICATION HISTORY:
;    Written by J.-Ph. Bernard (2023)
;    Evolution details on the DustEMWrap gitlab.
;    See http://dustemwrap.irap.omp.eu/ for FAQ and help.  
;-

IF keyword_set(help) THEN BEGIN
  doc_library,'phangs_smooth_muse_isrf'
  goto,the_end
ENDIF
26556ecf   Jean-Philippe Bernard   First commit
47
48
49
50

dustem_define_la_common
dustem_init

8cfdf0b6   Jean-Philippe Bernard   improved
51
52
53
54
55
56
file=!phangs_data_dir+'/ISRF/WORK/'+source_name+'_ref_header.sav'
st_info=file_info(file)
IF st_info.exists NE 1 THEN BEGIN
	message,'Could not find '+file,/continue
	stop
ENDIF
26556ecf   Jean-Philippe Bernard   First commit
57
58
59
restore,file,/verb
;% RESTORE: Restored variable: HREF.

8cfdf0b6   Jean-Philippe Bernard   improved
60
61
62
63
64
65
file=!phangs_data_dir+'/ISRF/WORK/'+source_name+'_isrf_min_prediction.sav'
st_info=file_info(file)
IF st_info.exists NE 1 THEN BEGIN
	message,'Could not find '+file,/continue
	stop
ENDIF
26556ecf   Jean-Philippe Bernard   First commit
66
67
68
69
70
71
restore,file,/verb
;% RESTORE: Restored variable: ISRFS.
;% RESTORE: Restored variable: G0S.
;% RESTORE: Restored variable: OBJECT_DISTANCE.
;% RESTORE: Restored variable: OBJECT_THICKNESS.
;% RESTORE: Restored variable: USE_SOURCE_NAME.
9b0b6d7e   Jean-Philippe Bernard   finished implemen...
72
file=!phangs_data_dir+'/ISRF/WORK/'+source_name+'_seds_indices.sav'
8cfdf0b6   Jean-Philippe Bernard   improved
73
74
75
76
77
st_info=file_info(file)
IF st_info.exists NE 1 THEN BEGIN
	message,'Could not find '+file,/continue
	stop
ENDIF
26556ecf   Jean-Philippe Bernard   First commit
78
restore,file,/verb
9b0b6d7e   Jean-Philippe Bernard   finished implemen...
79
80
81
82
;% RESTORE: Restored variable: ALL_SEDS_INDICES.

;file=!phangs_data_dir+'/ISRF/WORK/'+source_name+'_all_seds_muse_pixels.sav'
;restore,file,/verb
26556ecf   Jean-Philippe Bernard   First commit
83
84
85
86
87
;% RESTORE: Restored variable: ALL_SEDS.
;% RESTORE: Restored variable: ALL_SEDS_INDICES.

Nwav=(size(ISRFS))[1]
Nvor=(size(ISRFS))[2]
33d0e4eb   Jean-Philippe Bernard   improved
88
89

;=== This is to compute the Voronoi bins sizes
26556ecf   Jean-Philippe Bernard   First commit
90
91
vor_num=lonarr(Nvor)
FOR i=0L,Nvor-1 DO BEGIN
9b0b6d7e   Jean-Philippe Bernard   finished implemen...
92
93
94
95
96
97
98
99
	IF ptr_valid(all_seds_indices[i]) THEN BEGIN
		vor_num[i]=n_elements(*all_seds_indices[i])
		IF vor_num[i] EQ 1 THEN BEGIN
			IF *all_seds_indices[i] EQ -1 THEN BEGIN
				vor_num[i]=0L
			ENDIF
	    ENDIF
	ENDIF
26556ecf   Jean-Philippe Bernard   First commit
100
101
ENDFOR
vor_sizes=2.*sqrt(1.*vor_num*sxpar(href,'CDELT2')^2/!pi)   ;FWHM in deg
33d0e4eb   Jean-Philippe Bernard   improved
102
print,minmax(vor_sizes)*60.^2
26556ecf   Jean-Philippe Bernard   First commit
103

33d0e4eb   Jean-Philippe Bernard   improved
104
;stop
ee1fd9a9   Jean-Philippe Bernard   improved in the f...
105
106
107
108
109
110
;==== remove negative values in ISRFs
;ind=where(ISRFs LE 0,count)
;IF count NE 0 THEN BEGIN
;	ISRFs[ind]=0.
;ENDIF

33d0e4eb   Jean-Philippe Bernard   improved
111
112
;==== Make the ISRF cube
message,'Making the ISRF cube',/info
26556ecf   Jean-Philippe Bernard   First commit
113
114
115
116
117
118
119
Nx=sxpar(href,'NAXIS1')
Ny=sxpar(href,'NAXIS2')
ISRF_cube=fltarr(Nx,Ny,Nwav)+la_undef()

im0=ISRF_cube[*,*,0]
ISRF0=fltarr(Nwav)+la_undef()
FOR i=0L,Nvor-1 DO BEGIN
33d0e4eb   Jean-Philippe Bernard   improved
120
121
122
123
	IF i mod 1000 EQ 0 THEN BEGIN
		message,strtrim(1.*i/Nvor*100,2)+' %',/continue
		;stop
	ENDIF
26556ecf   Jean-Philippe Bernard   First commit
124
125
126
127
128
129
	IF vor_num[i] NE 0 THEN BEGIN
		ij=index2ij(*all_seds_indices[i],[Nx,Ny])
		FOR j=0L,vor_num[i]-1 DO ISRF_cube[ij[j,0],ij[j,1],*]=ISRFS[*,i]
	ENDIF
ENDFOR

33d0e4eb   Jean-Philippe Bernard   improved
130
131
;==== smooth the ISRF
use_reso_filter='SPIRE3'
9b0b6d7e   Jean-Philippe Bernard   finished implemen...
132
IF keyword_set(resolution_filter) THEN use_reso_filter=resolution_filter
26556ecf   Jean-Philippe Bernard   First commit
133

33d0e4eb   Jean-Philippe Bernard   improved
134
135
message,'smoothing the ISRF cube',/info
data_reso=3./60./60.
9b0b6d7e   Jean-Philippe Bernard   finished implemen...
136
reso_str='_'+use_reso_filter
33d0e4eb   Jean-Philippe Bernard   improved
137
final_reso=dustem_filter2reso(use_reso_filter)
26556ecf   Jean-Philippe Bernard   First commit
138

33d0e4eb   Jean-Philippe Bernard   improved
139
140
141
142
143
;stop
;in fact degrade_res can degrade resolution of cubes, so ...
;=== That's a test
IF keyword_set(test) THEN BEGIN
	ISRFs=degrade_res(ISRF_cube[*,*,0:2],href,data_reso,final_reso,hout)
bbfe2364   Jean-Philippe Bernard   fixed a bug
144
	test_str='Test'
33d0e4eb   Jean-Philippe Bernard   improved
145
146
ENDIF ELSE BEGIN
	ISRFs=degrade_res(ISRF_cube,href,data_reso,final_reso,hout)
bbfe2364   Jean-Philippe Bernard   fixed a bug
147
	test_str=''
33d0e4eb   Jean-Philippe Bernard   improved
148
149
150
ENDELSE
header=hout
;stop
26556ecf   Jean-Philippe Bernard   First commit
151

9b0b6d7e   Jean-Philippe Bernard   finished implemen...
152
;=== project ISRFs on reference header for given resolution
8cfdf0b6   Jean-Philippe Bernard   improved
153
154
155
156
157
158
file=!phangs_data_dir+'/ISRF/WORK/'+source_name+'_ref_header'+reso_str+'.sav'
st_info=file_info(file)
IF st_info.exists NE 1 THEN BEGIN
	message,'Could not find '+file,/continue
	stop
ENDIF
9b0b6d7e   Jean-Philippe Bernard   finished implemen...
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
restore,file,/verb
;stop

NNx=sxpar(href,'NAXIS1')
NNy=sxpar(href,'NAXIS2')
proj_ISRFs=fltarr(NNx,NNy,Nwav)
i=0L
proj_ISRFs[*,*,i]=project2(header,ISRFs[*,*,i],href,/silent)
;FOR i=1L,Nwav-1 DO BEGIN
FOR i=1L,(size(ISRFs))[3]-1 DO BEGIN
	proj_ISRFs[*,*,i]=project2(header,ISRFs[*,*,i],href,/previous_lut,/silent)
ENDFOR

;stop
;==== put back ISRFs on voronoi bins
8cfdf0b6   Jean-Philippe Bernard   improved
174
175
176
177
178
179
180
file=!phangs_data_dir+'/ISRF/WORK/'+use_source_name+'_muse_data'+reso_str+'.sav'
st_info=file_info(file)
IF st_info.exists NE 1 THEN BEGIN
	message,'Could not find '+file,/continue
	stop
ENDIF
restore,file,/verb
9b0b6d7e   Jean-Philippe Bernard   finished implemen...
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
;% RESTORE: Restored variable: ST_TEMPLATES.
;% RESTORE: Restored variable: ST_MUSE_WEIGHTS.
;% RESTORE: Restored variable: VORONOI_ID.
;% RESTORE: Restored variable: AGE_VALUES.
;% RESTORE: Restored variable: METALICITY_VALUES.
;% RESTORE: Restored variable: BINS.
;% RESTORE: Restored variable: HREF.
NNvor=max(voronoi_id)+1
out_ISRFS=fltarr(Nwav,NNvor)
FOR i=0L,NNvor-1 DO BEGIN
	ind=where(voronoi_id EQ i,count)
	IF count NE 1 THEN BEGIN
		message,'count should be 1',/continue
		stop
	ENDIF ELSE BEGIN
		ij=index2ij(ind,[NNx,NNy])
		out_ISRFS[*,i]=reform(proj_ISRFs[ij[0,0],ij[0,1],*])
	ENDELSE
ENDFOR
;ISRFs=proj_ISRFs
ISRFs=out_ISRFs

33d0e4eb   Jean-Philippe Bernard   improved
203
204
IF keyword_set(save) THEN BEGIN
	file_save=!phangs_data_dir+'/ISRF/WORK/'+test_str+source_name+'_isrf_min_prediction'+reso_str+'.sav' 
9b0b6d7e   Jean-Philippe Bernard   finished implemen...
205
	save,ISRFs,href,use_reso_filter,file=file_save
33d0e4eb   Jean-Philippe Bernard   improved
206
207
	message,'Saved '+file_save,/continue
ENDIF
26556ecf   Jean-Philippe Bernard   First commit
208

9b0b6d7e   Jean-Philippe Bernard   finished implemen...
209
210
the_end:
;stop
26556ecf   Jean-Philippe Bernard   First commit
211
212

END