Skip to content

Commit 0479a3c

Browse files
committed
Add java.lang.Double to JavaClasses
This is easier to read and more efficient as it avoids repeated jimports of 'java.lang.Double' on each Python -> Java image conversion request.
1 parent 48b0fe0 commit 0479a3c

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

src/imagej/_java.py

+4
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ class MyJavaClasses(JavaClasses):
3030
significantly easier and more readable.
3131
"""
3232

33+
@JavaClasses.java_import
34+
def Double(self):
35+
return "java.lang.Double"
36+
3337
@JavaClasses.java_import
3438
def Throwable(self):
3539
return "java.lang.Throwable"

src/imagej/dims.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -184,8 +184,6 @@ def _assign_axes(xarr: xr.DataArray):
184184
:param xarr: xarray that holds the units
185185
:return: A list of ImageJ Axis with the specified origin and scale
186186
"""
187-
Double = sj.jimport("java.lang.Double")
188-
189187
axes = [""] * len(xarr.dims)
190188

191189
# try to get EnumeratedAxis, if not then default to LinearAxis in the loop
@@ -198,14 +196,14 @@ def _assign_axes(xarr: xr.DataArray):
198196
coords_arr = xarr.coords[dim].to_numpy()
199197

200198
if _is_numeric_scale(coords_arr):
201-
doub_coords = [Double(np.double(x)) for x in xarr.coords[dim]]
199+
doub_coords = [jc.Double(np.double(x)) for x in xarr.coords[dim]]
202200
else:
203201
_logger.warning(
204202
f"The {ax_type.label} axis is non-numeric and is translated "
205203
"to a linear index."
206204
)
207205
doub_coords = [
208-
Double(np.double(x)) for x in np.arange(len(xarr.coords[dim]))
206+
jc.Double(np.double(x)) for x in np.arange(len(xarr.coords[dim]))
209207
]
210208

211209
# EnumeratedAxis is a new axis made for xarray, so is only present in

0 commit comments

Comments
 (0)