Skip to content

Feature #252: clearer error and check for emissivity function#254

Merged
Didou09 merged 24 commits intodevelfrom
feature-#252
Nov 19, 2019
Merged

Feature #252: clearer error and check for emissivity function#254
Didou09 merged 24 commits intodevelfrom
feature-#252

Conversation

@lasofivec
Copy link
Copy Markdown
Collaborator

@lasofivec lasofivec commented Nov 15, 2019

Cleaner errors when user didn't define a correct emissivity function.

For example, if using function in #248 (comment), we get:

AssertionError: Input emissivity function (ff): When t=None or t is a scalar, ff must return a 2D (1, npts) np.ndarray!

Solves #252

@pep8speaks
Copy link
Copy Markdown

pep8speaks commented Nov 15, 2019

Hello @lasofivec! Thanks for updating this PR. We checked the lines you've touched for PEP 8 issues, and found:

Line 158:39: E713 test for membership should be 'not in'

Comment last updated at 2019-11-19 18:02:52 UTC

@lasofivec lasofivec requested a review from Didou09 November 15, 2019 17:11
@lasofivec lasofivec self-assigned this Nov 15, 2019
@Didou09
Copy link
Copy Markdown
Member

Didou09 commented Nov 18, 2019

Good idea,
Just taking over from here to:

  • finish PEP8 compliance
  • Modify a bit the error handling (see review)

Copy link
Copy Markdown
Member

@Didou09 Didou09 left a comment

Choose a reason for hiding this comment

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

All godd, but just taking over to polish (PEP + if instead of asserts)

Comment thread tofu/geom/_GG.pyx
######################################################################
# Signal calculation
######################################################################
cdef get_insp(ff):
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Ok, so I understand you are taking the function checking out of _GG to place into _core right ?
That's fine for me, just want to be sure I get it ;-)

Comment thread tofu/geom/_core.py
and pp.default is not pp.empty)]
return na, kw

def check_ff(self, ff, t=None, ani=None):
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

All good to me, the more detailed the error messages, the better it is for everyone indeed :-)

Comment thread tofu/geom/_core.py Outdated
time_steps = -1
# .. Checking basic definition of function ..........................
str_error = "Input emissivity function (ff): "
assert hasattr(ff, '__call__'), (str_error
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

However, small caveat: the sue of assert, though compact, is not the best option in my sense.
If statements would be bit better because:

  • more readable code structure
  • The error messages are defined only if the check is not passed (with assert, the message has to be defined even if there is no error).
  • This technical reason

I'll take over from here just to turn asserts into if, for good habits

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

ok, the code was originally yours :)

@codecov-io
Copy link
Copy Markdown

codecov-io commented Nov 18, 2019

Codecov Report

Merging #254 into devel will increase coverage by 0.05%.
The diff coverage is 66.1%.

Impacted file tree graph

@@            Coverage Diff             @@
##            devel     #254      +/-   ##
==========================================
+ Coverage   43.85%   43.91%   +0.05%     
==========================================
  Files          74       74              
  Lines       21462    21518      +56     
==========================================
+ Hits         9412     9449      +37     
- Misses      12050    12069      +19
Impacted Files Coverage Δ
tofu/utils.py 48.76% <100%> (+0.04%) ⬆️
tofu/version.py 100% <100%> (ø) ⬆️
tofu/tests/tests09_tutorials/tests01_runall.py 65.59% <55.55%> (-0.69%) ⬇️
tofu/geom/_core.py 63.5% <65.95%> (+0.03%) ⬆️

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 190338e...20e66de. Read the comment docs.

Comment thread tofu/geom/_core.py Outdated
try:
out = ff(test_pts, t=t)
except Exception:
assert False, (str_error
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

To force raise an exception just use
raise Exception(msg)

(assert False if overkill)

Comment thread tofu/geom/_core.py Outdated
+ " ff(Pts, t=t), where Pts is a (3, npts) np.array and"
+ " t a len()=nt iterable,"
+ " must return a (nt, npts) np.ndarray!")
assert (type(out) is np.ndarray
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Good practice : try using isinstance(var, class) instead of type(var) is class whenever possible
(I used to do the same, sorry)

Comment thread tofu/geom/_core.py Outdated
+ " np.ndarray when Pts is (3, npts), vect is"
+ " provided and t is None or a scalar")
assert type(out) is np.ndarray and out.shape == (1, npts), msg
return
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This function should return is_ani

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

why ?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Because:

  • It used to in the original version
  • the default value of ani is None, but the functions called later take ani as input and expect it to be True or False. This function function (check_ff) determines whether ani is True or False, even when it is None. It checks and format ani for other functions called later

@Didou09 Didou09 merged commit 78c221f into devel Nov 19, 2019
@Didou09 Didou09 deleted the feature-#252 branch November 19, 2019 18:22
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.

4 participants