Skip to content

Commit

Permalink
Update bioformats dependency to 8.0.1 (labsyspharm#231)
Browse files Browse the repository at this point in the history
* Change URL and hash for jar artifact

* Adapt bioformats logging call to avoid spurious message

Previously we called enableLogging, but under the latest bioformats that emits
one DEBUG-level message during internal logging setup. This message contains a
stack trace from an internally caught exception which looks extra-scary even
though it's irrelevant. Now we use setRootLevel which suppresses even that
message.

* Skip y-axis stage coords flip for InCell reader

Bioformats 6.4.0 added an explicit correction for the stage y-axis.
  • Loading branch information
jmuhlich authored Nov 25, 2024
1 parent 4027581 commit d1c1ba7
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 17 deletions.
2 changes: 1 addition & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
include versioneer.py
include ashlar/_version.py
recursive-include ashlar/jars *.jar
include ashlar/jars/bioformats_package.jar
16 changes: 10 additions & 6 deletions ashlar/reg.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@

if not jnius_config.vm_running:
pkg_root = pathlib.Path(__file__).parent.resolve()
bf_jar_path = pkg_root / 'jars' / 'loci_tools.jar'
bf_jar_path = pkg_root / 'jars' / 'bioformats_package.jar'
if not bf_jar_path.exists():
raise RuntimeError("loci_tools.jar missing from distribution"
raise RuntimeError("bioformats_package.jar missing from distribution"
" (expected it at %s)" % bf_jar_path)
jnius_config.add_classpath(str(bf_jar_path))
# These settings constrain the memory used by BioFormats to near the minimum
Expand All @@ -48,7 +48,7 @@
ChannelSeparator = jnius.autoclass('loci.formats.ChannelSeparator')
DynamicMetadataOptions = jnius.autoclass('loci.formats.in.DynamicMetadataOptions')
UNITS = jnius.autoclass('ome.units.UNITS')
DebugTools.enableLogging("ERROR")
DebugTools.setRootLevel("ERROR")


# TODO:
Expand Down Expand Up @@ -378,9 +378,13 @@ def tile_position(self, i):
value = v.doubleValue()
values.append(value)
position_microns = np.array(values, dtype=float)
# Invert Y so that stage position coordinates and image pixel
# coordinates are aligned (most formats seem to work this way).
position_microns *= [-1, 1]
# Flip the y-axis of the stage coordinate system to align it with the
# image coordinate system, as seems to be required for most formats.
# Skip this for any formats known not to require it.
if self.format_name not in (
"InCell 1000/2000", # As of Bioformats 6.4.0
):
position_microns *= [-1, 1]
position_pixels = position_microns / self.pixel_size
return position_pixels

Expand Down
20 changes: 10 additions & 10 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,32 +43,32 @@
LICENSE = 'MIT License'
HOMEPAGE = 'https://github.com/sorgerlab/ashlar'

LOCI_TOOLS_URL = 'https://downloads.openmicroscopy.org/bio-formats/6.3.1/artifacts/loci_tools.jar'
LOCI_TOOLS_SHA1 = 'bdf1a37b561fea02fd8d1c747bd34db3fc49667b'
BIOFORMATS_JAR_URL = 'https://downloads.openmicroscopy.org/bio-formats/8.0.1/artifacts/bioformats_package.jar'
BIOFORMATS_JAR_SHA256 = '8c7557a9357a83bf40272292fbd676beb466a9a8bab34126e92a49d636c64bc2'

def download_bioformats():
print("Ensuring latest bioformats is present:")
dist_root = os.path.abspath(os.path.dirname(__file__))
jar_dir = os.path.join(dist_root, 'ashlar', 'jars')
lt_jar_path = os.path.join(jar_dir, 'loci_tools.jar')
lt_jar_path = os.path.join(jar_dir, 'bioformats_package.jar')
if not os.access(jar_dir, os.F_OK):
os.mkdir(jar_dir)
try:
with open(lt_jar_path, 'rb') as f:
existing_sha1 = hashlib.sha1(f.read()).hexdigest()
if existing_sha1 == LOCI_TOOLS_SHA1:
existing_sha256 = hashlib.sha256(f.read()).hexdigest()
if existing_sha256 == BIOFORMATS_JAR_SHA256:
print(" Up to date!")
return
except IOError:
pass
print(" Downloading BioFormats from %s ..." % LOCI_TOOLS_URL)
print(" Downloading BioFormats from %s ..." % BIOFORMATS_JAR_URL)
# FIXME add progress bar
content = urlopen(LOCI_TOOLS_URL).read()
content_sha1 = hashlib.sha1(content).hexdigest()
content = urlopen(BIOFORMATS_JAR_URL).read()
content_sha256 = hashlib.sha256(content).hexdigest()
with open(lt_jar_path, 'wb') as f:
f.write(content)
if content_sha1 != LOCI_TOOLS_SHA1:
raise RuntimeError("loci_tools.jar hash mismatch")
if content_sha256 != BIOFORMATS_JAR_SHA256:
raise RuntimeError("bioformats_package.jar hash mismatch")

# Define some distutils command subclasses for a few key commands to trigger
# downloading the BioFormats JAR before they run.
Expand Down

0 comments on commit d1c1ba7

Please sign in to comment.