diff --git a/sourcefinder/config.py b/sourcefinder/config.py index 99d68e8..b2b2d83 100644 --- a/sourcefinder/config.py +++ b/sourcefinder/config.py @@ -203,18 +203,25 @@ class ImgConf(_Validate): """ - back_size_x: int | None = 32 + back_size_x: int | None = None """Subimage size for estimation of background node values (X direction). The nodes are centred on the subimages. """ - back_size_y: int | None = 32 + back_size_y: int | None = None """Subimage size for estimation of background node values (Y direction). The nodes are centred on the subimages. """ + grid: int | None = 64 + """Background subimage size used as fallback for back_size_x and + back_size_y. If both are not set, this implies + back_size_x=backsize_y=grid, i.e. the subimages are squares. + + """ + eps_ra: float = 0.0 """Calibration uncertainty in right ascension (degrees), see equation 27a of the NVSS paper. @@ -326,13 +333,6 @@ class ImgConf(_Validate): deblend_nthresh: int = 0 """Number of deblending subthresholds; 0 to disable.""" - grid: int | None = None - """Background subimage size used as fallback for back_size_x and - back_size_y. If both are not set, this implies - back_size_x=backsize_y=grid, i.e. the subimages are squares. - - """ - bmaj: float | None = None """Set beam: Major axis of restoring beam (degrees).""" diff --git a/sourcefinder/image.py b/sourcefinder/image.py index c8ab4d5..696e513 100644 --- a/sourcefinder/image.py +++ b/sourcefinder/image.py @@ -10,9 +10,7 @@ from numba import guvectorize, float32, int32 import pandas as pd -from sourcefinder import extract -from sourcefinder import stats -from sourcefinder import utils +from sourcefinder import extract, stats, utils from sourcefinder.config import Conf, ImgConf, ExportSettings from sourcefinder.utility import containers from sourcefinder.utility.uncertain import Uncertain diff --git a/sourcefinder/utility/cli.py b/sourcefinder/utility/cli.py index e6d3058..f7f7af7 100755 --- a/sourcefinder/utility/cli.py +++ b/sourcefinder/utility/cli.py @@ -34,6 +34,7 @@ import astropy.io.fits as pyfits import numpy +import sourcefinder from sourcefinder.accessors import open as open_accessor from sourcefinder.accessors import sourcefinder_image_from_accessor from sourcefinder.accessors import writefits as tkp_writefits @@ -124,6 +125,13 @@ def construct_argument_parser(): """, ) + general_group.add_argument( + "-v", + "--version", + action="version", + version=f"PySE {sourcefinder.__version__} (Python {sys.version.split()[0]})", + ) + image_group = parser.add_argument_group("Image parameters") image_group.add_argument( @@ -456,11 +464,21 @@ def excepthook(type, value, traceback): # command line we get a None value, ignore these cli_args[section_name][arg_name] = cli_value + image_args = cli_args["Image parameters"] + # Handle grid vs back-size-x/y precedence + if image_args.get("grid") is not None: + if image_args.get("back_size_x") is None: + image_args["back_size_x"] = image_args["grid"] + if image_args.get("back_size_y") is None: + image_args["back_size_y"] = image_args["grid"] + # Note: Dataclass replace is not recursive for stacked dataclasses. # Replace one by one to avoid arguments being reset to their # defaults. - conf_image = replace(conf.image, **cli_args["Image parameters"]) + conf_image = replace(conf.image, **image_args) conf_export = replace(conf.export, **cli_args["Export parameters"]) + # The functions skymodel, csv, summary and regions are currently not able + # to handle Pandas DataFrames. no_pandas_df_dict = {"pandas_df": False} conf_export = replace(conf_export, **no_pandas_df_dict) conf = replace(conf, image=conf_image, export=conf_export) @@ -581,7 +599,9 @@ def run_sourcefinder(files, conf, mode): if mode == "fixed": sr = imagedata.fit_fixed_positions( - eval(conf.image.fixed_posns), # fixed_posns is a string, use eval to obtain it's contents + eval( + conf.image.fixed_posns + ), # fixed_posns is a string, use eval to obtain it's contents conf.image.ffbox * max(imagedata.beam[0:2]), ) diff --git a/test/test_image.py b/test/test_image.py index 7a591bf..d2dcea1 100644 --- a/test/test_image.py +++ b/test/test_image.py @@ -79,7 +79,8 @@ def setUp(self): eye in DS9 """ self.image = accessors.sourcefinder_image_from_accessor( - accessors.open(os.path.join(DATAPATH, "NCP_sample_image_1.fits")) + accessors.open(os.path.join(DATAPATH, "NCP_sample_image_1.fits")), + conf=Conf(ImgConf(grid=32), export=ExportSettings()), ) self.assertListEqual(list(self.image.data.shape), [1024, 1024]) self.boxsize = BOX_IN_BEAMPIX * max( @@ -389,7 +390,7 @@ def testSingleSourceExtraction(self): # Start with comparing results from fitting with ground truth results # from fitting. This implies "vectorized==False". conf_fitting = Conf( - image=ImgConf(detection_thr=5, vectorized=False), + image=ImgConf(detection_thr=5, grid=32, vectorized=False), export=ExportSettings( source_params=source_params, pandas_df=False ), @@ -417,7 +418,7 @@ def testSingleSourceExtraction(self): # Next, compare results from "tweaked moments" with ground truth results # from "tweaked moments". This implies "vectorized==True". conf_moments = Conf( - image=ImgConf(detection_thr=5, vectorized=True), + image=ImgConf(detection_thr=5, grid=32, vectorized=True), export=ExportSettings( source_params=source_params, pandas_df=False ), @@ -451,7 +452,7 @@ def testForceSourceShape(self): major/minor axes to be held constant when fitting. """ conf = Conf( - image=ImgConf(detection_thr=5, force_beam=True), + image=ImgConf(detection_thr=5, grid=32, force_beam=True), export=ExportSettings(pandas_df=False), ) image = accessors.sourcefinder_image_from_accessor( @@ -470,7 +471,7 @@ def testWcsConversionConsistency(self): """ conf = Conf( - image=ImgConf(detection_thr=5), + image=ImgConf(detection_thr=5, grid=32), export=ExportSettings(pandas_df=False), ) fits_image = accessors.sourcefinder_image_from_accessor( @@ -514,7 +515,7 @@ def testNoLabelledIslandsCase(self): image = accessors.sourcefinder_image_from_accessor( FitsImage(GRB120422A), conf=Conf( - ImgConf(detection_thr=5e10, analysis_thr=5e10), + ImgConf(detection_thr=5e10, grid=32, analysis_thr=5e10), export=ExportSettings(pandas_df=False), ), )