Skip to content

Commit 48b0fe0

Browse files
committed
Use coords_array instead of scale_array variable
The scale is dervied from the 1D coordinates array associated with a particlar axis. For clarity, this commit replaces parameters/variables that use scale_array with coords_array.
1 parent 0126d00 commit 48b0fe0

File tree

1 file changed

+16
-16
lines changed

1 file changed

+16
-16
lines changed

src/imagej/dims.py

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -195,9 +195,9 @@ def _assign_axes(xarr: xr.DataArray):
195195
axis_str = _convert_dim(dim, direction="java")
196196
ax_type = jc.Axes.get(axis_str)
197197
ax_num = _get_axis_num(xarr, dim)
198-
scale_arr = xarr.coords[dim].to_numpy()
198+
coords_arr = xarr.coords[dim].to_numpy()
199199

200-
if _is_numeric_scale(scale_arr):
200+
if _is_numeric_scale(coords_arr):
201201
doub_coords = [Double(np.double(x)) for x in xarr.coords[dim]]
202202
else:
203203
_logger.warning(
@@ -214,7 +214,7 @@ def _assign_axes(xarr: xr.DataArray):
214214
if EnumeratedAxis is not None:
215215
java_axis = EnumeratedAxis(ax_type, sj.to_java(doub_coords))
216216
else:
217-
java_axis = _get_linear_axis(ax_type, scale_arr, sj.to_java(doub_coords))
217+
java_axis = _get_linear_axis(ax_type, coords_arr, sj.to_java(doub_coords))
218218

219219
axes[ax_num] = java_axis
220220

@@ -284,23 +284,23 @@ def _get_enumerated_axis():
284284
return None
285285

286286

287-
def _get_linear_axis(axis_type: "jc.AxisType", scale_array: np.ndarray, values):
287+
def _get_linear_axis(axis_type: "jc.AxisType", coords_array: np.ndarray, values):
288288
"""Get linear axis.
289289
290290
This is used if no EnumeratedAxis is found. If EnumeratedAxis
291291
is available, use _get_enumerated_axis() instead.
292292
"""
293293
DefaultLinearAxis = sj.jimport("net.imagej.axis.DefaultLinearAxis")
294294
origin = values[0]
295-
if len(scale_array) <= 1:
295+
if len(coords_array) <= 1:
296296
scale = 1
297297
else:
298-
scale = _compute_slope(scale_array)
298+
scale = _compute_slope(coords_array)
299299
axis = DefaultLinearAxis(axis_type, scale, origin)
300300
return axis
301301

302302

303-
def _compute_slope(axis):
303+
def _compute_slope(coords_array):
304304
"""Compute slope (i.e. scale) of an axis.
305305
306306
Each axis will have an associated coodinates array (1D) which
@@ -310,10 +310,10 @@ def _compute_slope(axis):
310310
array. The calculated slope is then used as the 'scale'
311311
parameter for creating an ImageJ2 DefaultLinenarAxis.
312312
313-
:param axis: List like 1D array with indexing.
313+
:param coords_array: List like 1D array with indexing.
314314
:return: Slope of the axis.
315315
"""
316-
n = len(axis)
316+
n = len(coords_array)
317317
sum_x = 0
318318
sum_y = 0
319319
sum_xy = 0
@@ -322,22 +322,22 @@ def _compute_slope(axis):
322322

323323
for i in range(n):
324324
sum_x += i
325-
sum_y += axis[i]
326-
sum_xy += i * axis[i]
325+
sum_y += coords_array[i]
326+
sum_xy += i * coords_array[i]
327327
sum_x2 += i**2
328-
sum_y2 += axis[i] ** 2
328+
sum_y2 += coords_array[i] ** 2
329329

330330
return ((n * sum_xy) - (sum_x * sum_y)) / ((n * sum_x2) - (sum_x**2))
331331

332332

333-
def _is_numeric_scale(scale: np.ndarray) -> bool:
333+
def _is_numeric_scale(coords_array: np.ndarray) -> bool:
334334
"""
335-
Checks if the scale of the given axis is numeric.
335+
Checks if the coordinates array of the given axis is numeric.
336336
337-
:param scale: A 1D NumPy array.
337+
:param coords_array: A 1D NumPy array.
338338
:return: bool
339339
"""
340-
return np.issubdtype(scale.dtype, np.number)
340+
return np.issubdtype(coords_array.dtype, np.number)
341341

342342

343343
def _dataset_to_imgplus(rai: "jc.RandomAccessibleInterval") -> "jc.ImgPlus":

0 commit comments

Comments
 (0)