Blame view

LabTools/IRAP/JPB/phangs_make_astrosat_images.pro 5.11 KB
eff80468   Jean-Philippe Bernard   improved
1
PRO phangs_make_astrosat_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
3
4
5
6
7
8
9
10
11
12
13
14
15

;+
; NAME:
;    phangs_make_astrosat_images
; PURPOSE:
;    makes astrosat images usable by the Phangs ISRF project
; CATEGORY:
;    Dustem Phangs
; CALLING SEQUENCE:
;    phangs_make_astrosat_images[,source_name=][,/save][,/show_images][,/nostop]
; INPUTS:
;    None
; OPTIONAL INPUT PARAMETERS:
;    source_name            : source name (default = 'ngc0628')
eff80468   Jean-Philippe Bernard   improved
16
;    resolution_filter      : if set makes images at this resolution (default none)
9beef1e9   Jean-Philippe Bernard   first commit
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
; 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:
;    input astrosat images are asumed to be in Angstrom-1 cm-2 erg s-1 PER PIXEL (even though BUNIT   = 'Angstrom-1 cm-2 erg s-1' in header)
;    
; EXAMPLES
;	phangs_make_astrosat_images,source_name='ngc0628',/show,/nostop
;	phangs_make_astrosat_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_astrosat_images'
  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...
52
53
54
55
56
57
reso_str=''
;stop
IF keyword_set(resolution_filter) THEN BEGIN
		reso_str='_'+resolution_filter
ENDIF

9beef1e9   Jean-Philippe Bernard   first commit
58
pdp_define_la_common
eff80468   Jean-Philippe Bernard   improved
59
60
dustem_init

9beef1e9   Jean-Philippe Bernard   first commit
61
62
63
64
;window,0
obp=[1.1,0,1.15,1]
win=0L

03f214d1   Jean-Philippe Bernard   improved
65
;data_dir=!phangs_data_dir+'/phangs_drive/PHANGS_ASTROSAT/v1p0/release/'
06c3ba9c   Jean-Philippe Bernard   improved
66
67
;data_dir=!phangs_data_dir+'/phangs_drive/Archive/PHANGS_ASTROSAT/v1p0/release/'
data_dir=!phangs_data_dir+'/phangs_drive/Archive/PHANGS_AstroSat/v1p0/release/'
9beef1e9   Jean-Philippe Bernard   first commit
68
69
70
71
72
73
74
save_data_dir=!phangs_data_dir+'/ISRF/WORK/'

astrosat_data:
;BUNIT   = 'Angstrom-1 cm-2 erg s-1'
;in fact Angstrom-1 cm-2 erg s-1 PER PIXEL ?!

;This is to get the reference header
f145894a   Jean-Philippe Bernard   improved
75
76
77
78
79
80
81
file=save_data_dir+use_source_name+'_ref_header'+reso_str+'.sav'
st_info=file_info(file)
IF st_info.exists NE 1 THEN BEGIN
	message,'Could not find file '+st_info,/continue
	stop
ENDIF
restore,file,/verb
9b0b6d7e   Jean-Philippe Bernard   finished implemen...
82
;restore,save_data_dir+use_source_name+'_jwst_images.sav',/verb
9beef1e9   Jean-Philippe Bernard   first commit
83
;% RESTORE: Restored variable: HREF.
9beef1e9   Jean-Philippe Bernard   first commit
84
85
86
87
88
89
90
91
92
93
94

astrosat_filters=dustem_filter_names2filters(['F148W','F154W','F169M','F172M','N219M'])
Nastrosat_filter=n_elements(astrosat_filters)
astrosat_images=fltarr(sxpar(href,'NAXIS1'),sxpar(href,'NAXIS2'),2,Nastrosat_filter)
files=data_dir+strupcase(use_source_name)+'_'+['F148','F154','F169','F172','N219']+'_bkg_subtracted_mw_corrected.fits'
;NGC0628_F148_bkg_subtracted_mw_corrected.fits	NGC0628_F169_bkg_subtracted_mw_corrected.fits	NGC0628_N219_bkg_subtracted_mw_corrected.fits
;NGC0628_F154_bkg_subtracted_mw_corrected.fits	NGC0628_F172_bkg_subtracted_mw_corrected.fits
wavs_mic=dustem_filter2wav(astrosat_filters)
cmic=3.e14   ;mic/sec
facts=wavs_mic/cmic*(wavs_mic*1.e4)/4./!pi*1.e-7*1.e4*1.e20    ;from Flambda in ergs/cm2/s/AA to MJy/sr (note: was divided by 4*pi)
imrange=[-0.5,2]*1e-17    ;erg/s/cm2/AA
9b0b6d7e   Jean-Philippe Bernard   finished implemen...
95
imrange=[-0.5,1]/10   ;MJy/sr
9beef1e9   Jean-Philippe Bernard   first commit
96

524e900a   Jean-Philippe Bernard   fixed smoothing I...
97
98
win=0L

9beef1e9   Jean-Philippe Bernard   first commit
99
100
FOR i=0L,Nastrosat_filter-1 DO BEGIN
	file=files[i]
f145894a   Jean-Philippe Bernard   improved
101
102
	st_info=file_info(file)
	IF st_info.exists NE 1 THEN BEGIN
5526ff78   Jean-Philippe Bernard   checking file exi...
103
		message,'Could not find file '+file,/continue
f145894a   Jean-Philippe Bernard   improved
104
105
		stop
	ENDIF
9beef1e9   Jean-Philippe Bernard   first commit
106
107
108
109
110
111
	d=mrdfits(file,0,h)
	steradians=(sxpar(h,'CDELT2')/!radeg)^2   ;pixel in sr
	fact=facts[i]*4.*!pi/steradians           ;This is to rescale from /pixel to /sr
	ind=where(finite(d) NE 1,count)
	IF count NE 0 THEN d[ind]=la_undef()
	d=la_mul(d,fact)
524e900a   Jean-Philippe Bernard   fixed smoothing I...
112
113
	window,win & win=win+1
	image_cont20,d,h,/square,imrange=imrange,image_color_table='jpbloadct',axis_color_table=1,/silent,tit=tit,off_bar_pos=obp
eff80468   Jean-Philippe Bernard   improved
114
115
116
117
	reso_str=''
	;stop
	IF keyword_set(resolution_filter) THEN BEGIN
		reso_str='_'+resolution_filter
eff80468   Jean-Philippe Bernard   improved
118
119
120
121
122
    data_reso=sxpar(h,'BMAJ')
		final_reso=dustem_filter2reso(resolution_filter)
  	d=degrade_res(d,h,data_reso,final_reso,hout)
    h=hout
	ENDIF
eff80468   Jean-Philippe Bernard   improved
123
124
125
	IF sxpar(h,'NAXIS1') NE sxpar(href,'NAXIS1') OR sxpar(h,'NAXIS2') NE sxpar(href,'NAXIS2') THEN BEGIN
		d=project2(h,d,href,/silent)
	ENDIF
9beef1e9   Jean-Philippe Bernard   first commit
126
	tit=source_name+' '+astrosat_filters[i]
524e900a   Jean-Philippe Bernard   fixed smoothing I...
127
128
	window,win & win=win+1
	image_cont20,d,href,/square,imrange=imrange,image_color_table='jpbloadct',axis_color_table=1,/silent,tit=tit,off_bar_pos=obp
9beef1e9   Jean-Philippe Bernard   first commit
129
	astrosat_images[*,*,0,i]=d
9b0b6d7e   Jean-Philippe Bernard   finished implemen...
130
	IF not keyword_set(nostop) THEN stop
9beef1e9   Jean-Philippe Bernard   first commit
131
132
133
134
135
136
137
138
139
140
141
142
143
ENDFOR

;Invent variances (will have to do better)
perc_error=5./100.
astrosat_images[*,*,1,*]=la_power(la_mul(astrosat_images[*,*,0,*],perc_error),2)   ;assumed intensity variance
;=== check for null variances
ind=where(astrosat_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
9b37a060   Jean-Philippe Bernard   improved for smoo...
144
145
	;file_save=save_data_dir+use_source_name+'_astrosat_data'+reso_str+'.sav'     ;changed names on April 15 2024
	file_save=save_data_dir+use_source_name+'_astrosat_images'+reso_str+'.sav'
9beef1e9   Jean-Philippe Bernard   first commit
146
147
148
149
150
151
152
	save,astrosat_images,astrosat_filters,href,file=file_save
	message,'Saved '+file_save,/info
ENDIF

the_end:

END