Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • Dec 11 21:36
    tjof2 edited #2035
  • Dec 11 13:55
    pquinn-dls commented #2204
  • Dec 09 21:08
    jlaehne commented #1927
  • Dec 09 19:36
    ericpre milestoned #2288
  • Dec 09 19:36
    ericpre unlabeled #2288
  • Dec 09 19:36

    ericpre on RELEASE_next_minor

    Add __getitem__ method to ROIs Add documentation Add tests and 12 more (compare)

  • Dec 09 19:36
    ericpre closed #2288
  • Dec 09 14:49
    francisco-dlp synchronize #2288
  • Dec 09 14:35
    francisco-dlp edited #2288
  • Dec 09 13:28

    francisco-dlp on RELEASE_next_patch

    Remove erroneous line in docs Merge pull request #2291 from t… (compare)

  • Dec 09 13:28
    francisco-dlp closed #2291
  • Dec 09 13:27
    francisco-dlp labeled #2291
  • Dec 09 13:27
    francisco-dlp labeled #2291
  • Dec 09 13:04
    thomasaarholt opened #2291
  • Dec 09 13:00
    francisco-dlp commented #2290
  • Dec 09 12:36
    thomasaarholt opened #2290
  • Dec 09 11:15
    francisco-dlp commented #2288
  • Dec 09 11:10
    francisco-dlp synchronize #2288
  • Dec 08 12:16
    pquinn-dls synchronize #2203
  • Dec 07 08:28
    francisco-dlp unlabeled #2288
SteC4
@SteC4

TO export NMF decomposition factors I’m using
import csv
csvwriter = csv.writer(open("NMF_factors.csv","wb") )
for row in (0,1) :
csvwriter.writerow(NMF_factors.inav[row].data)

and I got the error
TypeError: a bytes-like object is required, not 'str'

Any suggestion ? Thanks

Thomas Aarholt
@thomasaarholt
Hi @SteC4. The reason you're getting that error there is that the .data object that you're trying to write to a text file (csv) is not a string. s.data is a numpy array. You could probably fix this by using writerow(str(NMF_factors.inav[row].data) instead. However, you're probably better off saving each of those nav positions as msa files.
for i, single_spectrum in enumerate(NMF_factors):
    single_spectrum.save('pos{}.msa'.format(i))
MSA is a comma/new-line separated format that includes the necessary energy calibration as a header.
Thomas Aarholt
@thomasaarholt
Oh, and in case anyone is interested in practicing their coding skills, the advent of code xmas calendar is happening again this year. Can highly recommend: https://adventofcode.com/
Katherine E. MacArthur
@k8macarthur
Does anyone know if there's a way to get the image alignment function Align2D to work without assuming a constant drift direction? In my data I have steps in the other direction from manual correction at the microscope...
Thomas Aarholt
@thomasaarholt
Wait, does
Does align2d only work if the drift is in one direction? That doesn't sound right.
Katherine E. MacArthur
@k8macarthur
So with align2d you can specify at set of shifts, or if you don't it uses estimate_shift. Estimate_shift seems to assume only one drift direction...
Francisco de la Peña
@francisco-dlp
No, it doesn't assume any drift direction.
Thomas Aarholt
@thomasaarholt
I used on 3d sims data some years back and can confirm what Francisco is saying.
Katherine E. MacArthur
@k8macarthur

'Notes

The statistical analysis approach to the translation estimation when using reference=’stat’ roughly follows [1]_ . If you use it please cite their article.'

It looks like it does but only when you use a static reference. If you use 'cascade' as the reference maybe then it doesn't.
Either way i think my in-situ data shifts too much in one place to cope with normal cross-correlation which is why the align2D might be failing.
Francisco de la Peña
@francisco-dlp
That's probably the case. You could try to align first manually those big jumps and let the algorithms do the fine job in a second step.
doraiiyer
@doraiiyer
This is my first post here since joining afterI am still learning to use hyperspy. Plot() has the option of allowing the use of element lines, however if use multiple spectra and want to show the lines plot_spectra() does not have the option. How does get around that for multiple spectra?
Thomas Aarholt
@thomasaarholt
I'm not sure the
Ugh, I really hate gitter on mobile. I changed tab to look up the code, and then it just sends whatever I've already written. Sorry about that.
The plot_spectra function unfortunately doesn't support eds lines directly. You may be able to plot a single eds spectrum and then use the ax argument in plot_spectra to plot more spectra on the same plot. I'll give this a shot.
Thomas Aarholt
@thomasaarholt
Try this and see what you think
import hyperspy.api as hs

# make some dummy data
s = hs.datasets.example_signals.EDS_SEM_Spectrum()
s2 = s.deepcopy()
s2.data *= 2
my_spectra = [s, s2]

def plot_eds_spectra(spectra):
    'plot single spectrum, then add more spectra to first plot using `plot_spectra`'
    s0 = spectra[0]
    s.plot(True)

    ax = s._plot.signal_plot.ax
    hs.plot.plot_spectra(spectra[1:], ax=ax)

plot_eds_spectra([s, s2])
image.png
Andrew Herzing
@aaherzing_gitlab
When performing a model fit to an EDS spectrum, is it possible to constrain the background to be positive at all energy channels?
hui-cc
@hui-cc
Yes, it is, background is just a component and its amplitude can be bounded to be positive
Andrew Herzing
@aaherzing_gitlab
Thanks. How is this done for the 6th order polynomial backgroun component of the EDS model?
Thomas Aarholt
@thomasaarholt
@hui-cc, no, I don't think this can be done. You can bound the individual parameters (a0, a1 etc) to be positive, but it doesn't have an amplitude. And even if one creates such a component as an expression, the problem is that a only-positive polynomial will only go up.
Andrew Herzing
@aaherzing_gitlab
That was my understanding as well. I guess I will work on applying bounds to some of the other components to see if that has a secondary effect on the background fit.
Zanetta Pierre-marie
@ZanettaPM
If I'm correct you cannot apply different bounds to the polynomial coefficients since they are all contained in "coefficients" term
I was trying to do that before too
doraiiyer
@doraiiyer
Thomas -the function for multiple spectra with lines works well. Thank you. I did notice a quality difference between the lines from plot() and plot_spectra(). the plot() produces a stepped line while plot_spectra() is smooth. I ran the routine using spyder and ipython. two figures were produced, one was blank and the other had all the plots. this might be because we are overlapping over a previous plot and plot_spectra produces a canvas.
Thomas Aarholt
@thomasaarholt
@ZanettaPM you can do it on the new Polynomial function that eric and I added.
>>> poly = hs.model.components1D.Polynomial(5, legacy=False)
>>> poly.parameters
(<Parameter a0 of 5th order Polynomial component>,
 <Parameter a1 of 5th order Polynomial component>,
 <Parameter a2 of 5th order Polynomial component>,
 <Parameter a3 of 5th order Polynomial component>,
 <Parameter a4 of 5th order Polynomial component>,
 <Parameter a5 of 5th order Polynomial component>)
Thomas Aarholt
@thomasaarholt
@doraiiyer Ah, I didn't think about the first point you mention - I didn't notice it since my example had many channels.
I've created an updated version for you that sets the style of the first plot to the "default" one, which is what happens for the plot_spectraones. I've also added a return fig.
import hyperspy.api as hs

# make some dummy data
s = hs.datasets.example_signals.EDS_SEM_Spectrum()
s2 = s.deepcopy()
s2.data *= 2
my_spectra = [s, s2]
def plot_eds_spectra(spectra):
    s0 = spectra[0]
    s.plot(True)
    fig = s._plot.signal_plot.figure
    ax = s._plot.signal_plot.ax
    firstline = ax.lines[0]

    hs.plot.plot_spectra(spectra[1:], ax=ax)

    firstline.set_drawstyle('default')    
    return fig

fig = plot_eds_spectra([s, s2])
If you zoom in on the plot, you can see that it now has the same "smooth" line
Thomas Aarholt
@thomasaarholt
Unfortunately I've not been able to remove the empty figure that appears.
Zanetta Pierre-marie
@ZanettaPM
@thomasaarholt Great ! I'll take a look at this
doraiiyer
@doraiiyer
@thomasaarholt That worked well. Thank you.
MurilooMoreira
@MurilooMoreira

Hello guys, I am using this function to open my data: hs.load("sample.emd", sum_frames=False, load_SI_image_stack=True, SI_dtype=np.int8, rebin_energy=4)
[<Signal2D, title: HAADF, dimensions: (50|179, 161)>,

<EDSSEMSpectrum, title: EDS, dimensions: (50, 179, 161|1024)>]

I am trying to see each individual frame of my data, I am able to do that with the SI, but when I try with the HAADF image, I can only see the last frame or the sum over all frames.
Does someone have the solution for that? Thank you.
Actually I want to save each dark field image apart, this is why I need to access these frames.
MurilooMoreira
@MurilooMoreira
Sorry guys, I solved the problem. Thank you.
Katherine E. MacArthur
@k8macarthur
@MurilooMoreira how did you solve it, because I also struggled with this before?
MANUEL PIÑON
@ManuelSmguad_twitter
hola, alguien puede ayudarme a resolver la instalación python e hyperspy
no tengo ni idea como comenzar hacerlo
Alexander Skorikov
@askorikov
@k8macarthur You can use load_SI_image_stack=True parameter for HAADF signal in particular or sum_frames=False to load all saved time series in general (might be extremely memory hungry though). See Extra loading arguments section for EMD format.
MurilooMoreira
@MurilooMoreira
@k8macarthur Hi, when you open your data as @askorikov said, you can use call "your_data".data[index], where the argument of the .data[] will be your HAADF images. So, you can access your stacked images changing the index.
Just be careful with memory, to avoid problems with that you can explore the option of rebin your data while it's opened.