-
Notifications
You must be signed in to change notification settings - Fork 11
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
add fast_cve to labpdfprocapp.py and some other fixes #87
Conversation
yucongalicechen
commented
Jul 25, 2024
- closes Implement quick calculation #85 (changed default calculation to fast cve while giving an option of -b to enable brute-force calculation. system exit if mu*D is out of range for 0.5-6.)
- fixed a few other issues: it seems that we accidentally deleted the labpdfproc command last time (so we cannot run the last released version using labpdfproc). also the default value for args.output_correction was wrong.
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.
looks good. Please see 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.
I am not sure I like this refactoring tbh as it makes the brute_force
and fast_
calculations assymmetric.
I think a better design is to have different ways of computing the cve, all of which have the same signature and return the same data-types (and units) and when they are applied the "factory method" (but it can just be an if-statement) just figures out which to call.
You can decide whether we do both on the data grid (so pass in hte data-grid) or both on a 0.1 grid and do the interpolation outside, but I think this would be clearer and easier to maintain and extend (for example, if we come up with a new way of computing that we want to add.
Also, why does fast_cve have its own module? Either put it in functions.py
or make a module of cve_calculators.py
, but probably the former unless it is getting too long and messy.
Okay, yes I agree it is confusing to define different tth grids. I put the fast_cve module into functions with an if-else statement on which method to use. Should be more readable now! |
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.
please see my comments. This seems to be heading a little bit in the wrong direction. If you want to chat about the design we can, or if you have it figured out from my comments, that is fine too.
It is easy to fix.
…rs _cve_brute_force or _cve_interp_polynomial
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.
please see comments
src/diffpy/labpdfproc/functions.py
Outdated
else: | ||
return _cve_interp_polynomial(diffraction_data, mud, wavelength) | ||
|
||
|
||
def compute_cve(diffraction_data, mud, wavelength, brute_force=False): |
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.
This function naming is a bit confusing. I think the cve is computed in the function you call _cve_method
, so that should be called _compute_cve
. This function seems to do something else, like take a computed cve and put it into a diffraction object.
Let's maybe have a quick conversation about this.
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.
Does _interpolate_cve
sound good?
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.
I added the method argument to args and cleaned up the four relevant functions in functions.py (_cve_brute_force, _cve_polynomial_interpolation, _compute_cve, and interpolate_cve).
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.
I added the method argument to args and cleaned up the four relevant functions in functions.py (_cve_brute_force, _cve_polynomial_interpolation, _compute_cve, and interpolate_cve).
I guess my question is whether we need this function. I feel like I want a function where I give it a grid (in the form of a DO) and it gives me a cve, and a function that I give a diffraction pattern and a cve on hte same grid as each other and it gives me a corrected pattern, regardless of what backend is used. So the interpolation step is not needed for the brute-force case, and it probably should be done as part of the cve calculation in the fast cve calculator? I am interested in the cleanest interface for the user.
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.
I think this function is necessary. If we use the original grid for brute-force calculations, it could take forever to run (so I think the interpolation would be necessary), and the interpolation is accurate since the numbers are small.
If we're interested, I can explore whether we can write cve as a continuous function of angle so that we can remove the interpolation?
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.
that's ok, I don't mind having an interpolation. I just don't like the current structure because it gives a messy api and difficult to follow code. btw, we might be able to interpolate onto different grids in the DO itself. I wanted to have that capability but not sure if I implemented it.
I updated the functions so that they now pass around DOs. There are some duplicated codes but I think it might good to have some comments on the current structure first. |
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.
please see inline comments. Sorry, I started a review before but didn't finish it.
return methods[method] | ||
|
||
|
||
def compute_cve(diffraction_data, mud, method="polynomial_interpolation"): |
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.
Good practice here is to make the default as method=None
then in the code do
If method is None:
method = "polynomial_interpolation"
"-m", | ||
"--method", | ||
help=f"The method for computing absorption correction. Allowed methods: {*CVE_METHODS, }. " | ||
f"Default method is polynomial interpolation if not specified. ", |
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.
is there an indent problem here?
it is determined as follows: | ||
If user provides an output directory, use it. | ||
Otherwise, we set it to the current directory if nothing is provided. | ||
We then create the directory if it does not exist. | ||
|
||
Returns | ||
------- | ||
pathlib.PosixPath that contains the full path of the output directory |
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.
why are we returning posixPath and not just Path? We want it to be platform independent, no?
@yucongalicechen this PR is getting a bit long and complicated. We can split some of the tasks into other PRs if we like,like outputting chi and not xy files. Make an issue to do that and note it in the conversation, then we can resolve the conversation and try and resolve all the conversations either by code fixes or issues, then we can merge this. It is in the right direction now. |
Sounds great, I'll break these into different issues and PRs and let you know! |
@sbillinge I think I addressed all comments here in PR #89, #92, and #93, except that there's one comment about the posixPath I haven't got to. |
Yes if it works. |
Yes I think Path works better than string. I edited the docstring in #96. |