Skip to content

Commit 581b7c1

Browse files
authored
Merge pull request #145 from transientskp/make_cli_backwards_compatible
Use back-size-x/y if set, fall back to grid parameter from config.
2 parents 09e1efd + 88b42e1 commit 581b7c1

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

sourcefinder/config.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -158,16 +158,16 @@ class ImgConf(_Validate):
158158
allow_multiprocessing: bool = True # Allow multiprocessing for Gaussian fitting in parallel.
159159
margin: int = 0 # Margin in pixels to ignore around the edge of the image.
160160
radius: float = 0.0 # Radius in pixels around sources to include in analysis.
161-
back_size_x: int = 32 # Background estimation box size (X direction).
162-
back_size_y: int = 32 # Background estimation box size (Y direction).
161+
back_size_x: int | None = 32 # Background estimation box size (X direction).
162+
back_size_y: int | None = 32 # Background estimation box size (Y direction).
163163
eps_ra: float = 0.0 # RA matching tolerance in arcseconds.
164164
eps_dec: float = 0.0 # Dec matching tolerance in arcseconds.
165165
detection: float = 10.0 # Detection threshold.
166166
analysis: float = 3.0 # Analysis threshold.
167167
fdr: bool = False # Use False Detection Rate (FDR) algorithm.
168168
alpha: float = 1e-2 # FDR alpha value (significance level).
169169
deblend_thresholds: int = 0 # Number of deblending subthresholds; 0 to disable.
170-
grid: int = 64 # Background grid segment size.
170+
grid: int | None = None # Background grid segment size used as fallback for back-size-x and back-size-y.
171171
bmaj: float | None = None # Set beam: Major axis of beam (degrees).
172172
bmin: float | None = None # Set beam: Minor axis of beam (degrees).
173173
bpa: float | None = None # Set beam: Beam position angle (degrees).

sourcefinder/image.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -223,14 +223,22 @@ def __grids(self):
223223
useful_chunk = ndimage.find_objects(np.where(self.data.mask, 0, 1))
224224
assert (len(useful_chunk) == 1)
225225
x_dim, y_dim = self.data[useful_chunk[0]].shape
226+
# Use 'back-size-x' and 'back-size-y' if available, fall back to 'grid'.
227+
back_size_x = self.conf.image.back_size_x or self.conf.image.grid
228+
if back_size_x is None:
229+
raise ValueError("Expected either back-size-x or grid to be set in the config object")
230+
back_size_y = self.conf.image.back_size_y or self.conf.image.grid
231+
if back_size_y is None:
232+
raise ValueError("Expected either back-size-y or grid to be set in the config object")
226233
# We should divide up the image into subimages such that each grid
227234
# node is centered on a subimage. This is only possible if
228235
# self.back_size_x and self.back_size_y are divisors of xdim and ydim,
229236
# respectively. If not, we need to select a frame within useful_chunk
230237
# that does have the appropriate dimensions. At the same time, it should
231238
# be as large as possible and centered within useful_chunk.
232-
rem_row = np.mod(x_dim, self.conf.image.back_size_x)
233-
rem_col = np.mod(y_dim, self.conf.image.back_size_y)
239+
rem_row = np.mod(x_dim, back_size_x)
240+
rem_col = np.mod(y_dim, back_size_y)
241+
234242
start_offset_row, rem_rem_row = divmod(rem_row, 2)
235243
start_offset_col, rem_rem_col = divmod(rem_col, 2)
236244
end_offset_row = start_offset_row + rem_rem_row
@@ -245,8 +253,8 @@ def __grids(self):
245253

246254
# Before proceeding, check that our data has the size of at least
247255
# one subimage, for both dimensions.
248-
if (centred_inds[1] - centred_inds[0] > self.conf.image.back_size_x and
249-
centred_inds[3] - centred_inds[2] > self.conf.image.back_size_y):
256+
if (centred_inds[1] - centred_inds[0] > back_size_x and
257+
centred_inds[3] - centred_inds[2] > back_size_y):
250258

251259
subimages, number_of_elements_for_each_subimage = \
252260
utils.make_subimages(self.data.data[centred_inds[0]:
@@ -257,7 +265,7 @@ def __grids(self):
257265
centred_inds[1],
258266
centred_inds[2]:
259267
centred_inds[3]],
260-
self.conf.image.back_size_x, self.conf.image.back_size_y)
268+
back_size_x, back_size_y)
261269

262270
mean_grid = np.zeros(number_of_elements_for_each_subimage.shape,
263271
dtype=np.float32)

0 commit comments

Comments
 (0)