phangs_make_jwst_images.pro
5.53 KB
1
2
3
4
5
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
PRO phangs_make_jwst_images,source_name=source_name,save=save,show_images=show_images,nostop=nostop,resolution_filter=resolution_filter,help=help
;+
; 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')
; resolution_filter : if set makes images at this resolution (default none)
; 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:
; Files written:
; _ref_header.sav
; _jwst_images.sav
; 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
use_source_name='ngc0628'
IF keyword_set(source_name) THEN use_source_name=source_name
pdp_define_la_common
dustem_init
;window,0
obp=[1.1,0,1.15,1]
win=0L
;data_dir='/Volumes/PILOT_FLIGHT1/PHANGS-JWST/DR1/'
data_dir=!phangs_data_dir+'/phangs_drive/PHANGS-JWST/DR1/'
save_data_dir=!phangs_data_dir+'/ISRF/WORK/'
;========== get JWST reference header
file=data_dir+use_source_name+'_nircam_lv3_f300m_i2d_anchor_atgauss1.fits'
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
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
;=== save reference header
IF keyword_set(save) THEN BEGIN
save_file=save_data_dir+use_source_name+'_ref_header'+reso_str+'.sav'
save,href,file=save_file
message,'Saved '+save_file,/continue
ENDIF
Nx=sxpar(href,'NAXIS1')
Ny=sxpar(href,'NAXIS2')
filters_names=['F200W','F300M','F335M','F360M','F0770W','F1000W','F1130W','F2100W']
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))
filters=dustem_filter_names2filters(filters_names)
Nfilters=n_elements(filters)
jwst_images=fltarr(Nx,Ny,2,Nfilters)
IF not keyword_set(nostop) THEN stop
;========== Make JWST images
FOR i=0L,Nfilters-1 DO BEGIN
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
stop
;===== Invent variances (will have to do better)
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
; ;===== 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
IF keyword_set(save) THEN BEGIN
save_file=save_data_dir+use_source_name+'_jwst_images'+reso_str+'.sav'
save,jwst_images,filters,href,file=save_file
message,'Saved '+save_file,/continue
ENDIF
the_end:
END