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 reader for Jobin-yvon .xml-format #25

Merged
merged 12 commits into from
Sep 29, 2022
Merged

Conversation

pietsjoh
Copy link
Contributor

@pietsjoh pietsjoh commented Aug 23, 2022

Description of the change

Add support for reading the .xml-format from jobin-yvon.

Progress of the PR

  • basic load functionality (data, axes, original_metadata, metadata) + corresponding tests
  • load signal data
    • check order of map (which direction is X and which is Y)
  • implement different signal axis formats (with corresponding units)
    • wavelength (nm)
    • wavenumber (1/cm)
    • abs. wavenumber (1/cm)
    • energy (eV)
    • different names for abs. and rel. wavenumber?
  • metadata mapping
    • remove spaces in nodes
    • add more entrys from original_metadata
    • rotation angle
    • glued spectrum
  • update docstring (if appropriate),
  • update user guide (if appropriate),
  • add an changelog entry in the upcoming_changes folder (see upcoming_changes/README.rst),
  • Check formatting changelog entry in the readthedocs doc build of this PR (link in github checks)
  • add tests (currently dependant on hyperspy.load())
  • ready for review.

Minimal example of the bug fix or the new feature

from rsciio.jobin_yvon import api
api.file_reader("test.xml")

@pietsjoh pietsjoh changed the title Jobin yvon Add Reader for Jobin-yvon .xml-format Aug 23, 2022
@pietsjoh pietsjoh changed the title Add Reader for Jobin-yvon .xml-format Add reader for Jobin-yvon .xml-format Aug 23, 2022
@codecov
Copy link

codecov bot commented Aug 23, 2022

Codecov Report

Base: 82.87% // Head: 83.37% // Increases project coverage by +0.50% 🎉

Coverage data is based on head (f1194fc) compared to base (e852a08).
Patch coverage: 96.48% of modified lines in pull request are covered.

Additional details and impacted files
@@            Coverage Diff             @@
##             main      #25      +/-   ##
==========================================
+ Coverage   82.87%   83.37%   +0.50%     
==========================================
  Files          40       40              
  Lines        8041     8337     +296     
  Branches     1860     1930      +70     
==========================================
+ Hits         6664     6951     +287     
+ Misses        913      911       -2     
- Partials      464      475      +11     
Impacted Files Coverage Δ
rsciio/jobin_yvon/api.py 96.48% <96.48%> (ø)
rsciio/__init__.py
rsciio/bruker/api.py 88.25% <0.00%> (+0.15%) ⬆️
rsciio/dens/api.py 83.33% <0.00%> (+1.85%) ⬆️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

docs/supported_formats/jobin_yvon.rst Outdated Show resolved Hide resolved
docs/supported_formats/jobin_yvon.rst Outdated Show resolved Hide resolved
docs/supported_formats/jobin_yvon.rst Outdated Show resolved Hide resolved
docs/supported_formats/jobin_yvon.rst Outdated Show resolved Hide resolved
rsciio/jobin_yvon/api.py Outdated Show resolved Hide resolved
rsciio/jobin_yvon/api.py Outdated Show resolved Hide resolved
rsciio/jobin_yvon/api.py Outdated Show resolved Hide resolved
rsciio/jobin_yvon/api.py Outdated Show resolved Hide resolved
rsciio/jobin_yvon/specifications.yaml Outdated Show resolved Hide resolved
rsciio/jobin_yvon/specifications.yaml Outdated Show resolved Hide resolved
rsciio/jobin_yvon/specifications.yaml Outdated Show resolved Hide resolved
rsciio/jobin_yvon/specifications.yaml Outdated Show resolved Hide resolved
rsciio/jobin_yvon/api.py Outdated Show resolved Hide resolved
rsciio/jobin_yvon/api.py Outdated Show resolved Hide resolved
rsciio/jobin_yvon/specifications.yaml Outdated Show resolved Hide resolved
upcoming_changes/25.new.rst Outdated Show resolved Hide resolved
rsciio/jobin_yvon/api.py Outdated Show resolved Hide resolved
rsciio/jobin_yvon/api.py Outdated Show resolved Hide resolved
rsciio/jobin_yvon/api.py Outdated Show resolved Hide resolved
@jlaehne
Copy link
Contributor

jlaehne commented Sep 18, 2022

@LMSC-NTappy as you have implemented the .sur reader not so long ago, may you have a look at this PR?

name: Str
Name of the axis.
"""
scale = np.abs(array[0] - array[-1]) / (array.size - 1)
Copy link
Contributor

Choose a reason for hiding this comment

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

I like the approach of loading as uniform axis and warn the user of possible non-uniformity.

However, I would use a regression method such as numpy.polyfit in order to minimize the linearized axis error:
[scale, offset] = np.polyfit(np.arange(array.size),array,1)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

An advantage of the method I used is that the boundaries match exactly.
Moreover, the offset obtained from the fit is wrong when the axis contains negative values.
For example there is a test file with navigation axis (-2, 0, 2).

I personally wouldn't use the fit for the offset calculation, but I could imagine using a fit for the scale.

Copy link
Contributor

Choose a reason for hiding this comment

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

Indeed, the only additional degree of freedom of the fit should be that the first and last point are not fixed. So if we want to keep their positions, there is no advantage of the fit.

Copy link
Contributor

Choose a reason for hiding this comment

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

An advantage of the method I used is that the boundaries match exactly.

Indeed, the only additional degree of freedom of the fit should be that the first and last point are not fixed. So if we want to keep their positions, there is no advantage of the fit.

I don't see any virtue in ensuring that first/last points match exactly but if that's a concern to you I guess you have good reasons.

Moreover, the offset obtained from the fit is wrong when the axis contains negative values.
For example there is a test file with navigation axis (-2, 0, 2).

Sounds odd to me. Running this gives

np.polyfit(x=np.arange(3),y=[-2,0,2],deg=1)
#out: array([ 2., -2.])

Which is exactly a scale of 2 and an offset of -2

I personally wouldn't use the fit for the offset calculation, but I could imagine using a fit for the scale.

Definitely this would induce more error than what is currently implemented (at lease in some cases)

You do as you please :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Which is exactly a scale of 2 and an offset of -2

I made a mistake here. Yes it should also work in this case.

I use a fit now to get the scale/offset of the signal axis.

Copy link
Contributor

@LMSC-NTappy LMSC-NTappy left a comment

Choose a reason for hiding this comment

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

Overall looks good to me.

I have some troubles with the way the non uniform axes are linearized, which can lead to errors in some cases.

Other than that, I suggested a few changes that in my opinion improve readability

Copy link
Contributor

@LMSC-NTappy LMSC-NTappy left a comment

Choose a reason for hiding this comment

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

Looks good to me.

Linearisation strategy is still a subject of disagreement but if by default the signal is loaded as nua I guess it is the user's responsibility to linearize in the way it pleases him/her (and decide how the linearization error is dealt with).

Cheers

Nico

Copy link
Contributor

@LMSC-NTappy LMSC-NTappy left a comment

Choose a reason for hiding this comment

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

Looks good to me this way!

Copy link
Contributor

@LMSC-NTappy LMSC-NTappy left a comment

Choose a reason for hiding this comment

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

Looks good to me!

IMHO there is nothing preventing this to be merged.

@jlaehne jlaehne merged commit d4ef3ce into hyperspy:main Sep 29, 2022
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.

3 participants