allencellmodeling / czifile Goto Github PK
View Code? Open in Web Editor NEWczi reader from https://www.lfd.uci.edu/~gohlke/code/czifile.py.html
License: BSD 3-Clause "New" or "Revised" License
czi reader from https://www.lfd.uci.edu/~gohlke/code/czifile.py.html
License: BSD 3-Clause "New" or "Revised" License
Attempting to use czifile
within a Jupyter notebook installed via Anaconda and am seeing FutureWarning
as so:
/anaconda3/lib/python3.6/site-packages/czifile/czifile.py:400: FutureWarning: Using a non-tuple sequence for multidimensional indexing is deprecated; use `arr[tuple(seq)]` instead of `arr[seq]`. In the future this will be interpreted as an array index, `arr[np.array(seq)]`, which will result either in an error or a different result.
out[index] = tile
Some quick searching seems to be a numpy
warning regarding future deprecation.
Doesn't seem to be causing issues yet, but thought I would mention it.
I've been experimenting with the library on macos, linux, and windows (which generally work great, thank you!) and I encountered a small problem on Windows (10) running in a VM (VMWare) on my mac. The call:
img = czi.asarray()
with no arguments, raises the following error:
C:\Users\sheinb\Anaconda3\lib\site-packages\czifile\czifile.py in func(directory_entry, resize, order, start, out)
393 start=self.start, out=out):
394 """Read, decode, and copy subblock data."""
--> 395 subblock = directory_entry.data_segment()
396 tile = subblock.data(resize=resize, order=order)
397 index = [slice(i-j, i-j+k) for i, j, k in
AttributeError: 'list' object has no attribute 'data_segment'
This virtual machine has 2 CPUs assigned, and multiprocessor.cpu_count seems to report this correctly. I found, though, if I explicitly pass max_workers
as 2, then the call works but if I pass max_workers as 1, it does not. Probably a rare issue (since everyone presumably has >1 CPU) but maybe there's a small issue is this part of the code? My knowledge of executor maps is limited...
if max_workers > 1:
self._fh.lock = True
with ThreadPoolExecutor(max_workers) as executor:
executor.map(func, self.filtered_subblock_directory)
self._fh.lock = None
else:
func(self.filtered_subblock_directory)
I want to use this library to analyze some czi files which are around 1GB each, I want to get ndarray of the image so that I could split it into small batches of the data and feed into neural network to do a classification problem. I stuck at the first step, I want to read the information from the czi file but it return me all zero.
The following is my code
import czifile
from czifile import CziFile
image_arrays.shape
with CziFile('/Users/ziqisu/Documents/138-DCCD-1-CYS-sample.czi') as czi:
image_arrays = czi.asarray
image_arrays.shape
the return value is (1, 1, 1, 1, 3, 38880, 38880, 1)
image_arrays.strides
return value is (9069926400, 9069926400, 9069926400, 9069926400, 3023308800, 77760, 2, 2)
If I just want to see what is image_arrays
Image_arrays[0, 0, 0, 0]
It will give me ndarray of all zero just like:
`array([[[[0],
[0],
[0],
...,
[0],
[0],
[0]],
[[0],
[0],
[0],
...,
[0],
[0],
[0]],
[[0],
[0],
[0],
...,
[0],
[0],
[0]],
...,
[[0],
[0],
[0],
...,
[0],
[0],
[0]],
[[0],
[0],
[0],
...,
[0],
[0],
[0]],
[[0],
[0],
[0],
...,
[0],
[0],
[0]]],
[[[0],
[0],
[0],
...,
[0],
[0],
[0]],
[[0],
[0],
[0],
...,
[0],
[0],
[0]],
[[0],
[0],
[0],
...,
[0],
[0],
[0]],
...,
[[0],
[0],
[0],
...,
[0],
[0],
[0]],
[[0],
[0],
[0],
...,
[0],
[0],
[0]],
[[0],
[0],
[0],
...,
[0],
[0],
[0]]],
[[[0],
[0],
[0],
...,
[0],
[0],
[0]],
[[0],
[0],
[0],
...,
[0],
[0],
[0]],
[[0],
[0],
[0],
...,
[0],
[0],
[0]],
...,
[[0],
[0],
[0],
...,
[0],
[0],
[0]],
[[0],
[0],
[0],
...,
[0],
[0],
[0]],
[[0],
[0],
[0],
...,
[0],
[0],
[0]]]], dtype=uint16)`
I already write down a function to check whether or not it is all zero in the array, it turns out it is all zero.
Is there anyone that could help me figure out what actually happened here? Thank you!
Hi Allen,
I ran czifile using pip and tried fetching decode_jxr function but it is throwing error.
Could you please help me in using decode_jxr ()? Your help is much appreciated
(I am new to this data format, so blindly trying to iterate over continuous chunks of data). Using latest czifile:
import czifile
f = czifile.CziFile('/Users/axelr/Downloads/Brightfield+RAC/2019_02_19__11_16__SL000768.czi')
for block in f.subblocks():
print(block.shape)
print(block.compression)
print(block.data())
break
Result:
---------------------------------------------------------------------------
KeyError Traceback (most recent call last)
<ipython-input-6-a57de3b0f14e> in <module>
6 print(block.shape)
7 print(block.compression)
----> 8 print(block.data())
9 break
~/system1/envs/pipeline/lib/python3.7/site-packages/czifile/czifile.py in data(self, raw, resize, order)
615 fh.seek(self.data_offset)
616 data = fh.read(self.data_size)
--> 617 data = DECOMPRESS[de.compression](data)
618 if de.compression == 2:
619 # LZW
KeyError: 4
can't pip install in a clean environment for lack of Cython
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.