phangs_binid2weights.pro 2.5 KB
FUNCTION phangs_binid2weights,st_muse_weights,vid,st_templates,age_values,metalicity_values,reddening=reddening,help=help

;+
; NAME:
;    phangs_binid2weights
; PURPOSE:
;    get the Muse weights of a given Muse voronoi bin
; CATEGORY:
;    DustEM
; CALLING SEQUENCE:
;    weights=phangs_binid2weights(st_muse_weights,vid,st_templates,age_values,metalicity_values[,reddening=])
; INPUTS:
;    st_muse_weights    = Muse weiths structure
;    vid                = Voronoi ID
;    st_templates       = Muse templates info structure (as returned by read_muse_templates_info.pro)
;    age_values         = age values (to be compares with st_templates.age)
;    metalicity_values  = Z values (to be compares with st_templates.Z)
; OPTIONAL INPUT PARAMETERS:
;    None
; OUTPUTS:
;    weights = weights array (dim [Nage,NZ])
; OPTIONAL OUTPUT PARAMETERS:
;    reddening = redenning value for that bin (E(B-V))
; ACCEPTED KEY-WORDS:
;    help                  = if set, print this help
; COMMON BLOCKS:
;    None
; SIDE EFFECTS:
;    None
; RESTRICTIONS:
;    The DustEMWrap IDL code must be installed
; PROCEDURE:
;    Scans the grid SEDs to find the best fit (lowest chi2)
; EXAMPLES
;    
; MODIFICATION HISTORY:
;    Written by JPB Jan 2024
;    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_binid2weights'
  weights=0.
  goto,the_end
ENDIF


ind=where(st_muse_weights.bin_id EQ vid,count)
IF count EQ 0 THEN BEGIN
  message,'bin '+strtrim(vid,2)+' not found in structure provided',/continue
  stop
ENDIF

st=st_muse_weights[ind]
reddening=st.reddening
Nage=n_elements(age_values)
NZ=n_elements(metalicity_values)
Nweights=Nage*Nz

weights=fltarr(Nage,Nz)

;help,age_values,metalicity_values,weights
;stop

tagnames=tag_names(st)
FOR i=0L,Nweights-1 DO BEGIN
	indd=where(tagnames EQ 'W_'+strtrim(i,2),ccount)
	value=st.(indd)
	IF value NE 0 THEN BEGIN
		ind=where(st_templates.id EQ i,count)
		ii=where(age_values EQ st_templates[ind].age,counti)
		jj=where(metalicity_values EQ round(st_templates[ind].Z*100.)/100.,countj)
		IF counti NE 1 and countj NE 1 THEN BEGIN
			message,'metalicity or age not found',/continue
			stop
		ENDIF
		;ij=index2ij([i],[Nage,NZ])
		;weights[ij[0,0],ij[0,1]]=st.(indd)
		weights[ii,jj]=st.(indd)
		message,'Found non zero weight '+strtrim(value,2)+' at age['+strtrim(ii,2)+']='+strtrim(age_values[ii],2)+' Z['+strtrim(jj,2)+']='+strtrim(metalicity_values[jj],2),/info
	ENDIF
ENDFOR

the_end:
RETURN,weights

END