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

Refactor the rsr-reader and add more test coverage #124

Merged
merged 12 commits into from Nov 13, 2020

Conversation

adybbroe
Copy link
Collaborator

@adybbroe adybbroe commented Nov 12, 2020

Signed-off-by: Adam.Dybbroe a000680@c21856.ad.smhi.se

Signed-off-by: Adam.Dybbroe <a000680@c21856.ad.smhi.se>
@adybbroe adybbroe self-assigned this Nov 12, 2020
pyspectral/tests/test_rsr_reader.py Outdated Show resolved Hide resolved
pyspectral/tests/test_rsr_reader.py Outdated Show resolved Hide resolved
pyspectral/tests/test_rsr_reader.py Outdated Show resolved Hide resolved
Adam.Dybbroe added 2 commits November 12, 2020 08:53
# Conflicts:
#	pyspectral/rsr_reader.py
Signed-off-by: Adam.Dybbroe <a000680@c21856.ad.smhi.se>
pyspectral/rsr_reader.py Outdated Show resolved Hide resolved
pyspectral/rsr_reader.py Outdated Show resolved Hide resolved
@coveralls
Copy link

coveralls commented Nov 12, 2020

Coverage Status

Coverage increased (+3.4%) to 76.302% when pulling fafcfc2 on adybbroe:fix4-h5py-3.1 into 18f3472 on pytroll:master.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.7%) to 73.587% when pulling e7f9544 on adybbroe:fix4-h5py-3.1 into 18f3472 on pytroll:master.

Signed-off-by: Adam.Dybbroe <a000680@c21856.ad.smhi.se>
@adybbroe adybbroe marked this pull request as ready for review November 12, 2020 09:37
Signed-off-by: Adam.Dybbroe <a000680@c21856.ad.smhi.se>
check_instrument.return_value = None

with pytest.raises(AttributeError) as exec_info:
dummy = RelativeSpectralResponse('MyPlatform')
Copy link
Contributor

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

Copy link
Member

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.

Copy link
Member

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.

Copy link
Member

@mraspaud mraspaud left a 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 :)

Comment on lines 257 to 299
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

Copy link
Member

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

Copy link
Collaborator Author

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>
@ghost
Copy link

ghost commented Nov 12, 2020

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

Adam.Dybbroe added 2 commits November 12, 2020 17:33
Signed-off-by: Adam.Dybbroe <a000680@c21856.ad.smhi.se>
Signed-off-by: Adam.Dybbroe <a000680@c21856.ad.smhi.se>
Adam.Dybbroe added 2 commits November 12, 2020 17:42
Signed-off-by: Adam.Dybbroe <a000680@c21856.ad.smhi.se>
Signed-off-by: Adam.Dybbroe <a000680@c21856.ad.smhi.se>
@adybbroe
Copy link
Collaborator Author

Ok to merge @pnuu ?
I don't see how I should improve the deepcode issue. And I think the stickler issues should be gone...


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'])
Copy link
Member

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?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Oh, yes, right! thx!

Copy link
Member

@pnuu pnuu left a 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.

check_instrument.return_value = None

with pytest.raises(AttributeError) as exec_info:
dummy = RelativeSpectralResponse('MyPlatform')
Copy link
Member

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
Copy link
Member

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.

Copy link
Collaborator Author

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.

Adam.Dybbroe added 2 commits November 13, 2020 16:23
Signed-off-by: Adam.Dybbroe <a000680@c21856.ad.smhi.se>
Signed-off-by: Adam.Dybbroe <a000680@c21856.ad.smhi.se>
@adybbroe adybbroe merged commit 0f2eedb into pytroll:master Nov 13, 2020
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.

Pyspectral incompatible with h5py=3.1.0
6 participants