-
Notifications
You must be signed in to change notification settings - Fork 10
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
Refactoring of FieldOfView and more warnings #265
Merged
astronomyk
merged 12 commits into
AstarVienna:dev_master
from
teutoburg:fh/fov-improvements
Sep 5, 2023
Merged
Refactoring of FieldOfView and more warnings #265
astronomyk
merged 12 commits into
AstarVienna:dev_master
from
teutoburg:fh/fov-improvements
Sep 5, 2023
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Also remove redundant np.unique around self.waveset, which already returns unique elements.
And some de-nesting, and some renaming, and various small stuff.
only took 2 h to figure that one out...
Codecov ReportPatch coverage:
Additional details and impacted files@@ Coverage Diff @@
## dev_master #265 +/- ##
==============================================
+ Coverage 80.20% 80.23% +0.03%
==============================================
Files 143 143
Lines 14779 14805 +26
==============================================
+ Hits 11853 11879 +26
Misses 2926 2926
☔ View full report in Codecov by Sentry. |
astronomyk
approved these changes
Sep 5, 2023
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.
Nicely done!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Refactoring
FieldOfView
.make_...
methods were very long, but clearly sectioned. I used that to create several smaller auxiliary functions to split things up a bit. Maybe, with some further refactoring in the future, we might be able to merge some of those. Or subclassFieldOfView
🙃np.unique
was used to get a list of unique elements (reference indices for spectra mostly). This is a textbook usecase of aset
, so I used that instead.xfail
actually (currently) XPASS, so I included them back in. Those were quite useful in making sure the refactoring here didn't break stuff. I think it would be worth looking into why the others still xfail (as they did before this PR).FovVolumeList
now inherits fromcollections.abc.MutableSequence
, because that's what it really is, making some nice mixin-methods available.Generators
I turned some "list-appending-in-loop" functions (mostly in
optics.fov_manager_utils
(sidenote: I'm not sure where the functions in that module are actually used - I hope it's not something abandoned? 😂 )) into generators, meaning they will not return the instantiatedlist
, but a generator, that can either be turned into alist
immediately, or just iterated over when access to the whole list (or repeated access) is not needed. This will change the API of some functions, so I updated some tests accordingly.De-nesting
Various parts of the codebase have almost a whole function inside an
if
-clause, which is skipped if the condition is not met. Most of these cases can be simplified by an "early return" approach, i.e. checking for the negative of that condition, and aborting if it's not met, otherwise proceeding as normal (I think it's called a "guard clause" sometimes). There are more of these that I will eventually tackle when working on those classes anyway...In some other cases, things could be de-nested by other approaches, such as combining a double loop into a single iteration.
Warnings
Motivated by the issues a user was experiencing, I included a few checks for observing a source and warnings if those fail:
extract_area_from_imagehdu
).Misc
No more mutable default arguments
Mutable default arguments (i.e.
def foo(bar=[]):
) can cause unintended consequences (see e.g. this article) and should be avoided. If I haven't missed any, this should get rid of all of them in this repo (there were only a handful of cases anyway). In all cases,None
is now used as the default, and check for that.Boolean conditions
There were a few cases of
if foo is True:
orif foo is False:
, which I replaced withif foo:
orif not foo:
, respectively.log instead of print
Self-explaining...
Renaming
Not really worth mentioning, but for completeness: I renamed some variables for clarity (and to shutup pylint).
Docstring
Along the way, I made some fixes to various docstrings, both in content and to comply with Numpy's style manual.