FUNCTION extract_all_muse_phangs_seds,source_name, $ voronoi_id, $ images, $ filters, $ indices=indices, $ counts=counts, $ use_these_indices=use_these_indices, $ help=help ;+ ; 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. ;- 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 dustem_init ;file='/tmp/seds_muse_pixels.sav' ;IF keyword_set(filename) THEN file=filename ;message,'upon completion, extracted seds will be stored in '+file,/continue ;stop all_seds=ptrarr(Nvor) all_seds_indices=ptrarr(Nvor) counts=lonarr(Nvor) unset_ptrs=[-1L] Nunset=0L vid_start=0LL ;vid_start=40749LL ;This is for test (to check for un-defined pointers on voronoi bins) IF NOT keyword_set(use_these_indices) THEN BEGIN FOR vid=vid_start,Nvor-1 DO BEGIN IF vid mod 100 EQ 0 THEN BEGIN message,'Extracting sed '+strtrim(vid,2)+' '+strtrim(1.*vid/Nvor*100.,2)+' %',/continue ENDIF index=where(voronoi_id EQ vid,count) 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 ENDIF ELSE BEGIN unset_ptrs=[unset_ptrs,vid] Nunset=Nunset+1 ENDELSE ENDFOR ENDIF ELSE BEGIN FOR vid=vid_start,Nvor-1 DO BEGIN IF vid mod 100 EQ 0 THEN BEGIN message,'Extracting sed '+strtrim(vid,2)+' '+strtrim(1.*vid/Nvor*100.,2)+' %',/continue ENDIF 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 ENDFOR ENDELSE ;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 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 END