Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions sourcefinder/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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)."""

Expand Down
4 changes: 1 addition & 3 deletions sourcefinder/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
24 changes: 22 additions & 2 deletions sourcefinder/utility/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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]),
)

Expand Down
13 changes: 7 additions & 6 deletions test/test_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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
),
Expand Down Expand Up @@ -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
),
Expand Down Expand Up @@ -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(
Expand All @@ -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(
Expand Down Expand Up @@ -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),
),
)
Expand Down