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

;stop

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

RETURN,weights

END