; docformat = 'rst' ; ; NAME: ; convertTaxoToColor ; PURPOSE: ; Compute the expected color of a filter from a taxonomic class spectrum. ; ;+ ; :Description: ; Compute the expected color of a filter from a taxonomic class spectrum. ; ; :Categories: ; Database, Asteroid, Colors ; ; :Params: ; taxo: in, required, type=structure ; A structure of N reflectance spectra. Fields are:: ; .N: the number of classes ; .wave: a vector of reference wavelength for each spectral bin (micron) ; .class: an array of structure, with name, spec, and dev fields for each class ; filter: in, required, type=structure ; A structure defining the filter. Fields are:: ; .wave: a vector of reference wavelength for each spectral bin (micron) ; .trans: the transmission curve ; reference: in, required, type=structure ; A structure defining the reference filter. Fields are:: ; .wave: a vector of reference wavelength for each spectral bin (micron) ; .trans: the transmission curve ; ; :Keywords: ; AB: in, optional, type=boolean, default=0 ; If set, returns the magnitude in the AB system [Oke, J.B. 1974, ApJS, 27, 21] ; ST: in, optional, type=boolean, default=0 ; If set, returns the magnitude in the STMAG system [Stone, R.P.S. 1996, ApJS, 107, 423] ; Vega: in, optional, type=boolean, default=1 ; If set, returns the magnitude in the Vega system [Bessel, M. S. 2005, ARA&A, 43, 293] ; ; :Returns: A structure with the ; ; :Examples: ; ; :Uses: ; specToMag ; ; :Author: ; B.Carry (OCA) ; ; :History: ; Change History:: ; Written in December 2015, B. Carry (OCA) ; 2017 Aug. - B. Carry (OCA) - Outsource magnitude computation to specToMag code ;- function convertTaxoToColor, taxo, filter, reference, AB=AB, ST=ST, Vega=Vega COMPILE_OPT hidden, idl2 ;-----------------------------------------------------------------------------------------------; ;-----------------------------------------------------------------------------------------------; ;--- TAG --- I -- Initialization And Input Verification -----------------------; ;-----------------------------------------------------------------------------------------------; ;-----------------------------------------------------------------------------------------------; ;--I.1-- Check Input Parameters -------------------------------------------------------------- if n_params() lt 3 then begin message, /ioError, 'syntax: color = convertTaxoToColor( taxo, filter, reference )' return, -1 endif ;--I.2-- Check Validity of Input Spectra ----------------------------------------------------- requiredTag = ['N','wave','class'] nbTag=n_elements(requiredTag) for kTag=0, nbTag-1 do begin if not tag_exist( taxo, requiredTag[kTag] ) then begin message, 'Field '+requiredTag[kTag]+' missing in taxo structure' return, -1 endif endfor ;--I.3-- Check Validity of Input Filter ------------------------------------------------------ requiredTag = ['wave','trans'] nbTag=n_elements(requiredTag) for kTag=0, nbTag-1 do begin if not tag_exist( filter, requiredTag[kTag] ) then begin message, 'Field '+requiredTag[kTag]+' missing in filter structure' return, -1 endif endfor ;--I.4-- Check Validity of Input Filter ------------------------------------------------------ requiredTag = ['wave','trans'] nbTag=n_elements(requiredTag) for kTag=0, nbTag-1 do begin if not tag_exist( reference, requiredTag[kTag] ) then begin message, 'Field '+requiredTag[kTag]+' missing in reference structure' return, -1 endif endfor ;--I.5-- Define Output Structure ------------------------------------------------------------- empty={name:'',ref:0.,unc:0.} color=replicate(empty,taxo.N) ;-----------------------------------------------------------------------------------------------; ;-----------------------------------------------------------------------------------------------; ;--- TAG --- II -- Compute Color Indices -----------------------; ;-----------------------------------------------------------------------------------------------; ;-----------------------------------------------------------------------------------------------; for kTaxo=0, taxo.N-1 do begin ;--II.1-- Format Input Spectrum for specToMag Function -------------------------------------; specIn = {wave: taxo.wave, flux:taxo.class[kTaxo].spec} specUp = {wave: taxo.wave, flux:taxo.class[kTaxo].dev} ;--II.2-- Reference Magnitude --------------------------------------------------------------; refMag = specToMag( specIn, reference, /Vega ) upRef = specToMag( specUp, reference, /Vega ) refUnc = abs(refMag-upRef) ; print, refMag, upRef, refUnc ;--II.3-- Current Filter Magnitude ---------------------------------------------------------; curMag = specToMag( specIn, filter, /Vega ) upMag = specToMag( specUp, filter, /Vega ) curUnc = abs(curMag-upMag) ; print, curMag, upMag, curUnc cgPlot, specIn.wave, specIn.flux, /xLog, xRange=[0.1, 10], /yLog cgPlot, /OverPlot, specIn.wave, specUp.flux, color='gray' cgPlot, /OverPlot, reference.wave, reference.trans, color='blue' cgPlot, /OverPlot, filter.wave, filter.trans, color='orange' ;--II.4-- Store Photometry in Structure ----------------------------------------------------; color[kTaxo].name = taxo.class[kTaxo].name color[kTaxo].ref = (refMag-curMag) color[kTaxo].unc = refUnc + curUnc endfor return, color end ;-------------------old and rong code!!! ;;--- ;;---;-----------------------------------------------------------------------------------------------; ;;---;-----------------------------------------------------------------------------------------------; ;;---;--- TAG --- II -- Spectral Normalization -----------------------; ;;---;-----------------------------------------------------------------------------------------------; ;;---;-----------------------------------------------------------------------------------------------; ;;--- ;;--- ;--II.1-- Interpolate over Reference ------------------------------------------------------- ;;--- spec4ref = interpol( taxo.class[kTaxo].spec, taxo.wave, reference.wave ) ;;--- ;;--- ;--II.2-- Normalize spectra ---------------------------------------------------------------- ;;--- refColor = total( spec4ref * reference.trans ) / total(reference.trans) ;;--- norma = taxo.class[kTaxo] ;;--- norma.spec /= refColor ;;--- norma.dev /= refColor ;;--- ;;--- ;;---; cgPlot, taxo.wave, taxo.class[kTaxo].spec, thick=1, xr=[0.1,3] ;;---; cgPlot, /OverPlot, reference.wave, spec4ref, color='red', thick=4 ;;---;stop ;;---; cgPlot, taxo.wave, norma.spec, thick=1, xr=[0.1,3] ;;---; cgPlot, /OverPlot, reference.wave, spec4ref, color='red', thick=4 ;;---; ;;---; cgPlot, /OverPlot, reference.wave, reference.trans, color='gray' ;;---; cgPlot, /OverPlot, filter.wave, filter.trans, color='dark gray' ;;---; print, total( norma.spec * reference.trans) / total(reference.trans) ;;---;stop ;;--- ;;---;-----------------------------------------------------------------------------------------------; ;;---;-----------------------------------------------------------------------------------------------; ;;---;--- TAG --- III -- Convert Spectra to Color -----------------------; ;;---;-----------------------------------------------------------------------------------------------; ;;---;-----------------------------------------------------------------------------------------------; ;;--- ;;--- ;--II.1-- Interpolate Spectrum over Filter ------------------------------------------------- ;;--- spec4filter = interpol( taxo.class[kTaxo].spec, taxo.wave, filter.wave ) ;;--- dev4filter = interpol( taxo.class[kTaxo].dev, taxo.wave, filter.wave ) ;;---;---good? spec4filter = interpol( norma.spec, taxo.wave, filter.wave ) ;;---;---good? dev4filter = interpol( norma.dev, taxo.wave, filter.wave ) ;;--- ;;---; cgPlot, /over, filter.wave, spec4filter, color='green' , thick=2 ;;---; cgPlot, /over, reference.wave, reference.trans, color='navy', thick=2 ;;---; cgPlot, /over, filter.wave, filter.trans, color='navy' , thick=2 ;;--- ;;--- ;--II.2-- Convert Spectrum to Photometry --------------------------------------------------- ;;--- flux = total( spec4filter*filter.trans ) / total(filter.trans) ;;--- unc = total( dev4filter*filter.trans ) / total(filter.trans) ;;--- ;;--- ;--II.3-- Store Photometry in Structure ---------------------------------------------------- ;;--- color[kTaxo].name = taxo.class[kTaxo].name ;;--- color[kTaxo].ref = flux / refColor ;;--- color[kTaxo].unc = unc / refColor ;;---; color[kTaxo].ref = flux ;;---; color[kTaxo].unc = unc ;;--- ;;--- ;;---; gC = where(filter.trans gt 0.02 ) ;;---; centC = median( filter.wave[gC] ) ;;---; cgPlot, /over, centC, flux, psym=4 ;;---;stop ;;--- endfor ;;--- ;;--- return, color ;;--- ;;---end ;;---