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

Flatten Diffraction Vector Bugfix #1024

Merged
merged 20 commits into from
Mar 25, 2024
Merged

Conversation

CSSFrancis
Copy link
Member

@CSSFrancis CSSFrancis commented Feb 28, 2024


name: Flatten Diffraction Vector Bugfix
about: Fixes a bug when flattening diffraction vectors


Checklist

  • Updated CHANGELOG.md
  • Marked as finished

What does this PR do? Please describe and/or link to an open issue.
There was a bug for flattening diffraction vectors when the scales/number of axes was wrong. This causes problems with 5D datasets.

@coveralls
Copy link

coveralls commented Feb 28, 2024

Coverage Status

coverage: 93.473%. first build
when pulling 620b01c on CSSFrancis:flatten_dv_bugfix
into c024409 on pyxem:main.

Copy link
Member

@pc494 pc494 left a comment

Choose a reason for hiding this comment

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

Couple of small little changes I think would make this a bit more resilient.

Comment on lines +102 to +106
elif self._is_object_dtype:
self.ragged = True
elif self.ragged == True:
self.ragged = False
Copy link
Member

Choose a reason for hiding this comment

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

This looks weird to me. If the first elif clause is met then the second elif clause will also be met. If that's by design it's confusing, but I think it's more likely a bug.

Copy link
Member Author

Choose a reason for hiding this comment

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

Let me add some comments and see if I can't clean up the logic.

That is needed partially because upstream in hyperspy the ragged flag is a bit of a mess....

Sometimes you have data that isn't an object but hyperspy thinks that it is ragged in which case you want to say that it isn't ragged. Sometimes you have a signal with data=None in the process of initializing the signal in which case you just want to pass through without setting anything and sometimes you have an signal with a object datatype that isn't flagged as ragged....

pyxem/signals/diffraction_vectors.py Outdated Show resolved Hide resolved
Comment on lines 1205 to 1208
if self.ragged:
ragged = True
else:
ragged = False
Copy link
Member

Choose a reason for hiding this comment

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

What does this do?

Copy link
Member Author

Choose a reason for hiding this comment

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

Nothing actually 😅 Deleted.

pyxem/signals/diffraction_vectors2d.py Show resolved Hide resolved
pyxem/signals/diffraction_vectors2d.py Show resolved Hide resolved
@CSSFrancis
Copy link
Member Author

Couple of small little changes I think would make this a bit more resilient.

@pc494 Sounds good! I might have to think about how we could change things in hyperspy to make this work a bit better. Unfortunately, handling ragged things in hyperspy is still a bit of a "beta" feature mostly because dask and numpy have different behaviors with regard to slicing object arrays. (Dask will keep the object dtype and numpy will return the underlying array).

@pc494
Copy link
Member

pc494 commented Mar 7, 2024

Couple of small little changes I think would make this a bit more resilient.

@pc494 Sounds good! I might have to think about how we could change things in hyperspy to make this work a bit better. Unfortunately, handling ragged things in hyperspy is still a bit of a "beta" feature mostly because dask and numpy have different behaviors with regard to slicing object arrays. (Dask will keep the object dtype and numpy will return the underlying array).

If you are comfortable that the code currently works I think a few comments might be enough. I hope you can understand why I found reading some of it a bit strange, now I understand that it's due to some odd upstream behaviour I'm sympathetic to the need to 'fudge' things occasionally.

@pc494
Copy link
Member

pc494 commented Mar 13, 2024

I think this is still with @CSSFrancis but please tag me if that's not the case.

@CSSFrancis
Copy link
Member Author

@pc494 this is probably good to review again

@pc494
Copy link
Member

pc494 commented Mar 25, 2024

Perfect should be able to get to this today :)

Copy link
Member

@pc494 pc494 left a comment

Choose a reason for hiding this comment

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

LGTM

@pc494 pc494 merged commit ee17c2f into pyxem:main Mar 25, 2024
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants