Skip to content

Commit d474b6a

Browse files
committed
Split pub citation and version citation functions
This commit splits the former ij.py.cite() method into cite_publication() and cite_versions() which produce the PyImageJ citation string and the environment packages seperately.
1 parent 9013e7b commit d474b6a

File tree

1 file changed

+64
-18
lines changed

1 file changed

+64
-18
lines changed

src/imagej/__init__.py

Lines changed: 64 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
import scyjava as sj
4949
import xarray as xr
5050
from jpype import JImplementationFor, setupGuiEnvironment
51+
from jpype import __version__ as _jpype_version
5152
from scyjava.config import find_jars
5253

5354
import imagej.convert as convert
@@ -164,43 +165,88 @@ def argstring(self, args, ij1_style=True):
164165
formatted_args.append(arg)
165166
return " ".join(formatted_args)
166167

167-
def cite(self, show: bool = True) -> str:
168-
"""Generate a citation string and package version numbers.
168+
def cite_publication(self, show: bool = True) -> str:
169+
"""Generate a citation string.
169170
170-
Generate the PyImageJ citation/reference string and fetch
171-
the environments Python and Java versions.
171+
Generate the PyImageJ citation/reference string.
172172
173173
:param show: Print the PyImageJ citation if True, if False
174174
the PyImageJ citation string is returned instead.
175-
:return: A citation and package version numbers
175+
:return: The PyImageJ citation.
176176
"""
177177
# set PyImageJ reference sub strings
178-
authors = "Rueden, C.T., Hiner, M.C., Evans, E.L. et al."
178+
header = "=====PyImageJ Citation====="
179+
authors = "\nRueden, C.T., Hiner, M.C., Evans, E.L. et al."
179180
pub_title = "\nPyImageJ: A library for integrating ImageJ and Python."
180181
journal = "\nNat Methods 19, 1326–1327 (2022)."
181182
doi_link = "\nhttps://doi.org/10.1038/s41592-022-01655-4"
182-
divider = "\n-----------------------"
183-
# collect the current Python version
184-
py_vi = sys.version_info
185-
python_version = f"\nPython version: {py_vi.major}.{py_vi.minor}.{py_vi.micro}"
186-
# collect the current Java version
187-
j_vi = sj.jvm_version()
188-
java_version = f"\nJava version: {j_vi[0]}.{j_vi[1]}.{j_vi[2]}"
189-
# construct final string
183+
184+
# construct output citation string
190185
citation = (
191-
authors
186+
header
187+
+ authors
192188
+ pub_title
193189
+ journal
194190
+ doi_link
195-
+ divider
196-
+ python_version
197-
+ java_version
198191
)
199192
if show:
200193
print(citation)
201194
else:
202195
return citation
203196

197+
def cite_versions(self, show: bool = True) -> str:
198+
"""Fetch the current environment's package versions.
199+
200+
Fetch and construct the current environment's package versions.
201+
This function returns the versions for:
202+
- Python
203+
- Java
204+
- pyimagej
205+
- scyjava
206+
- imglyb
207+
- jgo
208+
- jpype
209+
210+
:param show: Print the PyImageJ citation if True, if False
211+
the PyImageJ citation string is returned instead.
212+
:param show: Print the version numbers if True, if False
213+
the environment version number string is returned instead.
214+
:return: The current PyImageJ instance's package versions.
215+
"""
216+
# collect the current isntance's package versions
217+
py_ver = sys.version_info
218+
java_ver = sj.jvm_version()
219+
pyimagej_ver = __version__
220+
scyjava_ver = sj.get_version("scyjava")
221+
imglyb_ver = sj.get_version("imglyb")
222+
jpype_ver = _jpype_version
223+
jgo_ver = sj.get_version("jgo")
224+
225+
# construct version strings
226+
header = "=====Environment package versions====="
227+
python_ver_str = f"\nPython: {py_ver.major}.{py_ver.minor}.{py_ver.micro}"
228+
java_ver_str = f"\nJava: {java_ver[0]}.{java_ver[1]}.{java_ver[2]}"
229+
pyimagej_ver_str = f"\npyimagej: {pyimagej_ver}"
230+
scyjava_ver_str = f"\nscyjava: {scyjava_ver}"
231+
imglyb_ver_str = f"\nimglyb: {imglyb_ver}"
232+
jgo_ver_str = f"\njgo: {jgo_ver}"
233+
jpype_ver_str = f"\njpype: {jpype_ver}"
234+
235+
# construct output version string
236+
versions = (
237+
header
238+
+ python_ver_str
239+
+ java_ver_str
240+
+ scyjava_ver_str
241+
+ imglyb_ver_str
242+
+ jgo_ver_str
243+
+ jpype_ver_str
244+
)
245+
if show:
246+
print(versions)
247+
else:
248+
return versions
249+
204250
def dtype(self, image_or_type):
205251
"""Get the dtype of the input image as a numpy.dtype object.
206252

0 commit comments

Comments
 (0)