Blame view

LabTools/IRAP/JPB/extract_all_muse_phangs_seds.pro 3.77 KB
9b0b6d7e   Jean-Philippe Bernard   finished implemen...
1
2
3
4
5
6
7
8
FUNCTION extract_all_muse_phangs_seds,source_name, $
                                 voronoi_id, $
                                 images, $
                                 filters, $
                                 indices=indices, $
                                 counts=counts, $
                                 use_these_indices=use_these_indices, $
                                 help=help
d6343d56   Jean-Philippe Bernard   First commit
9

9b0b6d7e   Jean-Philippe Bernard   finished implemen...
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
;+
; NAME:
;    extract_all_muse_phangs_seds
; PURPOSE:
;    extract SEDs in Muse Voronoi bins
; CATEGORY:
;    PHANGS ISRF
; CALLING SEQUENCE:
;    all_seds=extract_all_muse_phangs_seds(source_name,voronoi_id,images,filters[,indices=][,counts=][,use_these_indices=])
; INPUTS:
;    source_name = source name
;    voronoi_id  = voronoi id map
;    images      = images cube from which SEDs must be extracted
;    filters     = filters name list corresponing to images
; OPTIONAL INPUT PARAMETERS:
;    use_these_indices = if set SED extraction will use these indices instead of recomputing them from voronoi_id map
; OUTPUTS:
;    None
; OPTIONAL OUTPUT PARAMETERS:
;    indices     = list of indices
;    counts      = list of pixel numbers for each voronoi bin
; ACCEPTED KEY-WORDS:
;    help      = If set, print this help
; COMMON BLOCKS:
;    None
; SIDE EFFECTS:
;    The following files are written :
;    /tmp/seds_muse_pixels.sav (by default, or filename if set) containing variable all_seds and all_seds_indices
; RESTRICTIONS:
;    None
; PROCEDURE:
;    uses dustem_sed_extractor
; EXAMPLES
;  
; MODIFICATION HISTORY:
;    Written by J.-Ph. Bernard (2023)
;    Evolution details on the DustEMWrap gitlab.
;    See http://dustemwrap.irap.omp.eu/ for FAQ and help.  
;-
d6343d56   Jean-Philippe Bernard   First commit
49

9b0b6d7e   Jean-Philippe Bernard   finished implemen...
50
51
52
53
54
55
56
57
IF keyword_set(help) THEN BEGIN
  doc_library,'extract_all_muse_phangs_seds'
  all_seds=-1
  goto,the_end
ENDIF

;Nvor=max(voronoi_id)
Nvor=max(voronoi_id)+1     ;+1 is because voronoi IDs start at 0
d6343d56   Jean-Philippe Bernard   First commit
58
59
dustem_init

9b0b6d7e   Jean-Philippe Bernard   finished implemen...
60
61
;file='/tmp/seds_muse_pixels.sav'
;IF keyword_set(filename) THEN file=filename
d6343d56   Jean-Philippe Bernard   First commit
62

9b0b6d7e   Jean-Philippe Bernard   finished implemen...
63
;message,'upon completion, extracted seds will be stored in '+file,/continue
6fd06be5   Jean-Philippe Bernard   improved
64
;stop
d6343d56   Jean-Philippe Bernard   First commit
65
66
67
68
69

all_seds=ptrarr(Nvor)
all_seds_indices=ptrarr(Nvor)
counts=lonarr(Nvor)

9b37a060   Jean-Philippe Bernard   improved for smoo...
70
71
72
73
74
75
unset_ptrs=[-1L]
Nunset=0L

vid_start=0LL
;vid_start=40749LL   ;This is for test (to check for un-defined pointers on voronoi bins)

d6343d56   Jean-Philippe Bernard   First commit
76
IF NOT keyword_set(use_these_indices) THEN BEGIN
9b37a060   Jean-Philippe Bernard   improved for smoo...
77
78
   FOR vid=vid_start,Nvor-1 DO BEGIN
      IF vid mod 100 EQ 0 THEN BEGIN
d6343d56   Jean-Philippe Bernard   First commit
79
80
81
      	 message,'Extracting sed '+strtrim(vid,2)+' '+strtrim(1.*vid/Nvor*100.,2)+' %',/continue
      ENDIF
      index=where(voronoi_id EQ vid,count)
9b0b6d7e   Jean-Philippe Bernard   finished implemen...
82
83
84
85
86
      IF count NE 0 THEN BEGIN
         sed=dustem_sed_extractor(images,index,filters,/total_intensity_only)
         all_seds[vid]=ptr_new(sed)
         all_seds_indices[vid]=ptr_new(index)
         counts[vid]=count
9b37a060   Jean-Philippe Bernard   improved for smoo...
87
88
89
90
      ENDIF ELSE BEGIN
         unset_ptrs=[unset_ptrs,vid]
         Nunset=Nunset+1
      ENDELSE
d6343d56   Jean-Philippe Bernard   First commit
91
92
   ENDFOR
ENDIF ELSE BEGIN
9b37a060   Jean-Philippe Bernard   improved for smoo...
93
94
   FOR vid=vid_start,Nvor-1 DO BEGIN
      IF vid mod 100 EQ 0 THEN BEGIN
d6343d56   Jean-Philippe Bernard   First commit
95
96
          message,'Extracting sed '+strtrim(vid,2)+' '+strtrim(1.*vid/Nvor*100.,2)+' %',/continue
      ENDIF
9b37a060   Jean-Philippe Bernard   improved for smoo...
97
98
99
100
101
102
103
104
105
106
      IF ptr_valid(use_these_indices[vid]) THEN BEGIN
         index=*use_these_indices[vid]
         sed=dustem_sed_extractor(images,index,filters,/total_intensity_only)
         all_seds[vid]=ptr_new(sed)
         all_seds_indices[vid]=ptr_new(index)
         counts[vid]=n_elements(index)
      ENDIF ELSE BEGIN
         unset_ptrs=[unset_ptrs,vid]
         Nunset=Nunset+1
      ENDELSE
d6343d56   Jean-Philippe Bernard   First commit
107
108
109
   ENDFOR   
ENDELSE

9b37a060   Jean-Philippe Bernard   improved for smoo...
110
111
112
113
114
115
116
117
;Check for unset pointers
IF Nunset NE 0 THEN BEGIN
   message,'Found '+strtrim(Nunset,2)+' unset pointers to voronoi bins',/continue
   unset_ptrs=unset_ptrs[1:*]
   ;not sure what to do with those
   ;stop
ENDIF

9b0b6d7e   Jean-Philippe Bernard   finished implemen...
118
119
120
121
122
123
124
125
indices=all_seds_indices  ;to be retruned as keyword

;save,all_seds,all_seds_indices,file=file
;message,'Saved '+file,/info

the_end:

RETURN,all_seds
d6343d56   Jean-Philippe Bernard   First commit
126
127

END