- bugfix in czi metadata reader
- cziread now gives empty frame if the frame wasn't saved in the file - astype accepts extra arguments, but does not use them - improved jvm handling - tifread dtype fix
This commit is contained in:
@@ -346,7 +346,6 @@ class Shape(tuple):
|
||||
|
||||
|
||||
class Imread(np.lib.mixins.NDArrayOperatorsMixin):
|
||||
|
||||
def __new__(cls, path=None, *args, **kwargs):
|
||||
if cls is not Imread:
|
||||
return super().__new__(cls)
|
||||
@@ -955,7 +954,7 @@ class Imread(np.lib.mixins.NDArrayOperatorsMixin):
|
||||
def asarray(self):
|
||||
return self.__array__()
|
||||
|
||||
def astype(self, dtype):
|
||||
def astype(self, dtype, *args, **kwargs):
|
||||
new = self.copy()
|
||||
new.dtype = dtype
|
||||
return new
|
||||
|
||||
@@ -18,6 +18,7 @@ try:
|
||||
|
||||
def __init__(self, jars=None):
|
||||
if not self.vm_started and not self.vm_killed:
|
||||
try:
|
||||
jarpath = Path(__file__).parent / 'jars'
|
||||
if jars is None:
|
||||
jars = {}
|
||||
@@ -28,6 +29,11 @@ try:
|
||||
|
||||
import jpype
|
||||
jpype.startJVM(classpath=classpath)
|
||||
except Exception:
|
||||
self.vm_started = False
|
||||
else:
|
||||
self.vm_started = True
|
||||
try:
|
||||
import jpype.imports
|
||||
from loci.common import DebugTools
|
||||
from loci.formats import ImageReader
|
||||
@@ -36,11 +42,13 @@ try:
|
||||
from loci.formats import MetadataTools
|
||||
|
||||
DebugTools.setRootLevel("ERROR")
|
||||
self.vm_started = True
|
||||
|
||||
self.image_reader = ImageReader
|
||||
self.channel_separator = ChannelSeparator
|
||||
self.format_tools = FormatTools
|
||||
self.metadata_tools = MetadataTools
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
if self.vm_killed:
|
||||
raise Exception('The JVM was killed before, and cannot be restarted in this Python process.')
|
||||
@@ -51,8 +59,10 @@ try:
|
||||
dest.parent.mkdir(exist_ok=True)
|
||||
dest.write_bytes(request.urlopen(src).read())
|
||||
|
||||
def kill_vm(self):
|
||||
if self.vm_started and not self.vm_killed:
|
||||
@classmethod
|
||||
def kill_vm(cls):
|
||||
self = cls._instance
|
||||
if self is not None and self.vm_started and not self.vm_killed:
|
||||
import jpype
|
||||
jpype.shutdownJVM()
|
||||
self.vm_started = False
|
||||
|
||||
@@ -58,6 +58,9 @@ class Reader(AbstractReader, ABC):
|
||||
def text(item, default=""):
|
||||
return default if item is None else item.text
|
||||
|
||||
def def_list(item):
|
||||
return [] if item is None else item
|
||||
|
||||
ome = model.OME()
|
||||
|
||||
metadata = tree.find("Metadata")
|
||||
@@ -99,7 +102,7 @@ class Reader(AbstractReader, ABC):
|
||||
model=tubelens.attrib["Name"],
|
||||
nominal_magnification=1.0)) # TODO: nominal_magnification
|
||||
|
||||
for light_source in instrument.find("LightSources"):
|
||||
for light_source in def_list(instrument.find("LightSources")):
|
||||
if light_source.find("LightSourceType").find("Laser") is not None:
|
||||
ome.instruments[0].lasers.append(
|
||||
model.Laser(
|
||||
@@ -222,6 +225,9 @@ class Reader(AbstractReader, ABC):
|
||||
def text(item, default=""):
|
||||
return default if item is None else item.text
|
||||
|
||||
def def_list(item):
|
||||
return [] if item is None else item
|
||||
|
||||
ome = model.OME()
|
||||
|
||||
metadata = tree.find("Metadata")
|
||||
@@ -260,7 +266,7 @@ class Reader(AbstractReader, ABC):
|
||||
lens_na=float(text(objective.find("LensNA"))),
|
||||
nominal_magnification=float(text(objective.find("NominalMagnification")))))
|
||||
|
||||
for light_source in instrument.find("LightSources"):
|
||||
for light_source in def_list(instrument.find("LightSources")):
|
||||
if light_source.find("LightSourceType").find("Laser") is not None:
|
||||
ome.instruments[0].lasers.append(
|
||||
model.Laser(
|
||||
@@ -415,6 +421,7 @@ class Reader(AbstractReader, ABC):
|
||||
|
||||
def __frame__(self, c=0, z=0, t=0):
|
||||
f = np.zeros(self.base.shape['xy'], self.dtype)
|
||||
if (c, z, t) in self.filedict:
|
||||
directory_entries = self.filedict[c, z, t]
|
||||
x_min = min([f.start[f.axes.index('X')] for f in directory_entries])
|
||||
y_min = min([f.start[f.axes.index('Y')] for f in directory_entries])
|
||||
|
||||
@@ -44,6 +44,11 @@ class Reader(AbstractReader, ABC):
|
||||
else:
|
||||
pxsize = None
|
||||
|
||||
dtype = page.dtype.name
|
||||
if dtype not in ('int8', 'int16', 'int32', 'uint8', 'uint16', 'uint32',
|
||||
'float', 'double', 'complex', 'double-complex', 'bit'):
|
||||
dtype = 'float'
|
||||
|
||||
ome = model.OME()
|
||||
ome.instruments.append(model.Instrument(id='Instrument:0'))
|
||||
ome.instruments[0].objectives.append(model.Objective(id='Objective:0'))
|
||||
@@ -53,7 +58,7 @@ class Reader(AbstractReader, ABC):
|
||||
pixels=model.Pixels(
|
||||
id='Pixels:0',
|
||||
size_c=size_c, size_z=size_z, size_t=size_t, size_x=size_x, size_y=size_y,
|
||||
dimension_order="XYCZT", type=page.dtype.name, physical_size_x=pxsize, physical_size_y=pxsize),
|
||||
dimension_order="XYCZT", type=dtype, physical_size_x=pxsize, physical_size_y=pxsize),
|
||||
objective_settings=model.ObjectiveSettings(id="Objective:0")))
|
||||
for c, z, t in product(range(size_c), range(size_z), range(size_t)):
|
||||
ome.images[0].pixels.planes.append(model.Plane(the_c=c, the_z=z, the_t=t, delta_t=0))
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
[tool.poetry]
|
||||
name = "ndbioimage"
|
||||
version = "2023.8.2"
|
||||
version = "2023.9.0"
|
||||
description = "Bio image reading, metadata and some affine registration."
|
||||
authors = ["W. Pomp <w.pomp@nki.nl>"]
|
||||
license = "GPLv3"
|
||||
|
||||
Reference in New Issue
Block a user