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

Update metadata used in scale_by_exposure #116

Merged
merged 9 commits into from
Apr 27, 2022

Conversation

jlaehne
Copy link
Contributor

@jlaehne jlaehne commented Mar 22, 2022

Description of the change

  • update scale_by_exposure according to Metadata structure #109
  • some tests can only run with Hyperspy v1.7 (they work locally with the development branch)
  • added extra comments in contributors guide

Progress of the PR

  • Change implemented (can be split into several points),
  • docstring updated (if appropriate),
  • added tests (partly still commented out),
  • activate remaining tests once HyperSpy v1.7 is out,
  • added line to CHANGELOG.md,
  • ready for review.

Note

Tests run locally, should work once HyperSpy v1.7 is released. Merge will need to wait for the release, but can be reviewed already for a speedy release of LumiSpy v0.2 after the HyperSpy release.

@jlaehne jlaehne added this to the v0.2.0 milestone Mar 22, 2022
@jlaehne jlaehne added the status: WIP work in progress label Apr 9, 2022
@jlaehne jlaehne added status: needs review and removed status: WIP work in progress labels Apr 21, 2022
@jlaehne jlaehne mentioned this pull request Apr 21, 2022
Comment on lines 122 to 138
if self.metadata.has_item(
"Acquisition_instrument.Detector.integration_time"
):
exposure = float(
self.metadata.get_item("Acquisition_instrument.CL.exposure")
self.metadata.get_item(
"Acquisition_instrument.Detector.integration_time"
)
)
elif self.metadata.has_item("Acquisition_instrument.CL.dwell_time"):
# following will work only from hyperspy v1.7
elif self.metadata.has_item("integration_time", full_path=False):
exposure = float(
self.metadata.get_item("Acquisition_instrument.CL.dwell_time")
self.metadata.get_item("integration_time", full_path=False)
)
elif self.metadata.has_item("exposure", full_path=False):
exposure = float(self.metadata.get_item("exposure", full_path=False))
elif self.metadata.has_item("dwell_time", full_path=False):
exposure = float(self.metadata.get_item("dwell_time", full_path=False))
Copy link
Contributor

@ericpre ericpre Apr 23, 2022

Choose a reason for hiding this comment

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

Would it more simple and readable to do something along the line of (assuming the default value of exposure is None, which is more standard than float('nan')):

if exposure is None:
   # exposure is not provided, try to get it from metadata
    exposure = self.metadata.get_item("Acquisition_instrument.Detector.integration_time")
if exposure is None:
    # integration_time is not in the metadata, raise an error
    raise ValueError("Provide `exposure` argument or set `integration_time` in the metadata.")

Why should other cases (integration time saved elsewhere in the metadata) be supported? The point of defining a metadata specification is avoid this kind of thing!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Why should other cases (integration time saved elsewhere in the metadata) be supported? The point of defining a metadata specification is avoid this kind of thing!

Because, even though we have a metadata convention, not all readers parse the metadata yet. But in fact, we should then search the original_metadata and not the metadata.

Copy link
Contributor

Choose a reason for hiding this comment

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

The readers need to be fixed, then! :)
The motivation for the metadata specification is for user and hyperspy functionalities to know where to find relevant information and avoid using heuristic to find it which in my opinion is a bad practice and it needs to be avoided. I don't think, that this is explained in the hyperspy user guide, which would be good to do.

Considering that lumispy doesn't have a stable API at the moment, I would not worry too much about rough edges like this, where the expose needs to be passed explicitly and favour the use of good practice.

Exposure time in s. If not given, the function tries to find
'exposure' or 'dwell_time' in the metadata (for the moment only at
Gatan specific nodes).
Exposure time in s. If not given, the function tries to use the
Copy link
Contributor

Choose a reason for hiding this comment

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

Rename the exposure argument to integration_time so that it is consistent with the metadata specification?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, it would make sense, but I would not want to rename the function not to break the API and would probably allow exposure as backwards compatible Alias.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added deprecation warning.

@codecov-commenter
Copy link

codecov-commenter commented Apr 24, 2022

Codecov Report

Merging #116 (b09aa33) into main (2258151) will increase coverage by 0.98%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##             main     #116      +/-   ##
==========================================
+ Coverage   95.76%   96.75%   +0.98%     
==========================================
  Files          11       11              
  Lines         591      586       -5     
==========================================
+ Hits          566      567       +1     
+ Misses         25       19       -6     
Impacted Files Coverage Δ
lumispy/signals/common_luminescence.py 100.00% <100.00%> (ø)
lumispy/utils/axes.py 98.08% <0.00%> (+1.19%) ⬆️
lumispy/signals/luminescence_spectrum.py 91.75% <0.00%> (+1.33%) ⬆️
lumispy/signals/cl_spectrum.py 98.46% <0.00%> (+1.44%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 2258151...b09aa33. Read the comment docs.

lumispy/signals/common_luminescence.py Outdated Show resolved Hide resolved
integration_time = kwargs["exposure"]
raise DeprecationWarning(
"The `exposure` argument will be "
"removed in LumiSpy 1.0, use `integration_time` instead."
Copy link
Contributor

Choose a reason for hiding this comment

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

Same as above: better to use rename?

Comment on lines 122 to 138
if self.metadata.has_item(
"Acquisition_instrument.Detector.integration_time"
):
exposure = float(
self.metadata.get_item("Acquisition_instrument.CL.exposure")
self.metadata.get_item(
"Acquisition_instrument.Detector.integration_time"
)
)
elif self.metadata.has_item("Acquisition_instrument.CL.dwell_time"):
# following will work only from hyperspy v1.7
elif self.metadata.has_item("integration_time", full_path=False):
exposure = float(
self.metadata.get_item("Acquisition_instrument.CL.dwell_time")
self.metadata.get_item("integration_time", full_path=False)
)
elif self.metadata.has_item("exposure", full_path=False):
exposure = float(self.metadata.get_item("exposure", full_path=False))
elif self.metadata.has_item("dwell_time", full_path=False):
exposure = float(self.metadata.get_item("dwell_time", full_path=False))
Copy link
Contributor

Choose a reason for hiding this comment

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

The readers need to be fixed, then! :)
The motivation for the metadata specification is for user and hyperspy functionalities to know where to find relevant information and avoid using heuristic to find it which in my opinion is a bad practice and it needs to be avoided. I don't think, that this is explained in the hyperspy user guide, which would be good to do.

Considering that lumispy doesn't have a stable API at the moment, I would not worry too much about rough edges like this, where the expose needs to be passed explicitly and favour the use of good practice.

Copy link
Contributor

@ericpre ericpre 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, I suggested a clearer wording onthe deprecation to avoid confusing about when the deprecation starts and ends and when the exposure will stop working.

lumispy/signals/common_luminescence.py Outdated Show resolved Hide resolved
lumispy/signals/common_luminescence.py Outdated Show resolved Hide resolved
@jlaehne jlaehne merged commit 2ea75a0 into LumiSpy:main Apr 27, 2022
@jlaehne jlaehne deleted the scale-exposure-update branch April 27, 2022 23:03
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