Blame view

LabTools/IRAP/JPB/phangs_extract_seds.pro 7.18 KB
9b0b6d7e   Jean-Philippe Bernard   finished implemen...
1
2
PRO phangs_extract_seds,source_name=source_name $
											,resolution_filter=resolution_filter $
9b37a060   Jean-Philippe Bernard   improved for smoo...
3
											,reset_seds=reset_seds $
9b0b6d7e   Jean-Philippe Bernard   finished implemen...
4
											,help=help
d8b7c983   Jean-Philippe Bernard   First commit
5

6fd06be5   Jean-Philippe Bernard   improved
6
7
8
9
10
11
12
13
;+
; NAME:
;    phangs_extract_seds
; PURPOSE:
;    extract SEDs in Muse Voronoi bins
; CATEGORY:
;    PHANGS ISRF
; CALLING SEQUENCE:
9b37a060   Jean-Philippe Bernard   improved for smoo...
14
;    phangs_extract_seds[,source_name=][,/save][,/reset_seds]
6fd06be5   Jean-Philippe Bernard   improved
15
16
17
18
19
20
21
22
23
; INPUTS:
;    None
; OPTIONAL INPUT PARAMETERS:
;    source_name            : source name (default = 'ngc0628')
; OUTPUTS:
;    None
; OPTIONAL OUTPUT PARAMETERS:
;    None
; ACCEPTED KEY-WORDS:
9b37a060   Jean-Philippe Bernard   improved for smoo...
24
25
26
;    help       = If set, print this help
;	   nostop     = if set, does not stop
;    reset_seds = if set, removes all SED saved files from disk and recomputes all.
6fd06be5   Jean-Philippe Bernard   improved
27
28
29
; COMMON BLOCKS:
;    None
; SIDE EFFECTS:
9b37a060   Jean-Philippe Bernard   improved for smoo...
30
;    The following files are written, if they do not already exist (unless /reset_seds is used) :
9b0b6d7e   Jean-Philippe Bernard   finished implemen...
31
;    _seds_indices.sav
6fd06be5   Jean-Philippe Bernard   improved
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
;    _jwst_seds_muse_pixels.sav
;    _muse_seds_muse_pixels.sav
;    _astrosat_seds_muse_pixels.sav
;    _herschel_seds_muse_pixels.sav
;    _all_seds_muse_pixels.sav
; RESTRICTIONS:
;    None
; PROCEDURE:
;    
; EXAMPLES
;	phangs_extract_seds,source_name='ngc0628'
; 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_extract_seds'
  goto,the_end
ENDIF
d8b7c983   Jean-Philippe Bernard   First commit
53
54
55
56

use_source_name='ngc0628'
IF keyword_set(source_name) THEN use_source_name=source_name

9b0b6d7e   Jean-Philippe Bernard   finished implemen...
57
58
59
60
61
reso_str=''
IF keyword_set(resolution_filter) THEN BEGIN
		reso_str='_'+resolution_filter
ENDIF

d8b7c983   Jean-Philippe Bernard   First commit
62
63
data_dir=!phangs_data_dir+'/ISRF/WORK/'

9b37a060   Jean-Philippe Bernard   improved for smoo...
64
65
66
67
68
69
70
71
72
73
74
75
76
IF keyword_set(reset_seds) THEN BEGIN
  files_2b_removed=data_dir+use_source_name+'*seds_muse_pixels*'+reso_str+'.sav'
  str='rm '+files_2b_removed
  message,'spawning '+str,/continue
  ;stop
  spawn,str
  files_2b_removed=data_dir+use_source_name+'*_seds_indices*'+reso_str+'.sav'
  str='rm '+files_2b_removed
  message,'spawning '+str,/continue
  ;stop
  spawn,str  
ENDIF

d8b7c983   Jean-Philippe Bernard   First commit
77
78
extract_seds:

d175a44a   Jean-Philippe Bernard   improved
79
80
81
82
83
84
85
file=data_dir+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
d8b7c983   Jean-Philippe Bernard   First commit
86
87
88
89
90
91
92
;% 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.
d175a44a   Jean-Philippe Bernard   improved
93
94
95
96
97
98
99
file=data_dir+use_source_name+'_jwst_images'+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
9b37a060   Jean-Philippe Bernard   improved for smoo...
100
101
102
103
;% RESTORE: Restored variable: JWST_IMAGES.
;% RESTORE: Restored variable: FILTERS.
;% RESTORE: Restored variable: HREF.
;% RESTORE: Restored variable: NHCO.
d175a44a   Jean-Philippe Bernard   improved
104
105
106
107
108
109
110
file=data_dir+use_source_name+'_astrosat_images'+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     ;changed to astrosat_images
d8b7c983   Jean-Philippe Bernard   First commit
111
112
113
;% RESTORE: Restored variable: ASTROSAT_IMAGES.
;% RESTORE: Restored variable: ASTROSAT_FILTERS.
;% RESTORE: Restored variable: HREF.
d175a44a   Jean-Philippe Bernard   improved
114
115
116
117
118
119
120
file=data_dir+use_source_name+'_muse_filters_images'+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    ;changed to muse_images
6fd06be5   Jean-Philippe Bernard   improved
121
122
123
;% RESTORE: Restored variable: MUSE_IMAGES.
;% RESTORE: Restored variable: MUSE_FILTERS.
;% RESTORE: Restored variable: HREF.
d175a44a   Jean-Philippe Bernard   improved
124
125
126
127
128
129
130
file=data_dir+use_source_name+'_herschel_images'+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
6fd06be5   Jean-Philippe Bernard   improved
131
132
133
;% RESTORE: Restored variable: HERSCHEL_IMAGES.
;% RESTORE: Restored variable: HERSCHEL_FILTERS.
;% RESTORE: Restored variable: HREF.
d8b7c983   Jean-Philippe Bernard   First commit
134

9b0b6d7e   Jean-Philippe Bernard   finished implemen...
135
136
137
138
139
help,jwst_images,astrosat_images,muse_images,herschel_images


;stop

9b37a060   Jean-Philippe Bernard   improved for smoo...
140
;This is the file used to store seds indices
9b0b6d7e   Jean-Philippe Bernard   finished implemen...
141
file_save_indices=data_dir+use_source_name+'_seds_indices'+reso_str+'.sav'
d8b7c983   Jean-Philippe Bernard   First commit
142

9b37a060   Jean-Philippe Bernard   improved for smoo...
143
;This is the file used to save JWST seds in Muse voronoi bins
9b0b6d7e   Jean-Philippe Bernard   finished implemen...
144
file_save=data_dir+use_source_name+'_jwst_seds_muse_pixels'+reso_str+'.sav'
6fd06be5   Jean-Philippe Bernard   improved
145
res=file_info(file_save)
9b0b6d7e   Jean-Philippe Bernard   finished implemen...
146

6fd06be5   Jean-Philippe Bernard   improved
147
IF not res.exists THEN BEGIN
9b0b6d7e   Jean-Philippe Bernard   finished implemen...
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
	;stop
	all_seds=extract_all_muse_phangs_seds(use_source_name,voronoi_id,jwst_images,filters,indices=all_seds_indices,counts=counts)
	save,all_seds,file=file_save
	message,'Saved '+file_save,/info
	save,all_seds_indices,file=file_save_indices
	message,'Saved '+file_save_indices,/info	
ENDIF ELSE BEGIN
	message,'File '+file_save+' already exist',/continue
	stop
ENDELSE

;stop

restore,file_save_indices,/verb  ;just to get the all_seds_indices variable
;% RESTORE: Restored variable: ALL_SEDS_INDICES
6fd06be5   Jean-Philippe Bernard   improved
163

9b37a060   Jean-Philippe Bernard   improved for smoo...
164
;==== extract Muse SEDs, using previously computed all_seds_indices
9b0b6d7e   Jean-Philippe Bernard   finished implemen...
165
file_save=data_dir+use_source_name+'_muse_seds_muse_pixels'+reso_str+'.sav'
6fd06be5   Jean-Philippe Bernard   improved
166
167
res=file_info(file_save)
IF not res.exists THEN BEGIN
9b0b6d7e   Jean-Philippe Bernard   finished implemen...
168
169
170
	all_seds=extract_all_muse_phangs_seds(use_source_name,voronoi_id,muse_images,muse_filters,use_these_indices=all_seds_indices,counts=counts)
	save,all_seds,file=file_save
	message,'Saved '+file_save,/info	
9b37a060   Jean-Philippe Bernard   improved for smoo...
171
172
173
174
ENDIF ELSE BEGIN
	message,'File '+file_save+' already exist',/continue
	stop
ENDELSE
6fd06be5   Jean-Philippe Bernard   improved
175

9b0b6d7e   Jean-Philippe Bernard   finished implemen...
176
file_save=data_dir+use_source_name+'_astrosat_seds_muse_pixels'+reso_str+'.sav'
6fd06be5   Jean-Philippe Bernard   improved
177
178
res=file_info(file_save)
IF not res.exists THEN BEGIN
9b0b6d7e   Jean-Philippe Bernard   finished implemen...
179
180
181
	all_seds=extract_all_muse_phangs_seds(source_name,voronoi_id,astrosat_images,astrosat_filters,use_these_indices=all_seds_indices,counts=counts)
	save,all_seds,file=file_save
	message,'Saved '+file_save,/info	
9b37a060   Jean-Philippe Bernard   improved for smoo...
182
183
184
185
ENDIF ELSE BEGIN
	message,'File '+file_save+' already exist',/continue
	stop
ENDELSE
6fd06be5   Jean-Philippe Bernard   improved
186

9b0b6d7e   Jean-Philippe Bernard   finished implemen...
187
file_save=data_dir+use_source_name+'_herschel_seds_muse_pixels'+reso_str+'.sav'
6fd06be5   Jean-Philippe Bernard   improved
188
189
res=file_info(file_save)
IF not res.exists THEN BEGIN
9b0b6d7e   Jean-Philippe Bernard   finished implemen...
190
191
192
	all_seds=extract_all_muse_phangs_seds(source_name,voronoi_id,herschel_images,herschel_filters,use_these_indices=all_seds_indices,counts=counts)
	save,all_seds,file=file_save
	message,'Saved '+file_save,/info	
9b37a060   Jean-Philippe Bernard   improved for smoo...
193
194
195
196
ENDIF ELSE BEGIN
	message,'File '+file_save+' already exist',/continue
	stop
ENDELSE
d8b7c983   Jean-Philippe Bernard   First commit
197
198
199

;==== The following is not really useful, can be done through SED aggregation later
;==== However, not equivalent to the above, because of undefined pixels in some of the images, and the way this is handled by sed extractor
6fd06be5   Jean-Philippe Bernard   improved
200
201
;stop

9b0b6d7e   Jean-Philippe Bernard   finished implemen...
202
file_save=data_dir+use_source_name+'_all_seds_muse_pixels'+reso_str+'.sav'
6fd06be5   Jean-Philippe Bernard   improved
203
204
205
206
207
208
209
210
211
212
213
214
215
res=file_info(file_save)
IF not res.exists THEN BEGIN
	use_filters=[astrosat_filters,muse_filters,filters,herschel_filters]
	use_Nfilters=n_elements(use_filters)
	use_images=fltarr([sxpar(href,'NAXIS1'),sxpar(href,'NAXIS2'),2,use_Nfilters])
	from=0L & to=from+n_elements(filters)-1
	use_images[*,*,*,from:to]=jwst_images
	from=to+1 & to=from+n_elements(muse_filters)-1
	use_images[*,*,*,from:to]=muse_images
	from=to+1 & to=from+n_elements(astrosat_filters)-1
	use_images[*,*,*,from:to]=astrosat_images
	from=to+1 & to=from+n_elements(herschel_filters)-1
	use_images[*,*,*,from:to]=herschel_images
9b0b6d7e   Jean-Philippe Bernard   finished implemen...
216
217
218
	all_seds=extract_all_muse_phangs_seds(use_source_name,voronoi_id,use_images,use_filters,indices=all_seds_indices,counts=counts)
	save,all_seds,file=file_save
	message,'Saved '+file_save,/info
9b37a060   Jean-Philippe Bernard   improved for smoo...
219
220
221
222
ENDIF ELSE BEGIN
	message,'File '+file_save+' already exist',/continue
	stop
ENDELSE
6fd06be5   Jean-Philippe Bernard   improved
223
224

the_end:
d8b7c983   Jean-Philippe Bernard   First commit
225
226

END