Fix: Handle Missing Extinction Coefficient Data by Defaulting to Zero#77
Conversation
|
I think it failed these tests because it did not raise the exception error (that I removed). Suggestions? |
|
Hi Manuel, Thanks for opening this! Yes, the failure is expected, so no problem. Those tests should either be removed or updated to catch the warning output. The latter is not trivial, though I do it elsewhere in the tests, I believe. I used a similar method in Simple example: import warnings
warnings.simplefilter("once", UserWarning)One other nice thing about using What do you think? Regards, |
HarrisonKramer
left a comment
There was a problem hiding this comment.
Looks good. This approach works well for now.
Can you delete the failing tests and make the minor change I suggested?
Then we can merge 👍
Kramer
|
Hi Kramer, Thank you for the feedback! I agree, we can use Thank you! Manuel |
Codecov ReportAttention: Patch coverage is
@@ Coverage Diff @@
## master #77 +/- ##
==========================================
- Coverage 96.57% 96.56% -0.02%
==========================================
Files 105 105
Lines 6340 6345 +5
==========================================
+ Hits 6123 6127 +4
- Misses 217 218 +1
|
|
Thanks a lot for the contribution, @manuelFragata! and thanks for volunteering to work on warnings in the material module. PR looks good. Merging now! Regards, |
Description
This PR addresses the issue where the
MaterialFile.k()function raises aValueError when no extinction coefficient data is found in the material file (e.g., with Malitson.yml - this came up when I was using the "fused_silica" material, for example).Proposed Fix
k()Method inmaterial_file.py:The method now checks whether
self._korself._k_wavelengthisNone. If one of them is missing, the function will set a default extinction coefficient of zero.A print statement has been added to notify the user, because it may be important for some of their analyses:
wavelengthis a scalar, the method returns0.0.wavelengthis a NumPy array, it returns an array of zeros matching the shape of the input.If the extinction data is present, the method uses
np.interpto interpolate the extinction coefficient for the given wavelengths, as the already implemented approach.Testing
Here is the warning being triggered, but it allows the script to continue running:
Additional Modifications
I would also need some suggestions on how to show this warning message only once. Right now it will show up multiple times, as many as the method k() is called.
Any ideas on how I can improve this?
Thanks :)
Manuel