BEAST-Fitting / beast

Bayesian Extinction And Stellar Tool
http://beast.readthedocs.io
23 stars 34 forks source link

Bug in random_seds method of 'make_ast_inputs' module #785

Closed asmerci closed 4 months ago

asmerci commented 1 year ago

While trying to generate AST inputs by randomly sampling the physics model (using the --random_seds argument), I found what seems to be a bug in '~/beast/tools/run/make_ast_inputs.py'.

Lines 220–223 define 'random_seds' as an optional input for the sed sampling method (i.e. 'pick_method'):

220     if args.random_seds:
221         make_ast_inputs(
222             beast_settings_info=args.beast_settings_file, pick_method="random_seds"
223         )

Running make_ast_inputs with the --random_seds argument results in the following error:

UnboundLocalError: local variable 'chosen_seds' referenced before assignment

To my eye, this seems to be because there is no conditional block for "random_seds". However, a similar method name, "random_pick", is referenced starting on line 89.

 89         if pick_method == "random_pick":
 90 
 91             # construct magnitude cuts
 92             mag_cuts = settings.ast_maglimit
 93             Nfilters = settings.ast_bands_above_maglimit
 94 
 95             if len(mag_cuts) == 1:
 96                 tmp_cuts = mag_cuts
 97                 min_mags = np.zeros(len(settings.filters))
 98                 for k, filtername in enumerate(obsdata.filters):
 99                     sfiltername = obsdata.filter_aliases[filtername]
100                     sfiltername = sfiltername.replace("rate", "vega")
101                     sfiltername = sfiltername.replace("RATE", "VEGA")
102                     (keep,) = np.where(obsdata[sfiltername] < 99.0)
103                     min_mags[k] = np.percentile(obsdata[keep][sfiltername], 90.0)
104 
105                 # max. mags from the gst observation cat.
106                 mag_cuts = min_mags + tmp_cuts
107 
108             N_models = settings.ast_models_selected_per_age
109 
110             chosen_seds = pick_models(
111                 modelsedgrid_filename,
112                 settings.filters,
113                 mag_cuts,
114                 Nfilter=Nfilters,
115                 N_stars=N_models,
116                 Nrealize=Nrealize,
117                 outfile=outfile_seds,
118                 outfile_params=outfile_params,
119             )

Changing this line to

89               if pick_method == "random_seds":

allows the function to run successfully and produces the expected output.