Blame view

LabTools/IRAP/RM/phangs_make_herschel_images.pro 7.3 KB
6768fb27   Raphael Maris   First comit
1
2
3
4
PRO phangs_make_herschel_images,source_name=source_name,save=save,show_images=show_images,nostop=nostop,help=help

;+
; NAME:
6784b4c7   Jean-Philippe Bernard   modified and comm...
5
;    phangs_make_herschel_images
6768fb27   Raphael Maris   First comit
6
7
8
9
10
; PURPOSE:
;    makes astrosat images usable by the Phangs ISRF project
; CATEGORY:
;    Dustem Phangs
; CALLING SEQUENCE:
6784b4c7   Jean-Philippe Bernard   modified and comm...
11
;    phangs_make_herschel_images[,source_name=][,/save][,/show_images][,/nostop]
6768fb27   Raphael Maris   First comit
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
; INPUTS:
;    None
; OPTIONAL INPUT PARAMETERS:
;    source_name            : source name (default = 'ngc0628')
; 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...
32
;    input Herschel images are assumed to be in Jy/beam and Jy/pixel for SPIRE and PACS respectively
6768fb27   Raphael Maris   First comit
33
34
;    
; EXAMPLES
6784b4c7   Jean-Philippe Bernard   modified and comm...
35
36
;	phangs_make_herschel_images,source_name='ngc0628',/show,/nostop
;	phangs_make_herschel_images,source_name='ngc0628',/save,/show,/nostop
6768fb27   Raphael Maris   First comit
37
38
39
40
41
42
43
; 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...
44
  doc_library,'phangs_make_herschel_images'
6768fb27   Raphael Maris   First comit
45
46
47
48
49
50
  goto,the_end
ENDIF

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

6784b4c7   Jean-Philippe Bernard   modified and comm...
51
52
53
54
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
55
;window,0
6784b4c7   Jean-Philippe Bernard   modified and comm...
56
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
57
58
win=0L

6784b4c7   Jean-Philippe Bernard   modified and comm...
59
60
61
62
;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
63

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

;This is to get the reference header
6784b4c7   Jean-Philippe Bernard   modified and comm...
67
68
;JPB : I modified this since we now have a save set that contains only the reference Fits header
;restore,save_data_dir+'ngc0628_jwst_images.sav',/verb
6768fb27   Raphael Maris   First comit
69
70
71
72
;% RESTORE: Restored variable: JWST_IMAGES.
;% RESTORE: Restored variable: FILTERS.
;% RESTORE: Restored variable: HREF.
;% RESTORE: Restored variable: NHCO.
6784b4c7   Jean-Philippe Bernard   modified and comm...
73
74
restore,save_data_dir+'ngc0628_ref_header.sav',/verb
;% RESTORE: Restored variable: HREF.
6768fb27   Raphael Maris   First comit
75

6784b4c7   Jean-Philippe Bernard   modified and comm...
76
77
78
;== 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
79
80
81
82
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...
83
84
;JPB: added missing SPIRE filters
name_filters = ['pacs70','pacs100','pacs160','spire250','spire350','spire500']
6768fb27   Raphael Maris   First comit
85

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

6784b4c7   Jean-Philippe Bernard   modified and comm...
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
;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
106
107
108
109
110
111

FOR i=0L,Nherschel_filter-1 DO BEGIN
	file=files[i]
	d_narray=mrdfits(file,0,h)
	d = d_narray[*,*,0]
	d_err = d_narray[*,*,1]
6768fb27   Raphael Maris   First comit
112
 	ind=where(finite(d) NE 1,count)
6768fb27   Raphael Maris   First comit
113
	IF count NE 0 THEN d[ind]=la_undef()
6784b4c7   Jean-Philippe Bernard   modified and comm...
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136

  ;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

 	;if (STRPOS('spire250', name_filters[i]) NE -1) then begin
  ;   	fact = 1.e-6/omega_250
  ;endif
  ;if (STRPOS('spire350', name_filters[i]) NE -1) then begin
  ;     	fact = 1.e-6/omega_350
  ;endif
  ;if (STRPOS('spire500', name_filters[i]) NE -1) then begin
  ;     	fact = 1/e-6/omega_500
  ;endif
  ;if (STRPOS(name_filters[i],'spire') EQ -1) then begin
 	; 	steradians=(sxpar(h,'CDELT2')/!radeg)^2   ;pixel in sr
  ;  fact=1.e-6/steradians           ;This is to rescale from /pixel to /sr   	
  ;endif
              	
6768fb27   Raphael Maris   First comit
137
 	d=la_mul(d,fact)
6784b4c7   Jean-Philippe Bernard   modified and comm...
138
139
140
141
142
143

	;=== JPB: I have re-instored image_cont20. It has to work on your machine, if it does not, we'll have to fix the problem
	;=== and you can always not run it by not setting the show_images keyword
	IF keyword_set(show_images) THEN BEGIN
		image_cont20,d,h,/square,imrange=0,image_color_table='jpbloadct',axis_color_table=1,/silent,tit=tit,off_bar_pos=obp
	ENDIF
6768fb27   Raphael Maris   First comit
144
 	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...
145
146
147
148
149
150
151
152
      ;JPB: here something you could not know:
      ;project2 can store and restore the projection info. So, if you do the same projection twice, you can do this way:
      ;and gain a fcator of almost 2 in computing speed
     	;d=project2(h,d,href,/silent)
     	;d_err=project2(h,d_err,href,/silent)
     	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
153
	tit=use_source_name+' '+herschel_filters[i]
6784b4c7   Jean-Philippe Bernard   modified and comm...
154
155
156
157
158
	;=== JPB: I have re-instored image_cont20. It has to work on your machine, if it does not, we'll have to fix the problem
	;=== and you can always not run it by not setting the show_images keyword
	IF keyword_set(show_images) THEN BEGIN
		image_cont20,d,href,/square,imrange=imrange,image_color_table='jpbloadct',axis_color_table=1,/silent,tit=tit,off_bar_pos=obp
	ENDIF
6768fb27   Raphael Maris   First comit
159
	herschel_images[*,*,0,i]=d
6784b4c7   Jean-Philippe Bernard   modified and comm...
160
161
162
	;JPB: I believe that d_err is an uncertainty, not a variance, so it has to be squerd to go into this cube for the SED extractor
	;herschel_images[*,*,1,i]=d_err
	herschel_images[*,*,1,i]=la_power(d_err,2.)
6768fb27   Raphael Maris   First comit
163
164
ENDFOR

6768fb27   Raphael Maris   First comit
165
166
167
168
169
170
171
172
;=== 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...
173
174
175
	;=== 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'
	file_save=save_data_dir+use_source_name+'_herschel_images.sav'
6768fb27   Raphael Maris   First comit
176
177
178
179
180
181
182
	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
183
184

END