-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
check ncoefs only on attribute access
- Loading branch information
1 parent
9c94d84
commit f312819
Showing
4 changed files
with
20 additions
and
14 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,17 @@ | |
class _Scatter: | ||
"""The base object for any Surface and Volume objects.""" | ||
|
||
@property | ||
def ncoefs(self): | ||
"""The number of coefficients used in the legendre expansion.""" | ||
if not hasattr(self, "_ncoefs") or self._ncoefs is None: | ||
This comment was marked as resolved.
Sorry, something went wrong.
This comment was marked as resolved.
Sorry, something went wrong.
raphaelquast
Author
Contributor
|
||
raise AttributeError( | ||
"You must specify the number of approximation coefficients for " | ||
f"a {self.__class__.__name__} scattering function " | ||
"in order calculate interaction-terms!" | ||
) | ||
return self._ncoefs | ||
|
||
def scat_angle(self, t_0, t_ex, p_0, p_ex, a): | ||
""" | ||
Generalized scattering angle with respect to the given zenith-angles. | ||
|
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
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
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
I find this a weird way to enforce an interface. Why not simply make this an abstract property and child classes need to provide a number:
Then just use that property everywhere else instead of
_ncoefs
. If the child class doesn't support or have interaction terms just return 0.In case you need to different concepts of "number of coefficients" then you can introduce a second abstract property and use that instead. But if that's the case make sure both properties are named aptly so it's easy to distinguish the different concepts.