losonczylab / sima

Python package for analysis of dynamic fluorescence microscopy data
GNU General Public License v2.0
100 stars 50 forks source link

imaging.py has no attribute 'misc' #172

Closed eflister closed 9 years ago

eflister commented 9 years ago

downloaded/extracted: http://www.losonczylab.org/workflow_data.zip

i tried to run \sima\examples\workflow.py, which works for a while, then:

File "C:\Users\nlab\Downloads\WinPython-64bit-2.7.9.5\python-2.7.9.amd64\lib\site-packages\sima\imaging.py", line 593, in export_averages out = sima.misc.to16bit(im)

AttributeError: 'module' object has no attribute 'misc'

full description: https://groups.google.com/forum/?utm_medium=email&utm_source=footer#!msg/sima-users/lm6gaDcEXX8/vhM4-lf29rkJ

jzaremba commented 9 years ago

Thanks for the report @eflister

I just installed SIMA in a clean WinPython install and I'm unable to reproduce this issue.

What version of sima are you running? import sima; print sima.__version__

Does the following work?

import sima
import numpy as np
sima.misc.to16bit(np.random.random(5))

If they both do, can you post the full output of workflow.py?

eflister commented 9 years ago

What version of sima are you running? import sima; print sima.version

1.2.0

Does the following work?

import sima import numpy as np sima.misc.to16bit(np.random.random(5))

array([65535, 52683, 14832, 48091, 18136], dtype=uint16)

If they both do, can you post the full output of workflow.py?

now the ipython console inside spyder hangs on: Overwrite existing directory (C:\Users\nlab\Desktop\sima\data\workflow_data\workflow_data\dataset.sima)?

it won't accept 'y' or any text, and just sits there. i delete the generated files in C:\Users\nlab\Desktop\sima\data\workflow_data\workflow_data\

i stop ipython (red square in spyder) and try running again (hitting big green arrow in spyder), but ipython console doesn't change, other than stop button turning back to red. i can hit it again, and it turns grey, but hitting run again or typing into ipython console does nothing. i have to restart the kernel.

now we run OK for awhile, and the original error i reported doesn't occur? why not? i haven't rebooted, but i have restarted the kernel and restarted spyder. is that required?

now i get this warning: C:\Users\nlab\Downloads\WinPython-64bit-2.7.9.5\python-2.7.9.amd64\lib\site-packages\matplotlibinit.py:1318: UserWarning: This call to matplotlib.use() has no effect because the backend has already been chosen; matplotlib.use() must be called before pylab, matplotlib.pyplot, or matplotlib.backends is imported for the first time.

warnings.warn(_use_error_msg)

and then this error:

File "C:/Users/nlab/Desktop/sima/examples/workflow.py", line 144, in

show(block=True) File "C:\Users\nlab\Downloads\WinPython-64bit-2.7.9.5\python-2.7.9.amd64\lib\site-packages\matplotlib\pyplot.py", line 155, in show return _show(_args, *_kw) TypeError: show() got an unexpected keyword argument 'block' incidentally, to get opencv working with sima on windows, is it necessary to add \opencv\build\x64\vc12\bin to windows' path, or is it enough to just copy \opencv\build\python\2.7\x64\cv2.pyd to \WinPython-64bit-2.7.9.5\python-2.7.9.amd64\Lib\site-packages\? thanks! -e
eflister commented 9 years ago

now the ipython console inside spyder hangs on: Overwrite existing directory (C:\Users\nlab\Desktop\sima\data\workflow_data\workflow_data\dataset.sima)?

it won't accept 'y' or any text, and just sits there. i delete the generated files in C:\Users\nlab\Desktop\sima\data\workflow_data\workflow_data\

i stop ipython (red square in spyder) and try running again (hitting big green arrow in spyder), but ipython console doesn't change, other than stop button turning back to red. i can hit it again, and it turns grey, but hitting run again or typing into ipython console does nothing. i have to restart the kernel.

this is true in ipython, but it works fine in the regular python console.

now we run OK for awhile, and the original error i reported doesn't occur? why not? i haven't rebooted, but i have restarted the kernel and restarted spyder. is that required?

it also could have been installing picos, bottleneck, or mdp, which i (can't remember) may have done in between tests.

now i get this warning: C:\Users\nlab\Downloads\WinPython-64bit-2.7.9.5\python-2.7.9.amd64\lib\site-packages\matplotlibinit.py:1318: UserWarning: This call to matplotlib.use() has no effect because the backend has already been chosen; matplotlib.use() must be called before pylab, matplotlib.pyplot, or matplotlib.backends is imported for the first time.

warnings.warn(_use_error_msg)

this warning only seems to occur if i have previously imported matplotlib eg at the console.

and then this error:

File "C:/Users/nlab/Desktop/sima/examples/workflow.py", line 144, in

show(block=True) File "C:\Users\nlab\Downloads\WinPython-64bit-2.7.9.5\python-2.7.9.amd64\lib\site-packages\matplotlib\pyplot.py", line 155, in show return _show(_args, *_kw) TypeError: show() got an unexpected keyword argument 'block'

removing (block=True) allows it to complete without error (tho no graph pops up, is one supposed to?) show #(block=True)

pkaifosh commented 9 years ago

Hi Erik,

None of us here use Spyder, so we can't help you much regarding what happens when you stop and start the kernel there.

Regarding your original error, I don't know what to say. If you do manage to find a reproducible way of evoking the error, then we can look into it. But I think I will close the issue until then, since I have checked the code and the imaging.py module does import sima.misc.

Regarding the matplotlib warning, it only occurs if you have already imported matplotlib, as explained in the warning messages.

If you are running in Spyder, you may have to play around with the plotting commands and matplotlib backend. This example script was written with the intent of being run with a simple python command:

$ python workflow.py

eflister commented 9 years ago

it's not spyder, it's ipython. from within ipython running standalone:

%run C:\Users\nlab\Desktop\sima\examples\workflow.py
TIFF filenames:
[['workflow_data/Cycle01_Ch1.tif', 'workflow_data/Cycle01_Ch2.tif'], ['workflow_data/Cycle02_Ch1.tif', 'workflow_data/Cycle02_Ch2.tif'], ['workflow_data/Cycle03_Ch1.tif', 'workflow_data/Cycle03_Ch2.tif'], ['workflow_data/Cycle04_Ch1.tif', 'workflow_data/Cycle04_Ch2.tif'], ['workflow_data/Cycle05_Ch1.tif', 'workflow_data/Cycle05_Ch2.tif'], ['workflow_data/Cycle06_Ch1.tif', 'workflow_data/Cycle06_Ch2.tif'], ['workflow_data/Cycle07_Ch1.tif', 'workflow_data/Cycle07_Ch2.tif'], ['workflow_data/Cycle08_Ch1.tif', 'workflow_data/Cycle08_Ch2.tif'], ['workflow_data/Cycle09_Ch1.tif', 'workflow_data/Cycle09_Ch2.tif'], ['workflow_data/Cycle10_Ch1.tif', 'workflow_data/Cycle10_Ch2.tif'], ['workflow_data/Cycle11_Ch1.tif', 'workflow_data/Cycle11_Ch2.tif'], ['workflow_data/Cycle12_Ch1.tif', 'workflow_data/Cycle12_Ch2.tif'], ['workflow_data/Cycle13_Ch1.tif', 'workflow_data/Cycle13_Ch2.tif'], ['workflow_data/Cycle14_Ch1.tif', 'workflow_data/Cycle14_Ch2.tif'], ['workflow_data/Cycle15_Ch1.tif', 'workflow_data/Cycle15_Ch2.tif']]
Estimating model parameters.
Estimating displacements for cycle  0
Estimating displacements for cycle  1
Estimating displacements for cycle  2
Estimating displacements for cycle  3
Estimating displacements for cycle  4
Estimating displacements for cycle  5
Estimating displacements for cycle  6
Estimating displacements for cycle  7
Estimating displacements for cycle  8
Estimating displacements for cycle  9
Estimating displacements for cycle  10
Estimating displacements for cycle  11
Estimating displacements for cycle  12
Estimating displacements for cycle  13
Estimating displacements for cycle  14
Overwrite existing directory (C:\Users\nlab\Desktop\sima\data\workflow_data\workflow_data\dataset.sima)? ---------------------------------------------------------------------------
EOFError                                  Traceback (most recent call last)
C:\Users\nlab\Desktop\sima\examples\workflow.py in <module>()
     52 dataset = correction_approach.correct(
     53     sequences, dataset_path, channel_names=['tdTomato', 'GCaMP'],
---> 54     trim_criterion=0.95)
     55 
     56 # Export the time averages for a manuscript figure.

C:\Users\nlab\Downloads\WinPython-64bit-2.7.9.5\python-2.7.9.amd64\lib\site-packages\sima\motion\motion.pyc in correct(self, dataset, savedir, channel_names, info, correction_channels, trim_criterion)
    132             s[:, planes, rows, columns] for s in corrected_sequences]
    133         return sima.ImagingDataset(
--> 134             corrected_sequences, savedir, channel_names=channel_names)
    135 
    136 

C:\Users\nlab\Downloads\WinPython-64bit-2.7.9.5\python-2.7.9.amd64\lib\site-packages\sima\imaging.pyc in __init__(self, sequences, savedir, channel_names, read_only)
    140                 pass
    141         elif all(isinstance(s, sima.Sequence) for s in sequences):
--> 142             self.savedir = savedir
    143             self.sequences = sequences
    144             if channel_names is None:

C:\Users\nlab\Downloads\WinPython-64bit-2.7.9.5\python-2.7.9.amd64\lib\site-packages\sima\imaging.pyc in savedir(self, savedir)
    254                     overwrite = strtobool(
    255                         input("Overwrite existing directory ({})? ".format(
--> 256                             savedir)))
    257                     # Note: This will overwrite dataset.pkl and sequences.pkl
    258                     # but will leave all other files in the directory intact

EOFError: EOF when reading a line

that's without typing anything in response to the question regarding overwriting, it just EOF's immediately. within spyder's ipython, you don't see any of that, it just hangs.

other questions from this thread to be addressed: -i tried reproducing the original error by installing a new winpython, sima, and shapely, but nothing else, and running workflow in that same initial session. it didn't reproduce, very strange.

-what about show not recognizing the block argument?

-to get opencv working with sima on windows, is it necessary to add \opencv\build\x64\vc12\bin to windows' path, or is it enough to just copy \opencv\build\python\2.7\x64\cv2.pyd to \WinPython-64bit-2.7.9.5\python-2.7.9.amd64\Lib\site-packages\?

-which segment method implements the method discussed here? http://labrigger.com/blog/2015/04/23/new-spike-inference-for-sima/

thanks!

pkaifosh commented 9 years ago

it's ipython

Yes, the problem does seem to be that IPython doesn't play well with input (python3) or raw_input (python2). There is much literature on this:

https://github.com/ipython/ipython/issues/3990 http://stackoverflow.com/questions/14667144/ipython-raw-input-work-around https://github.com/bollwyvl/hy_kernel/issues/2

Since this is an issue with IPython and not with sima, I'm not reopening this issue.

@eflister Are you using the latest version of IPython? Anyway, this shouldn't really be a problem for you unless you try to save sima datasets to locations where there are already existing sima datasets.

For each of your other issues, please open a separate issue if you think it's a problem with sima, or a separate thread on the forum if you think it is more of a user support inquiry. Thanks.

eflister commented 9 years ago

yes, work-aroundable, but it's not good practice to have interactive input required -- what if called from a batch script, etc? most friendly to provide argument options, auto-backups, or similar to eliminate the need for the interactive input, especially considering incompatibility with ipython.

pkaifosh commented 9 years ago

@eflister Looks like based on #177 we will be eliminating the overwrite prompt.

I still don't mind having the user input prompt in the example workflow.py script though, since this is just for didactic purposes and gives the user a chance to inspect the outputs before moving on with the rest of the example.