Skip to content
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

Closed
wants to merge 15 commits into from

Conversation

yucongalicechen
Copy link
Collaborator

  • 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.

Copy link
Contributor

@sbillinge sbillinge left a 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.

src/diffpy/labpdfproc/labpdfprocapp.py Outdated Show resolved Hide resolved
Copy link
Contributor

@sbillinge sbillinge left a 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.

@yucongalicechen
Copy link
Collaborator Author

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!

Copy link
Contributor

@sbillinge sbillinge left a 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.

src/diffpy/labpdfproc/functions.py Outdated Show resolved Hide resolved
src/diffpy/labpdfproc/functions.py Outdated Show resolved Hide resolved
src/diffpy/labpdfproc/functions.py Outdated Show resolved Hide resolved
…rs _cve_brute_force or _cve_interp_polynomial
Copy link
Contributor

@sbillinge sbillinge left a 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 Show resolved Hide resolved
src/diffpy/labpdfproc/functions.py Show resolved Hide resolved
src/diffpy/labpdfproc/functions.py Outdated Show resolved Hide resolved
else:
return _cve_interp_polynomial(diffraction_data, mud, wavelength)


def compute_cve(diffraction_data, mud, wavelength, brute_force=False):
Copy link
Contributor

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.

Copy link
Collaborator Author

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?

Copy link
Collaborator Author

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).

Copy link
Contributor

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.

Copy link
Collaborator Author

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?

Copy link
Contributor

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.

@yucongalicechen
Copy link
Collaborator Author

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.

Copy link
Contributor

@sbillinge sbillinge left a 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.

src/diffpy/labpdfproc/functions.py Show resolved Hide resolved
return methods[method]


def compute_cve(diffraction_data, mud, method="polynomial_interpolation"):
Copy link
Contributor

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"

src/diffpy/labpdfproc/functions.py Show resolved Hide resolved
"-m",
"--method",
help=f"The method for computing absorption correction. Allowed methods: {*CVE_METHODS, }. "
f"Default method is polynomial interpolation if not specified. ",
Copy link
Contributor

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?

src/diffpy/labpdfproc/labpdfprocapp.py Show resolved Hide resolved
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
Copy link
Contributor

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?

src/diffpy/labpdfproc/tools.py Show resolved Hide resolved
@sbillinge
Copy link
Contributor

@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.

@yucongalicechen
Copy link
Collaborator Author

Sounds great, I'll break these into different issues and PRs and let you know!

@yucongalicechen
Copy link
Collaborator Author

@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.
We have output_dir=Path(...).resolve() so it is the absolute Path, so in the docstring I'll correct it as a Path object.
I want to make sure that we're happy with having output directory as a Path object instead of a string object?

@sbillinge
Copy link
Contributor

@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. We have output_dir=Path(...).resolve() so it is the absolute Path, so in the docstring I'll correct it as a Path object. I want to make sure that we're happy with having output directory as a Path object instead of a string object?

Yes if it works.

@yucongalicechen
Copy link
Collaborator Author

Yes I think Path works better than string. I edited the docstring in #96.

@yucongalicechen
Copy link
Collaborator Author

closed by PR #89, #92, #93, and #96.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement quick calculation
2 participants