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
Refactor the rsr-reader and add more test coverage #124
Conversation
Signed-off-by: Adam.Dybbroe <a000680@c21856.ad.smhi.se>
# Conflicts: # pyspectral/rsr_reader.py
Signed-off-by: Adam.Dybbroe <a000680@c21856.ad.smhi.se>
Signed-off-by: Adam.Dybbroe <a000680@c21856.ad.smhi.se>
Signed-off-by: Adam.Dybbroe <a000680@c21856.ad.smhi.se>
pyspectral/tests/test_rsr_reader.py
Outdated
check_instrument.return_value = None | ||
|
||
with pytest.raises(AttributeError) as exec_info: | ||
dummy = RelativeSpectralResponse('MyPlatform') |
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.
F841 local variable 'dummy' is assigned to but never used
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.
Replacing dummy
with _
will make Stickler happy.
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.
This is still an issue. If you don't use it, assign to _
or don't assign it at all.
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.
LGTM, I just would like to see one function refactored :)
pyspectral/rsr_reader.py
Outdated
def get_relative_spectral_responses(self, h5f): | ||
"""Read the rsr data and add to the object.""" | ||
no_detectors_message = False | ||
for bandname in self.band_names: | ||
self.rsr[bandname] = {} | ||
try: | ||
num_of_det = h5f[bandname].attrs['number_of_detectors'] | ||
except KeyError: | ||
if not no_detectors_message: | ||
LOG.debug("No detectors found - assume only one...") | ||
num_of_det = 1 | ||
no_detectors_message = True | ||
|
||
for i in range(1, num_of_det + 1): | ||
dname = 'det-{0:d}'.format(i) | ||
self.rsr[bandname][dname] = {} | ||
try: | ||
resp = h5f[bandname][dname]['response'][:] | ||
except KeyError: | ||
resp = h5f[bandname]['response'][:] | ||
|
||
self.rsr[bandname][dname]['response'] = resp | ||
|
||
try: | ||
wvl = (h5f[bandname][dname]['wavelength'][:] * | ||
h5f[bandname][dname][ | ||
'wavelength'].attrs['scale']) | ||
except KeyError: | ||
wvl = (h5f[bandname]['wavelength'][:] * | ||
h5f[bandname]['wavelength'].attrs['scale']) | ||
|
||
# The wavelength is given in micro meters! | ||
self.rsr[bandname][dname]['wavelength'] = wvl * 1e6 | ||
|
||
try: | ||
central_wvl = h5f[bandname][ | ||
dname].attrs['central_wavelength'] | ||
except KeyError: | ||
central_wvl = h5f[bandname].attrs['central_wavelength'] | ||
|
||
self.rsr[bandname][dname][ | ||
'central_wavelength'] = central_wvl | ||
|
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.
This function should be refactored, it is too long and cryptic
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.
I agree! I will do!
Signed-off-by: Adam.Dybbroe <a000680@c21856.ad.smhi.se>
Congratulations 🎉. DeepCode analyzed your code in 2.677 seconds and we found no issues. Enjoy a moment of no bugs ☀️. 👉 View analysis in DeepCode’s Dashboard | Configure the bot |
Signed-off-by: Adam.Dybbroe <a000680@c21856.ad.smhi.se>
Signed-off-by: Adam.Dybbroe <a000680@c21856.ad.smhi.se>
Signed-off-by: Adam.Dybbroe <a000680@c21856.ad.smhi.se>
Ok to merge @pnuu ? |
pyspectral/tests/test_rsr_reader.py
Outdated
|
||
test_rsr.rsr['M1'] = {'det-1': {}} | ||
test_rsr.set_band_central_wavelength_per_detector(h5f, 'M1', 'det-1') | ||
self.assertTrue('central_wavelength' in test_rsr.rsr['M1']['det-1']) |
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.
You could use assertIn
here to make deepcode happier: https://docs.python.org/2/library/unittest.html#unittest.TestCase.assertIn
Right?
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.
Oh, yes, right! thx!
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.
Just couple of comments. Feel free to merge.
pyspectral/tests/test_rsr_reader.py
Outdated
check_instrument.return_value = None | ||
|
||
with pytest.raises(AttributeError) as exec_info: | ||
dummy = RelativeSpectralResponse('MyPlatform') |
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.
Replacing dummy
with _
will make Stickler happy.
import unittest | ||
import numpy as np | ||
|
||
from pyspectral import utils | ||
from pyspectral.utils import np2str, bytes2string |
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.
I think the functions that are tested should be imported inside the test function/method. That way they can be mocked in other tests, if it becomes necessary.
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.
Okay, I thought the mocking was independent of the imports actually!?
I always have all imports at the top.
Signed-off-by: Adam.Dybbroe <a000680@c21856.ad.smhi.se>
Signed-off-by: Adam.Dybbroe <a000680@c21856.ad.smhi.se>
Signed-off-by: Adam.Dybbroe a000680@c21856.ad.smhi.se
pytest pyspectral
flake8 pyspectral