dustem_marginalize_grid.pro 3.21 KB
PRO dustem_marginalize_grid,fixed_parameters_description $
						   ,fixed_parameters_values $
						   ,seds $
						   ,Nseds $
						   ,params $
						   ,Nparams $
						   ,table_params $
						   ,table_pmins $
						   ,table_pmaxs $
						   ,help=help

;+
; NAME:
;    dustem_marginalize_grid
; PURPOSE:
;    marginalize a grid on given fixed parameter
; CATEGORY:
;    Dustem
; CALLING SEQUENCE:
;    dustem_marginalize_grid,fixed_parameters_description,fixed_parameters_values,seds,Nseds,Nfilters,Nparams,table_params,table_pmins,table_pmaxs
; INPUTS:
;    fixed_parameters_description : fixed parameters description
;    fixed_parameters_values      : fixed parameters values
;    seds                         : sed grid to be marginalized (also an output)
;    Nseds                        : Number of seds (also an output)
;    params                       : sed grid parameter values to be marginalized (also an output)
;    Nparams                      : Number of parameters in sed grid (also an output)
;    table_params                 : description of parameters in sed grid (also an output)
;    table_pmins                  : min values of parameters in sed grid (also an output)
;    table_pmaxs                  : max values of parameters in sed grid (also an output)
; OPTIONAL INPUT PARAMETERS:
;    NONE
; OUTPUTS:
;    None
; OPTIONAL OUTPUT PARAMETERS:
;    seds                         : sed grid to be marginalized (also an output)
;    Nseds                        : Number of seds (also an output)
;    Nparams                      : Number of parameters in sed grid (also an output)
;    table_params                 : description of parameters in sed grid (also an output)
;    table_pmins                  : min values of parameters in sed grid (also an output)
;    table_pmaxs                  : max values of parameters in sed grid (also an output)
; ACCEPTED KEY-WORDS:
;    help      = If set, print this help
; COMMON BLOCKS:
;    None
; SIDE EFFECTS:
;    None
; RESTRICTIONS:
;    ;Caution: grids should have regularly spaced parameter values for this to work
; PROCEDURE:
;    None
; EXAMPLES
;    
; MODIFICATION HISTORY:
;    Written by J.-Ph. Bernard (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,'dustem_marginalize_grid'
  goto,the_end
ENDIF


N_fixed_params=n_elements(fixed_parameters_description)

;Nparams=!dustem_grid.Nparams

FOR i=0L,N_fixed_params-1 DO BEGIN
	ind=where(table_params EQ fixed_parameters_description[i],count,complement=indc,ncomplement=nc)
	IF count NE 0 THEN BEGIN
		fixed_parameter_value=fixed_parameters_values[ind[0]]
		;compute distance between table parameter and the requested fixed value
		;distance=abs(fixed_parameter_value-seds[*].(ind[0]))
		distance=abs(fixed_parameter_value-params[*].(ind[0]))
		indd=where(distance EQ min(distance),ccount)
		;stop
		IF ccount EQ 0 THEN BEGIN
			message,'This should not happen',/continue
			stop
		ENDIF
		seds=seds[indd]
		params=params[indd]
		;Nseds=n_elements(seds)   ;or ccount
		Nseds=ccount
		;table_params=table_params[indc]
		;Nparams=nc
		;table_pmins=table_pmins[indc]
		;table_pmaxs=table_pmaxs[indc]
	ENDIF
ENDFOR

the_end:

END