pyxem / orix

Analysing crystal orientations and symmetry in Python
https://orix.readthedocs.io
GNU General Public License v3.0
78 stars 45 forks source link

add to_dict method to crystal_map to allow for easy extraction of tho… #457

Open SteffenBrinckmann opened 10 months ago

SteffenBrinckmann commented 10 months ago

add to_dict method to crystal_map to allow for easy extraction of those results that would be printed with repr

Description of the change

Progress of the PR

Minimal example of the bug fix or new feature

>>> from orix.io import load
>>> datadir = 'data/04/'
>>> fname = 'sdss_ferrite_austenite.ang' #.ang file produced by EMsoft
>>> cm = load(datadir + fname)
>>> metadata = cm.to_dict()

For reviewers

hakonanes commented 10 months ago

Thank you for this suggestion, @SteffenBrinckmann.

A public method to extract all contents of a crystal map is a good idea. We already use such a private function in the orix HDF5 writer:

https://github.com/pyxem/orix/blob/2e6f783e07c750f09553bec6fc51f5dfa9abae96/orix/io/plugins/orix_hdf5.py#L248-L298

This function returns all contents of a crystal map, including the rotations. It doesn't calculate the phase fractions for you, though. Can you explain what you need this information for, specifically?

I think making the mentioned private function a public crystal map method is the best solution. If you really need the phase fractions as well, we can add this to the dictionary if a boolean keyword is true, for example. What do you think?

SteffenBrinckmann commented 9 months ago

hey @hakonanes

best, Steffen

CSSFrancis commented 3 months ago

I think that @SteffenBrinckmann has a good idea. If the function is private it would be good to add this function to the CrystalMap object. Something like a function _to_dictionary would allow it to be saved by hyperspy signals as well which would be useful.

https://github.com/hyperspy/hyperspy/blob/3b350ff80b68b0928b284e76d3dc0a2b31e6dbf5/hyperspy/misc/utils.py#L524C37-L524C48

@hakonanes @pc494 Thoughts?

hakonanes commented 1 month ago

Haven't forgotten about this, but don't have time at the moment. A more thorough discussion about serialization (into dicts, I presume) would be good.