Blame view

LabTools/IRAP/JPB/phangs_make_jwst_images.pro 5.96 KB
eff80468   Jean-Philippe Bernard   improved
1
PRO phangs_make_jwst_images,source_name=source_name,save=save,show_images=show_images,nostop=nostop,resolution_filter=resolution_filter,help=help
9beef1e9   Jean-Philippe Bernard   first commit
2

14ae4f23   Jean-Philippe Bernard   improved
3
4
5
6
7
8
9
10
11
12
13
14
15
;+
; NAME:
;    phangs_make_jwst_images
; PURPOSE:
;    makes JWST images usable by the Phangs ISRF project
; CATEGORY:
;    Dustem Phangs
; CALLING SEQUENCE:
;    phangs_make_jwst_images[,source_name=][,/save][,/show_images][,/nostop]
; INPUTS:
;    None
; OPTIONAL INPUT PARAMETERS:
;    source_name            : source name (default = 'ngc0628')
ee1fd9a9   Jean-Philippe Bernard   improved in the f...
16
;    resolution_filter      : if set makes images at this resolution (default none)
14ae4f23   Jean-Philippe Bernard   improved
17
18
19
20
21
22
23
24
25
26
27
28
; 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:
ee1fd9a9   Jean-Philippe Bernard   improved in the f...
29
30
31
;    Files written:
;    _ref_header.sav
;    _jwst_images.sav
14ae4f23   Jean-Philippe Bernard   improved
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
; RESTRICTIONS:
;    None
; PROCEDURE:
;    input JWST images are asumed to be in units of MJy/sr
; EXAMPLES
;	 phangs_make_jwst_images,source_name='ngc0628',/save,/show,/nostop
; 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_make_jwst_images'
  goto,the_end
ENDIF
9beef1e9   Jean-Philippe Bernard   first commit
48
49
50
51
52

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

pdp_define_la_common
ee1fd9a9   Jean-Philippe Bernard   improved in the f...
53
dustem_init
9beef1e9   Jean-Philippe Bernard   first commit
54
55
56
57
58
;window,0
obp=[1.1,0,1.15,1]
win=0L

;data_dir='/Volumes/PILOT_FLIGHT1/PHANGS-JWST/DR1/'
f8a541d6   Jean-Philippe Bernard   updated to new fi...
59
60
61
;data_dir=!phangs_data_dir+'/phangs_drive/PHANGS-JWST/DR1/'
;/data/projects/phangs/phangs_drive/Archive/PHANGS_JWST/DR1/ngc0628/f1000w_psf_matched
data_dir=!phangs_data_dir+'/phangs_drive/Archive/PHANGS_JWST/DR1/'+use_source_name+'/f300m_psf_matched/'
9beef1e9   Jean-Philippe Bernard   first commit
62
63
64
save_data_dir=!phangs_data_dir+'/ISRF/WORK/'

;========== get JWST reference header
f8a541d6   Jean-Philippe Bernard   updated to new fi...
65
66
67
68
69
70
file=data_dir+use_source_name+'_nircam_lv3_f300m_i2d_anchor_atgauss1.fits'
st_info=file_info(file)
IF st_info.exists NE 1 THEN BEGIN
	message,'Could not find file '+file,/continue
	stop
ENDIF
9beef1e9   Jean-Philippe Bernard   first commit
71
72
73
74
75
76
77
78
79
80
d=mrdfits(file,1,h)
ind=where(finite(d) NE 1,count)
IF count NE 0 THEN d[ind]=la_undef()
print,sxpar(h,'CDELT1')
href=cd2astro_header(h)
sxaddpar,href,'EQUINOX',2000.
IF keyword_set(show_images) THEN BEGIN
	window,win & win=win+1
	image_cont20,d,href,/square,imrange=[-0.1,5],image_color_table='jpbloadct',/silent,tit=tit
ENDIF
14ae4f23   Jean-Philippe Bernard   improved
81

ee1fd9a9   Jean-Philippe Bernard   improved in the f...
82
83
84
85
86
87
88
89
90
91
92
93
94
95
reso_str=''
IF keyword_set(resolution_filter) THEN BEGIN
	reso_str='_'+resolution_filter
	data_reso=dustem_filter2reso(dustem_filter_names2filters('F300M'))
	final_reso=dustem_filter2reso(resolution_filter)
  dd=degrade_res(d,href,data_reso,final_reso,hout)
  href=hout
ENDIF

IF keyword_set(show_images) THEN BEGIN
	window,win & win=win+1
	image_cont20,dd,href,/square,imrange=[-0.1,5],image_color_table='jpbloadct',/silent,tit=tit
ENDIF

14ae4f23   Jean-Philippe Bernard   improved
96
97
;=== save reference header
IF keyword_set(save) THEN BEGIN
ee1fd9a9   Jean-Philippe Bernard   improved in the f...
98
	save_file=save_data_dir+use_source_name+'_ref_header'+reso_str+'.sav'
14ae4f23   Jean-Philippe Bernard   improved
99
100
101
102
	save,href,file=save_file
	message,'Saved '+save_file,/continue
ENDIF

9beef1e9   Jean-Philippe Bernard   first commit
103
104
105
106
Nx=sxpar(href,'NAXIS1')
Ny=sxpar(href,'NAXIS2')

filters_names=['F200W','F300M','F335M','F360M','F0770W','F1000W','F1130W','F2100W']
ee1fd9a9   Jean-Philippe Bernard   improved in the f...
107
108
filters_names2=['F200W','F300M','F335M','F360M','F770W','F1000W','F1130W','F2100W']   ;This is to be used for file names
instrus=dustem_filter2instru(dustem_filter_names2filters(filters_names))
9beef1e9   Jean-Philippe Bernard   first commit
109
110
111
112
113
114
filters=dustem_filter_names2filters(filters_names)
Nfilters=n_elements(filters)
jwst_images=fltarr(Nx,Ny,2,Nfilters)

IF not keyword_set(nostop) THEN stop

ee1fd9a9   Jean-Philippe Bernard   improved in the f...
115
116
;========== Make JWST images
FOR i=0L,Nfilters-1 DO BEGIN
f8a541d6   Jean-Philippe Bernard   updated to new fi...
117
	data_dir=!phangs_data_dir+'/phangs_drive/Archive/PHANGS_JWST/DR1/'+use_source_name+'/'+strlowcase(filters_names2[i])+'_psf_matched/'
ee1fd9a9   Jean-Philippe Bernard   improved in the f...
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
	file=data_dir+use_source_name+'_'+strlowcase(instrus[i])+'_lv3_'+strlowcase(filters_names2[i])+'_i2d_anchor_atgauss1.fits'
	st_info=file_info(file)
	IF st_info.exists NE 1 THEN BEGIN
		message,'requested file '+file+' does not exist',/info
		stop
	ENDIF
	d=mrdfits(file,0,h0)
	d=mrdfits(file,1,h)
	sxaddpar,h,'EQUINOX',2000.
	ind=where(finite(d) NE 1,count)
	IF count NE 0 THEN d[ind]=la_undef()
	IF keyword_set(resolution_filter) THEN BEGIN
		data_reso=dustem_filter2reso(dustem_filter_names2filters(filters_names[i]))
		final_reso=dustem_filter2reso(resolution_filter)
  	d=degrade_res(d,h,data_reso,final_reso,hout)
    h=hout
	ENDIF
	IF sxpar(h,'NAXIS1') NE Nx OR sxpar(h,'NAXIS2') NE Ny THEN BEGIN
		d=project2(h,d,href,/silent)
	ENDIF
	jwst_images[*,*,0,i]=d
	;i=i+1
	print,sxpar(h,'EXTNAME')
  filter_name=sxpar(h0,'FILTER')
  print,filter_name
	tit=source_name+' '+filter_name
	IF keyword_set(show_images) THEN BEGIN
		window,win & win=win+1
		image_cont20,d,href,/square,imrange=[-0.1,5],image_color_table='jpbloadct',/silent,tit=tit
		IF not keyword_set(nostop) THEN stop
	ENDIF
ENDFOR
9beef1e9   Jean-Philippe Bernard   first commit
150

9b0b6d7e   Jean-Philippe Bernard   finished implemen...
151
;stop
9beef1e9   Jean-Philippe Bernard   first commit
152

ee1fd9a9   Jean-Philippe Bernard   improved in the f...
153
;===== Invent variances (will have to do better)
9beef1e9   Jean-Philippe Bernard   first commit
154
155
156
157
158
159
160
161
162
perc_error=5./100.
jwst_images[*,*,1,*]=la_power(la_mul(jwst_images[*,*,0,*],perc_error),2)   ;assumed intensity variance
;=== check for null variances
ind=where(jwst_images[*,*,1,*] EQ 0.,count)
IF count NE 0 THEN BEGIN
	message,'There are null variances ...',/continue
	stop
ENDIF

ee1fd9a9   Jean-Philippe Bernard   improved in the f...
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
; ;===== WCO map:
; file=NH_data_dir+use_source_name+'_12m+7m+tp_co21_broad_mom0.fits'
; d=readfits(file,h)
; ;sxaddpar,h,'CTYPE1','RA---TAN'
; ;sxaddpar,h,'CTYPE2','RA---TAN'
; sxaddpar,h,'EQUINOX',2000.
; ind=where(finite(d) NE 1,count)
; IF count NE 0 THEN d[ind]=la_undef()
; IF sxpar(h,'NAXIS1') NE Nx OR sxpar(h,'NAXIS2') NE Ny THEN WCO=project2(h,d,href,/silent) ELSE WCO=d
; fact=4.e20/1.e21
; NHCO=la_mul(WCO,fact)   ;NH from CO in 1e21 H/cm2
; tit=source_name+' '+'NHCO [1e21 H/cm2]'
; IF keyword_set(show_images) THEN BEGIN
; 	window,win & win=win+1
; 	image_cont20,NHCO,href,/square,imrange=[-0.5,10],image_color_table='jpbloadct',/silent,tit=tit
; 	IF not keyword_set(nostop) THEN stop
; ENDIF
9beef1e9   Jean-Philippe Bernard   first commit
180
181

IF keyword_set(save) THEN BEGIN
ee1fd9a9   Jean-Philippe Bernard   improved in the f...
182
183
	save_file=save_data_dir+use_source_name+'_jwst_images'+reso_str+'.sav'
	save,jwst_images,filters,href,file=save_file
9beef1e9   Jean-Philippe Bernard   first commit
184
185
186
	message,'Saved '+save_file,/continue
ENDIF

14ae4f23   Jean-Philippe Bernard   improved
187
the_end:
9beef1e9   Jean-Philippe Bernard   first commit
188
189

END