Not working as library

223 views
Skip to first unread message

Gozdriov

unread,
Jun 27, 2013, 10:57:22 PM6/27/13
to hypersp...@googlegroups.com
Hi Guys, 

I'm trying to run Hyperspy as Library into iPython, but I'm getting an error that I suppose is an environment variable issue, I'm working in Windows7

with 

import hyperspy.hspy as hspy

I got:
---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
<ipython-input-3-54446973a401> in <module>()
      7 from skimage import io
      8 from scipy.signal import argrelextrema
----> 9 import hyperspy.hspy as hspy

ImportError: No module named hyperspy.hspy


I installed Hyperspy in 
C:\Program Files\Hyperspy\python-2.7.4
and my python is in 
C:\Python27

any help will be kindly appreciated.

Thanks


Francisco de la Peña

unread,
Jun 28, 2013, 1:18:35 AM6/28/13
to hypersp...@googlegroups.com
Hi,

That should work unless you have two separate Python installations. How did you install Hyperpsy? If you have installed the "Full version" and you already had a Python installation in your system from where you're trying to import Hyperspy that doesn't work. The "Full version" contains a portable Python distribution (WinPython) that is independent from your system's Python. To install Hyperspy in your system's Python you can download the Python installer from PyPi. This may require manually installing a number of other libraries. For Windows you can find them all here.

Does this solve your problem?

Best,

Francisco


2013/6/28 Gozdriov <gozd...@gmail.com>

--
You received this message because you are subscribed to the Google Groups "hyperspy-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to hyperspy-user...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Gozdriov

unread,
Jun 28, 2013, 11:05:47 AM6/28/13
to hypersp...@googlegroups.com
Thanks Francisco,

That seems to make sense,

However, I'm still having a problem, with a part of traits....once I've intalled all the required libraries and try again to import hyperspy like the example the documentation:


import hyperspy.hspy as hspy
import numpy as np
import matplotlib.pyplot as plt

an Impot error appears:

---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
<ipython-input-1-6cc9b4f691be> in <module>()
----> 1 import hyperspy.hspy as hspy
      2 import numpy as np
      3 import matplotlib.pyplot as plt

C:\Python27\Lib\site-packages\hyperspy\hspy.py in <module>()
     26 matplotlib.rcParams['image.cmap'] = 'gray'
     27 from hyperspy import Release
---> 28 from hyperspy import components
     29 from hyperspy import signals
     30 from hyperspy.io import load

C:\Python27\Lib\site-packages\hyperspy\components\__init__.py in <module>()
     27 '''
     28 
---> 29 from hyperspy.components.arctan import Arctan
     30 from hyperspy.components.bleasdale import Bleasdale
     31 from hyperspy.components.eels_double_offset import DoubleOffset

C:\Python27\Lib\site-packages\hyperspy\components\arctan.py in <module>()
     19 import numpy as np
     20 
---> 21 from hyperspy.component import Component
     22 
     23 class Arctan(Component):

C:\Python27\Lib\site-packages\hyperspy\component.py in <module>()
     21 import numpy as np
     22 
---> 23 from hyperspy.defaults_parser import preferences
     24 from hyperspy.misc.utils import (incremental_filename,
     25                                   append2pathname,

C:\Python27\Lib\site-packages\hyperspy\defaults_parser.py in <module>()
     29 from hyperspy.misc.utils import DictionaryBrowser
     30 from hyperspy.misc.interactive_ns import turn_logging_on, turn_logging_off
---> 31 from hyperspy.io import default_write_ext
     32 
     33 defaults_file = os.path.join(config_path, 'hyperspyrc')

C:\Python27\Lib\site-packages\hyperspy\io.py in <module>()
     25 from hyperspy.io_plugins import (msa, digital_micrograph, fei, mrc,
     26     ripple, tiff)
---> 27 from hyperspy.gui.tools import Load
     28 from hyperspy.misc import utils
     29 from hyperspy.misc.utils import (ensure_directory,strlist2enumeration)

C:\Python27\Lib\site-packages\hyperspy\gui\tools.py in <module>()
     33 from hyperspy.misc.tv_denoise import _tv_denoise_1d
     34 from hyperspy.drawing.utils import does_figure_object_exists
---> 35 from hyperspy.gui.mpl_traits_editor import MPLFigureEditor
     36 from hyperspy.axes import AxesManager
     37 from hyperspy.drawing.widgets import DraggableVerticalLine

C:\Python27\Lib\site-packages\hyperspy\gui\mpl_traits_editor.py in <module>()
      3 # The author is Gael Varoquaux
      4 
----> 5 import wx
      6 
      7 import matplotlib

ImportError: No module named wx


I installed the ETS, the Enthought Tool Suite, with traits but I don't know how to sort it out.

Thanks

All the best

Gozdriov

Francisco de la Peña

unread,
Jun 28, 2013, 11:17:27 AM6/28/13
to hypersp...@googlegroups.com
It seems that you don't have the wx libraries installed. Could you try installing wxPython and wxPython-common from
here ?

Btw, I guess that you're using EPD Free that ships with very few libraries, why don't you use Hyperspy the Python distribution shipped with Hyperspy instead?

Gozdriov

unread,
Jun 28, 2013, 11:43:27 PM6/28/13
to hypersp...@googlegroups.com
Hi Francisco,

It will be the best, 

another question, if I have:

<EELSSpectrum, title: spim01, dimensions: (29, 83, 1440)>

how can I make a np.array that has dimensions (29,83) and in each point the sum or integration of all the EELS?

something like: 

s1 = np.array([sum(s[:,:,i]) for i in range(1440)]) ??

Thanks

best

Gozdriov

Francisco de la Peña

unread,
Jun 29, 2013, 2:12:57 AM6/29/13
to hypersp...@googlegroups.com
Hi Gozdriov,

You can try the sum or integrate_simpson methods, e.g.

>>> s = signals.Spectrum(np.random.random((83, 29, 1440)))
>>> s
<Spectrum, title: , dimensions: (29, 83, 1440)>
>>> s1 = s.sum(-1)
>>> s1
<Spectrum, title: , dimensions: (29, 83)>

Note that, although s1 is a Spectrum the view is not well configured after the sum operation (this is because hyperspy cannot guess what you want):

>>> s1.axes_manager
<Axes manager, axes: (<axis1 axis, size: 29, index: 0>, <axis0 axis, size: 83, index: 0>)>
>>> s1.axes_manager.signal_dimension
0

If you want to operate on the data as if it was a line spectrum:

>>> s1.axes_manager.set_signal_dimension(1)
>>> s1.axes_manager
<Axes manager, axes: (<axis0 axis, size: 83, index: 0>, <axis1 axis, size: 29>)>

And If you want to operate on the data as if it was an image:

>>> s1.axes_manager.set_signal_dimension(2)
>>> s1.axes_manager
<Axes manager, axes: (<axis1 axis, size: 29>, <axis0 axis, size: 83>)>


However, because most likely you want to opearate on the data using an Image object (vs just an image view) it is better to do the following:

>>> im = s1.as_image((0, 1))
>>> im
<Image, title: , dimensions: (29, 83)>

`as_image` is a new command that we're introducing in version 0.7 that will be released today.

Best,

Francisco




2013/6/29 Gozdriov <gozd...@gmail.com>

Francisco de la Peña

unread,
Jun 29, 2013, 4:59:24 AM6/29/13
to hypersp...@googlegroups.com
I failed to mention in my previous post that a simpler and more natural way to obtain an Image object is to transform the spectrum in an Image before summing:

>>> im = s.to_image().sum(0)
>>> im
<Image, title: , dimensions: (29, 83)>

This works in Hypersy 0.6

Best,

Francisco


2013/6/29 Francisco de la Peña <frande...@gmail.com>

Gozdriov

unread,
Jun 29, 2013, 10:31:40 PM6/29/13
to hypersp...@googlegroups.com
Hi Francisco,

Thanks for your prompt reply.

Another one. if I just want to sum over a certain range and that the intensity in the image for (x,y) pixel is the value of that sum?

something like:

im = s.to_image().sum(500:700)  ???

and how can I print values?

Thanks

Gozdriov

Gozdriov

unread,
Jun 30, 2013, 2:44:44 AM6/30/13
to hypersp...@googlegroups.com
Hi Francisco, 

is there a way to collapse one of the dimensions like in a line scan, I mean, from 

>>> s = signals.Spectrum(np.random.random((83, 29, 1440)))
>>> s
<Spectrum, title: , dimensions: (29, 83, 1440)>

end up with the EELS of the 29 rows (or columns) added together, a line of   

<Spectrum, title: , dimensions: (83, 1440)>

It will be equivalent to a DM selection of a row with the cursor on a SI.

Thanks

Gozdriov

Francisco de la Peña

unread,
Jun 30, 2013, 3:03:40 AM6/30/13
to hypersp...@googlegroups.com
Hi Gozdriov,

>>> s = signals.Spectrum(np.random.random((83, 29, 1440)))
>>> s
<Spectrum, title: , dimensions: (29, 83, 1440)>

end up with the EELS of the 29 rows (or columns) added together, a line of   

<Spectrum, title: , dimensions: (83, 1440)>

It will be equivalent to a DM selection of a row with the cursor on a SI.


Is this what you want?

>>> s.sum(0)

<Spectrum, title: , dimensions: (83, 1440)>

Another one. if I just want to sum over a certain range and that the intensity in the image for (x,y) pixel is the value of that sum?

something like:

im = s.to_image().sum(500:700)  ???

The following should do what you want:

>>> im = s.to_image()[500:700].sum(0)

Note that this sums from channel 500 to channel 700. If you want to sum from axis value 500 to axis value 700 you can do it as follows:

>>> im = s.to_image()[500.:700.].sum(0)

Al these features are documented here.


and how can I print values?

The numpy array is always in the data attribute of the signal e.g.

>>> print s.to_image()[500.:700.].sum(0).data


Best,

Francisco

Gozdriov

unread,
Jun 30, 2013, 6:54:00 AM6/30/13
to hypersp...@googlegroups.com
Hi Francisco,

Thanks for the link, I'll look at it more carefully, =)

best

Gozdriov

Gozdriov

unread,
Jul 2, 2013, 10:44:57 PM7/2/13
to hypersp...@googlegroups.com
Hi Francisco,

Is there a way to get the onset value for a

<EELSSpectrum, title: SP01, dimensions: (29, 83, 1440)>

something similar to estimate_zero_loss_centre but for the starting of an edge and that returns a value for each spectrum???

Thanks

Best

Gozdriov


Francisco de la Peña

unread,
Jul 3, 2013, 12:03:50 PM7/3/13
to hypersp...@googlegroups.com
Hi Gozdriov,

No, we don't have edge detection. The closest thing that we have is find_peaks1D_ohaver. It could roughly work for edge detection when applied to the diffentiated spectrum. Are you thinking in something more sophisticated?

By the way, could you open a new thread for any future discussion that is not related to the original subject of this one ("Not working as a library"). In this way other users will have an easier time finding the information.

Best,

Francisco


2013/7/3 Gozdriov <gozd...@gmail.com>

Gozdriov

unread,
Jul 3, 2013, 11:15:51 PM7/3/13
to hypersp...@googlegroups.com
Hi Francisco,

I'll open a new thread.

Thanks
Reply all
Reply to author
Forward
0 new messages