BEAST-Fitting / beast

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

Splitting function still needs both sd_Nbins and sd_binwidth #682

Closed christinawlindberg closed 3 years ago

christinawlindberg commented 3 years ago

I noticed that split_catalog_using_map.split_main() still throws an error when sd_Nbins isn't set in the beast_settings_file it's provided.

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-21-2b20264c03d3> in <module>
      5     ast_file,
      6     gst_file.replace('.fits','_sourceden_map.hd5'), #get full sourceden_mad.hd5 file from dust folder
----> 7     n_per_file=6250, #this is the max number of sources per bin before it splits
      8 
      9 )

~/anaconda3/envs/astroconda/lib/python3.7/site-packages/beast/tools/split_catalog_using_map.py in split_main(beast_settings_info, catfile, astfile, mapfile, n_per_file, min_n_subfile, sort_col)
     75     # catalog can be split using a consistent grouping (= binning) of
     76     # the tiles
---> 77     if not settings.sd_Nbins and not settings.sd_binwidth:
     78         raise RuntimeError(
     79             "You need to specify the source density binning parameters in beast_settings_info"

AttributeError: 'beast_settings' object has no attribute 'sd_Nbins'
cmurray-astro commented 3 years ago

@christinawlindberg have you verified that sd_Nbins is set in your settings file?

christinawlindberg commented 3 years ago

When I set sd_Nbins I get the following warning (this is with sd_binmode = "linear"), which is what I would expect.

---------------------------------------------------------------------------
Exception                                 Traceback (most recent call last)
<ipython-input-112-2b20264c03d3> in <module>
      5     ast_file,
      6     gst_file.replace('.fits','_sourceden_map.hd5'), #get full sourceden_mad.hd5 file from dust folder
----> 7     n_per_file=6250, #this is the max number of sources per bin before it splits
      8 
      9 )

~/anaconda3/envs/astroconda/lib/python3.7/site-packages/beast/tools/split_catalog_using_map.py in split_main(beast_settings_info, catfile, astfile, mapfile, n_per_file, min_n_subfile, sort_col)
     84         bin_mode=settings.sd_binmode,
     85         N_bins=settings.sd_Nbins,
---> 86         bin_width=settings.sd_binwidth,
     87     )
     88 

~/anaconda3/envs/astroconda/lib/python3.7/site-packages/beast/tools/density_map.py in create(density_map, bin_mode, N_bins, bin_width)
    156             if (N_bins is not None) and (bin_width is not None):
    157                 raise Exception(
--> 158                     "Both sd_Nbins and sd_binwidth are set in the beast_settings file. Please set only one!"
    159                 )
    160 

Exception: Both sd_Nbins and sd_binwidth are set in the beast_settings file. Please set only one!

If I choose to only set sd_binwidth, I get the error I originally posted. And if I only set sd_Nbins, I get the following error.

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-114-2b20264c03d3> in <module>
      5     ast_file,
      6     gst_file.replace('.fits','_sourceden_map.hd5'), #get full sourceden_mad.hd5 file from dust folder
----> 7     n_per_file=6250, #this is the max number of sources per bin before it splits
      8 
      9 )

~/anaconda3/envs/astroconda/lib/python3.7/site-packages/beast/tools/split_catalog_using_map.py in split_main(beast_settings_info, catfile, astfile, mapfile, n_per_file, min_n_subfile, sort_col)
     84         bin_mode=settings.sd_binmode,
     85         N_bins=settings.sd_Nbins,
---> 86         bin_width=settings.sd_binwidth,
     87     )
     88 

AttributeError: 'beast_settings' object has no attribute 'sd_binwidth'
cmurray-astro commented 3 years ago

ah okay, the problem is that currently it still needs the parameters to be set, just set to None when not used. I'd add the flexibility to check if the parameter is set at all, but I think for completeness it makes sense to have all the possible parameters still listed in the beast_settings file.... what do you think @karllark ?

karllark commented 3 years ago

but I think for completeness it makes sense to have all the possible parameters still listed in the beast_settings file.... what do you think @karllark ?

Yes. As long as there is appropriate text in beast_settings.txt to say this and why.

galaxyumi commented 3 years ago

@cmurray-astro I would recommend to use 'hasattr' to avoid errors when the optional parameters are not set in the settings file. I did the same thing for a new parameter 'ast_reference_image_hdu_extension'. PR #698