-
Notifications
You must be signed in to change notification settings - Fork 3
Adding ND rebinner to refactor_24 #178
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
Conversation
krzywon
left a comment
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.
Ideally, NDrebin would be a class instead of a function, and many of the smaller calculation elements would be their own class methods. The many checks for dimensionality, etc, could all be done in the __init__. A series of smaller class methods, each specific to a single calculation, would greatly improved maintainability, and likely clear up the CodeScene complaints.
class NDRebin:
def __init__(data: Quantity[ArrayLike],
coords: Quantity[ArrayLike],
data_errs: Quantity[ArrayLike] | None = None,
axes: list[Quantity[ArrayLike]] | None = None,
upper: list[Sequence[float]] | None = None,
lower: list[Sequence[float]] | None = None,
step_size: list[Sequence[float]] | None = None,
num_bins: list[Sequence[int]] | None = None,
fractional: bool | None = False
):
self.data = data
...
self.binned_data = np.zeroes(self.data.shape()) # I'm not sure this is actually correct.
def __call__():
self.calculate_bins()
def calculate_bins():
# This would be the main call
def _calculate_fractional_binning():
# Put the fractional binning calcs in here.
|
Still refactoring the documentation and tests. The new class-based syntax is: I am wondering if the rebin.run() should just be automatically done when the class is constructed. To me this makes sense but maybe there are object oriented reasons not to? |
|
Should be ready to be reviewed again @krzywon |
DrPaulSharp
left a comment
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.
With respect to rebin.run(), the advantage of separating the run code from initialisation is that it enables the rebinner to be reused after it has been initialised. With further refactoring (which I am not suggesting for this PR) it would be possible to rebin with different parameters, for example:
rebin.run(nbins=30)
rebin.run(nbins=40)
Given this, I'd suggest leaving the code as is regarding running the rebinner.
I've got a few comments, I'll let @krzywon do the full review.
krzywon
left a comment
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.
Overall, much cleaner code. I haven't tested functionality, but unit tests pass. I think the comments and questions posed by @DrPaulSharp are valid and should be addressed
This would still be the case if |
Hmm, given that you have written a |
Very well, then we can keep it as is. |
b32dbfe to
6f3b4af
Compare
|
@DrPaulSharp @krzywon Are we ready to merge this branch in? I think I addressed all of your concerns. |
I'll take a proper look soon, but I need you to do a job for me first. Could you please rebase this branch on top of the refactor branch using |
df3430d to
620179b
Compare
I think I have rebased the branch, though I am not a git ninja. |
That seems to have got it although github has not tidied up the PR unfortunately. The PR currently has +794 lines -0 lines, with two files modified. Is this what you expect for the work you have done here? Hmm, there are 592 commits, which I don't like the look of. |
…nd removed for loops and most conditional logic
…d return in NDRebin __call__
…d return in NDRebin __call__
620179b to
8ea93ee
Compare
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.
No quality gates enabled for this code.
See analysis details in CodeScene
Quality Gate Profile: Custom Configuration
Want more control? Customize Code Health rules or catch issues early with our IDE extension and CLI tool.
|
Ok, that sorts the rebase. I'll give the code a once over later today. |
DrPaulSharp
left a comment
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.
@krzywon may want another look, but all seems ok to me.
This pull request adds a new function called NDrebin to the transforms folder. The goal of NDrebin is to enable the rebinning of an arbitrary sampling of datapoints in N-dimensions to a regular grid in N-dimensions. This is highly useful for arbitrary data visualization when the data was not measured on a nice uniform set of points, as is the case for example with (qx,qy,qz) points measured on a SANS instrument.
Note that this function will somewhat average or interpolate data, so some resolution information is lost. The ideal case is to fit or model directly to measured datapoints, then use NDrebin on both the data and the fit to produce plots and visualizations that can be compared.
Also added a utest_NDrebin file to test the NDrebin function. Additional manual tests can be performed by running the NDrebin.py file as main.