Blame view

LabTools/IRAP/RM/phangs_make_herschel_images.pro 6.77 KB
9b0b6d7e   Jean-Philippe Bernard   finished implemen...
1
2
3
4
5
6
PRO phangs_make_herschel_images,source_name=source_name $
															 ,save=save $
															 ,show_images=show_images $
															 ,nostop=nostop $
															 ,help=help $
															 ,resolution_filter=resolution_filter
6768fb27   Raphael Maris   First comit
7
8
9

;+
; NAME:
6784b4c7   Jean-Philippe Bernard   modified and comm...
10
;    phangs_make_herschel_images
6768fb27   Raphael Maris   First comit
11
12
13
14
15
; PURPOSE:
;    makes astrosat images usable by the Phangs ISRF project
; CATEGORY:
;    Dustem Phangs
; CALLING SEQUENCE:
6784b4c7   Jean-Philippe Bernard   modified and comm...
16
;    phangs_make_herschel_images[,source_name=][,/save][,/show_images][,/nostop]
6768fb27   Raphael Maris   First comit
17
18
19
20
; INPUTS:
;    None
; OPTIONAL INPUT PARAMETERS:
;    source_name            : source name (default = 'ngc0628')
9b0b6d7e   Jean-Philippe Bernard   finished implemen...
21
;    resolution_filter      : if set makes images at this resolution (default none)
6768fb27   Raphael Maris   First comit
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
; OUTPUTS:
;    None
; OPTIONAL OUTPUT PARAMETERS:
;    None
; ACCEPTED KEY-WORDS:
;    help      = If set, print this help
;    save      = If set, save result
;    show_images= if set, show images
;	 nostop    = if set, does not stop
; COMMON BLOCKS:
;    None
; SIDE EFFECTS:
;    A file is written
; RESTRICTIONS:
;    None
; PROCEDURE:
6784b4c7   Jean-Philippe Bernard   modified and comm...
38
;    input Herschel images are assumed to be in Jy/beam and Jy/pixel for SPIRE and PACS respectively
6768fb27   Raphael Maris   First comit
39
40
;    
; EXAMPLES
6784b4c7   Jean-Philippe Bernard   modified and comm...
41
42
;	phangs_make_herschel_images,source_name='ngc0628',/show,/nostop
;	phangs_make_herschel_images,source_name='ngc0628',/save,/show,/nostop
6768fb27   Raphael Maris   First comit
43
44
45
46
47
48
49
; 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
6784b4c7   Jean-Philippe Bernard   modified and comm...
50
  doc_library,'phangs_make_herschel_images'
6768fb27   Raphael Maris   First comit
51
52
53
54
55
56
  goto,the_end
ENDIF

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

6784b4c7   Jean-Philippe Bernard   modified and comm...
62
63
64
65
dustem_define_la_common
;JPB: I'm runing dustem_init there to get the filter informations into memory
dustem_init

6768fb27   Raphael Maris   First comit
66
;window,0
6784b4c7   Jean-Philippe Bernard   modified and comm...
67
obp=[1.1,0,1.15,1]   ;JPB: see with image_cont20 how this is used. This is an offset position for where the color bar should be drawn.
6768fb27   Raphael Maris   First comit
68
69
win=0L

6784b4c7   Jean-Philippe Bernard   modified and comm...
70
71
72
73
;JPB: modified this as this is the arborescence where the files are located in alma1.
;     make sure you put them in the same arborescence in your PC
;data_dir=!phangs_data_dir+'/phangs_drive/PHANGS_Herschel_JWST_cycle1/'
data_dir=!phangs_data_dir+'/phangs_drive/Archive/Ancillary/herschel/PHANGS_Herschel_v1/'
6768fb27   Raphael Maris   First comit
74

6784b4c7   Jean-Philippe Bernard   modified and comm...
75
save_data_dir=!phangs_data_dir+'/ISRF/WORK/'
6768fb27   Raphael Maris   First comit
76
77

;This is to get the reference header
b09a906c   Jean-Philippe Bernard   improved
78
79
80
81
82
83
84
file=save_data_dir+'ngc0628_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
restore,file,/verb
6784b4c7   Jean-Philippe Bernard   modified and comm...
85
;% RESTORE: Restored variable: HREF.
6768fb27   Raphael Maris   First comit
86

6784b4c7   Jean-Philippe Bernard   modified and comm...
87
88
89
;== I added PMW and PLW, since the data is available on alma1
;name_loc_filters = ['PACS_BLUE','PACS_GREEN','PACS_RED','PSW']
name_loc_filters = ['PACS_BLUE','PACS_GREEN','PACS_RED','PSW','PMW','PLW']
6768fb27   Raphael Maris   First comit
90
91
92
93
herschel_filters=dustem_filter_names2filters(name_loc_filters)
Nherschel_filter=n_elements(herschel_filters)
herschel_images=fltarr(sxpar(href,'NAXIS1'),sxpar(href,'NAXIS2'),2,Nherschel_filter)

6784b4c7   Jean-Philippe Bernard   modified and comm...
94
95
;JPB: added missing SPIRE filters
name_filters = ['pacs70','pacs100','pacs160','spire250','spire350','spire500']
6768fb27   Raphael Maris   First comit
96

6784b4c7   Jean-Philippe Bernard   modified and comm...
97
;=== JPB: added .gz, as this is how files are nammed in alma1 and mrdfits can actually read .gz files (!)
8cd4c352   Jean-Philippe Bernard   improved
98
99
;files=data_dir+use_source_name+'_scanamorphos_v25_'+name_filters+'_0.fits.gz'
files=data_dir+use_source_name+'_scanamorphos_v25_'+name_filters+'_0.fits'
6768fb27   Raphael Maris   First comit
100
101
102
wavs_mic=dustem_filter2wav(herschel_filters)
cmic=3.e14   ;mic/sec

6784b4c7   Jean-Philippe Bernard   modified and comm...
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
;JPB; as I want arrays which all have the same number of elements, I added dummy values (la_undef()) for PACS filters
;spire_beams_as = [450., 795., 1665.] ; in arcsec^2
herschel_beams_as = [la_undef(),la_undef(),la_undef(),450., 795., 1665.] ; in arcsec^2
;JPB: This below
;omega_250 = spire_beams_as[0]*(((1.0/3600.0)*!pi/180.0)^2) ;omega_beam in sr
;omega_350 = spire_beams_as[1]*(((1.0/3600.0)*!pi/180.0)^2) ;omega_beam in sr
;omega_500 = spire_beams_as[2]*(((1.0/3600.0)*!pi/180.0)^2) ;omega_beam in sr
;can be done like this in one line:
;omegas=spire_beams_as*(((1.0/3600.0)*!pi/180.0)^2) ;omega_beam in sr
;JPB: This is the same as above but preserves undefined values
omegas=la_mul(herschel_beams_as,((1.0/3600.0)*!pi/180.0)^2) ;omega_beam in sr
;JPB: This array will tell you which instrument the filter is from (quite useful for your loop later)
instrus=dustem_filter2instru(herschel_filters)

imrange=[-10,100]   ;MJy/sr
6768fb27   Raphael Maris   First comit
118

524e900a   Jean-Philippe Bernard   fixed smoothing I...
119
120
win=0L

6768fb27   Raphael Maris   First comit
121
122
FOR i=0L,Nherschel_filter-1 DO BEGIN
	file=files[i]
b09a906c   Jean-Philippe Bernard   improved
123
124
125
126
127
	st_info=file_info(file)
	IF st_info.exists NE 1 THEN BEGIN
		message,'Could not find '+file,/continue
		stop
	ENDIF
6768fb27   Raphael Maris   First comit
128
129
130
	d_narray=mrdfits(file,0,h)
	d = d_narray[*,*,0]
	d_err = d_narray[*,*,1]
6768fb27   Raphael Maris   First comit
131
 	ind=where(finite(d) NE 1,count)
6768fb27   Raphael Maris   First comit
132
	IF count NE 0 THEN d[ind]=la_undef()
6784b4c7   Jean-Philippe Bernard   modified and comm...
133
134
135
136
137
138
139
140

  ;JPB: look, I've reduced 4 IF statements into 1 statement, and no need to use clumpsy STRPOS
  IF instrus[i] EQ 'SPIRE' THEN BEGIN
  	fact=1.e-6/omegas[i]
  ENDIF ELSE BEGIN
  	steradians=(sxpar(h,'CDELT2')/!radeg)^2   ;pixel in sr
    fact=1.e-6/steradians            ;This is to rescale from /pixel to /sr
  ENDELSE
6784b4c7   Jean-Philippe Bernard   modified and comm...
141
              	
6768fb27   Raphael Maris   First comit
142
 	d=la_mul(d,fact)
6784b4c7   Jean-Philippe Bernard   modified and comm...
143

6784b4c7   Jean-Philippe Bernard   modified and comm...
144
	IF keyword_set(show_images) THEN BEGIN
524e900a   Jean-Philippe Bernard   fixed smoothing I...
145
		window,win & win=win+1
6784b4c7   Jean-Philippe Bernard   modified and comm...
146
147
		image_cont20,d,h,/square,imrange=0,image_color_table='jpbloadct',axis_color_table=1,/silent,tit=tit,off_bar_pos=obp
	ENDIF
9b0b6d7e   Jean-Philippe Bernard   finished implemen...
148
149
150
151
152
153
154
155
156
157
158
159

	reso_str=''
	IF keyword_set(resolution_filter) THEN BEGIN
    ;stop
		reso_str='_'+resolution_filter
		data_reso=dustem_filter2reso(herschel_filters[i])      ;This is undefined in instrument_descritpion.xcat
		final_reso=dustem_filter2reso(resolution_filter)
  	d=degrade_res(d,h,data_reso,final_reso,hout)
  	d_err=degrade_res(d_err,h,data_reso,final_reso,hout)
    h=hout
	ENDIF

6768fb27   Raphael Maris   First comit
160
 	IF sxpar(h,'NAXIS1') NE sxpar(href,'NAXIS1') OR sxpar(h,'NAXIS2') NE sxpar(href,'NAXIS2') THEN BEGIN
6784b4c7   Jean-Philippe Bernard   modified and comm...
161
162
163
     	d=project2(h,d,href,/silent,save_it='/tmp/saved_proj_info.sav')
     	d_err=project2(h,d_err,href,/silent,restore_it='/tmp/saved_proj_info.sav')
  ENDIF
6768fb27   Raphael Maris   First comit
164
	tit=use_source_name+' '+herschel_filters[i]
6784b4c7   Jean-Philippe Bernard   modified and comm...
165
	IF keyword_set(show_images) THEN BEGIN
524e900a   Jean-Philippe Bernard   fixed smoothing I...
166
		window,win & win=win+1
6784b4c7   Jean-Philippe Bernard   modified and comm...
167
		image_cont20,d,href,/square,imrange=imrange,image_color_table='jpbloadct',axis_color_table=1,/silent,tit=tit,off_bar_pos=obp
9b0b6d7e   Jean-Philippe Bernard   finished implemen...
168
		IF not keyword_set(nostop) THEN stop
6784b4c7   Jean-Philippe Bernard   modified and comm...
169
	ENDIF
6768fb27   Raphael Maris   First comit
170
	herschel_images[*,*,0,i]=d
6784b4c7   Jean-Philippe Bernard   modified and comm...
171
	herschel_images[*,*,1,i]=la_power(d_err,2.)
6768fb27   Raphael Maris   First comit
172
173
ENDFOR

6768fb27   Raphael Maris   First comit
174
175
176
177
178
179
180
181
;=== check for null variances
ind=where(herschel_images[*,*,1,*] EQ 0.,count)
IF count NE 0 THEN BEGIN
	message,'There are null variances ...',/continue
	stop
ENDIF

IF keyword_set(save) THEN BEGIN
6784b4c7   Jean-Philippe Bernard   modified and comm...
182
183
	;=== JPB: I changed the file name into images.sav, for compatibility with other files for other missions
	;file_save=save_data_dir+use_source_name+'_herschel_data.sav'
9b0b6d7e   Jean-Philippe Bernard   finished implemen...
184
	file_save=save_data_dir+use_source_name+'_herschel_images'+reso_str+'.sav'
6768fb27   Raphael Maris   First comit
185
186
187
188
189
190
191
	save,herschel_images,herschel_filters,href,file=file_save
	message,'Saved '+file_save,/info
ENDIF
; 
; mwrfits,herschel_images,save_data_dir+use_source_name+'_herschel_data.fits',href

the_end:
6768fb27   Raphael Maris   First comit
192
193

END