-
Notifications
You must be signed in to change notification settings - Fork 18
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
Conversation
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)) |
There was a problem hiding this comment.
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!
There was a problem hiding this comment.
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
.
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added deprecation warning.
Codecov Report
@@ 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
Continue to review full report at Codecov.
|
integration_time = kwargs["exposure"] | ||
raise DeprecationWarning( | ||
"The `exposure` argument will be " | ||
"removed in LumiSpy 1.0, use `integration_time` instead." |
There was a problem hiding this comment.
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
?
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)) |
There was a problem hiding this comment.
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.
b09aa33
to
9b7e816
Compare
There was a problem hiding this 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.
Description of the change
scale_by_exposure
according to Metadata structure #109Progress of the PR
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.