Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add notebook showing how to make elemental maps using EELS #3

Merged
merged 18 commits into from
Apr 22, 2024

Conversation

magnunor
Copy link
Contributor

Originally from the pull request hyperspy/hyperspy-demos#39

This pull request makes it work with HyperSpy 2.0.0

Copy link

Binder 👈 Launch a binder notebook on branch magnunor/exspy-demos/add_elemental_mapping_eels

Copy link

Check out this pull request on  ReviewNB

See visual diffs & provide feedback on Jupyter Notebooks.


Powered by ReviewNB

EELS/EELS_elemental_mapping.ipynb Outdated Show resolved Hide resolved
EELS/EELS_elemental_mapping.ipynb Outdated Show resolved Hide resolved
EELS/EELS_elemental_mapping.ipynb Outdated Show resolved Hide resolved
EELS/EELS_elemental_mapping.ipynb Outdated Show resolved Hide resolved
EELS/EELS_elemental_mapping.ipynb Outdated Show resolved Hide resolved
EELS/EELS_elemental_mapping.ipynb Outdated Show resolved Hide resolved
"metadata": {},
"outputs": [],
"source": [
"import numpy as np\n",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this is notebook to show how to quantify elemental maps, wouldn't it be better to keep it focused on the analysis part and simply use the convenience function hs.plot.plot_images to display the maps and move the part on how to use matplotlib to make a figure of maps to a separate notebook?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added a section on how to show the results using m.components.Zn_L3.intensity.plot() and hs.plot.plot_images.

I think having the more advanced plotting, via matplotlib, is also useful. As people often want to create high quality figures from the data they've processed, and having it directly in the same notebook makes it easier to do this.

But it can of course be moved to a separate notebook, ideally in the same exspy-demos/EELS/ folder.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is important to split them in separate notebook:

  • the elemental mapping notebook will be more clear and more focused (less clutter due to the plotting code). One advantage of using hyperspy/exspy is remove a lot of the python code in workflows and the tutorial should reflect this.
  • The notebook on customising matplotlib figure will get more visibility on its own rather than included in EELS elemental mapping notebook. Also since this can be used for EDS maps in a very similar fashion, it should go in somewhere else than the EELS folder so that user interested in EDS can also find this notebook easily.
  • At the end of the day, users will copy and paste code to make their own notebook, so it doesn't need to be in the same notebook?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good points! I moved the matplotlib plotting part to its own notebook.

I created a new folder plotting_and_visualization, but not sure if that is the best name.

In addition, should the model.hspy file be added as well? For example in EELS/datasets/? This so people don't have to run through the whole EELS elemental map notebook before they can run the plotting notebook. It is 1.3 MB.

"metadata": {},
"outputs": [],
"source": [
"cb_zn = fig.colorbar(ax_zn.images[0], cax=cbar_zn, extend='both', orientation='horizontal', label=\"Relative Zn, [a.u.]\")\n",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are these arbitrary units?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess "non-calibrated" is the more correct term, as we don't know the beam current well enough to get quantitative information.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the elemental maps, the beam current is not necessary, because the cross section should be sensitivity factor, similarly to Cliff-Lorimer for EDS - there are similar to the Hartree Slater cross section in GMS.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmmmm, what would be a better term than Relative Zn, [a.u.]?

EELS/EELS_elemental_mapping.ipynb Outdated Show resolved Hide resolved
EELS/EELS_elemental_mapping.ipynb Outdated Show resolved Hide resolved
@magnunor
Copy link
Contributor Author

Many good points! I started fixing things, but still a couple things remaining.

@magnunor
Copy link
Contributor Author

I resolved all the comments (and tag them as resolved), except the two remaining ones which require some discussion.

@magnunor
Copy link
Contributor Author

magnunor commented Apr 1, 2024

Done! I moved the matplotlib plotting to its own notebook. Note that the files are currently lacking there, I was not sure if/where the model.hspy should be included.

@ericpre
Copy link
Member

ericpre commented Apr 1, 2024

I made a PR to simplify the notebooks: magnunor#1

@magnunor
Copy link
Contributor Author

I made a PR to simplify the notebooks: magnunor#1

Very nice! I merged those changes. I wasn't sure if in .gitignore, it should be *.virtual_documents (from your PR), or .virtual_documents in the current main branch. So I went with *.virtual_documents, as this was in the most recent commit.


I also added a cell showing how to use ``hs.plot.plot_roi_map`, as (I feel) this feature is very useful for this type of data.

"cell_type": "markdown",
"metadata": {},
"source": [
"Before running the full fitting routine, we do a quick, interactive, exploration of the data using `hs.plot.plot_roi_map`. Move and resize the red and blue spans by click-and-dragging with your mouse. The red span should be from about 930 to 1005 eV, and the green from 1045 to 1145 eV."
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a note to mention these maps contain the background and that their interpretation needs to take that into account?
If you show these maps here it would be good to discuss the comparison with/without background subtraction. Just on its own and in its current form, it is not clear what does it shows and what the purpose of this step in this notebook.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done! I added both the visualization without the background removal, and with the background removal.

Especially the latter shows really nice why we have to use more advanced data processing to separate the intensity of Cu from the Zn. Ergo, why we have to use the model based approach.

EELS/EELS_elemental_mapping.ipynb Outdated Show resolved Hide resolved
@magnunor
Copy link
Contributor Author

Maybe adding the hs.plot.plot_roi_maps actually makes the Notebook unnecessarily cluttered? Since we'll have to add a lot of extra explanations. And that it could rather be highlighted in exspy/examples

@ericpre
Copy link
Member

ericpre commented Apr 18, 2024

I don't think that it makes cluttered but it does feel a bit out of place - it is not clear why you would this step here and what is its outcome.
There is pedagogical values in explaining and illustrating the effect of the background or edge overlap and it would fit well in this notebook since this is a good example of where fitting works well and the other method (substract background followed by edge intensity integration) doesn't work.

@magnunor
Copy link
Contributor Author

I kept the part with hs.plot.plot_roi_maps, and expanded it a bit to make it flow nicely into the next part about the model based approach.

@ericpre ericpre merged commit 8eeb948 into hyperspy:main Apr 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants