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

Changes to Synchrotron Radiation from issue #4921. Part 1. #4926

Merged
merged 6 commits into from
Jun 10, 2024

Conversation

FilipO28555
Copy link
Contributor

@FilipO28555 FilipO28555 commented Jun 5, 2024

in validate():

  • subtract_functions() is now without a bug and unnecessary list truncation
  • Changed the number of bins to 200 for better accuracy

Todos from issue #4912:

as well as uses pathlib and some comment corrections
@FilipO28555 FilipO28555 changed the title Changes to Synchrotron Radiation from issue [#4921](https://github.com/ComputationalRadiationPhysics/picongpu/issues/4912). part 1 Changes to Synchrotron Radiation from issue #4921. Part 1. Jun 5, 2024
…ncation

2) Changed the number of bins to 200 for better accuracy
3) added some printouts for clarity
@FilipO28555 FilipO28555 marked this pull request as ready for review June 5, 2024 14:36
- Introduced `read_photon_data` function to encapsulate the logic for reading and processing photon data from OpenPMD series iteration.
- Introduced `read_electron_data` function to encapsulate the logic for reading and processing electron data from OpenPMD series iteration.
- Refactored the `main` function to use the new abstraction functions for reading photon and electron data.

This change improves code readability and maintainability by separating concerns and making the main function less complex.
@PrometheusPi PrometheusPi added component: tools scripts, python libs and CMake refactoring code change to improve performance or to unify a concept but does not change public API labels Jun 6, 2024
@PrometheusPi PrometheusPi added this to the 0.8.0 / Next stable milestone Jun 6, 2024
Copy link
Contributor

@chillenzer chillenzer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, looks good. Thanks for going the extra mile to make this a little more sustainable code. In what sense are the questions answered? They are already ticked but that information has not propagated to me. So, it is likely that whatever method you used to answer them, does not help the uninvolved future reader of your code.

x1 = [x for x in x1 if x >= minX and x <= maxX]
y0 = [y for x, y in zip(x0, y0) if x >= minX and x <= maxX]
y1 = [y for x, y in zip(x1, y1) if x >= minX and x <= maxX]

y1 = np.interp(x0, x1, y1) # interpolate y1 to the x0 values
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, so you are saying that you are fine with the default behaviour of np.interp here? I would have assumed that for histograms using left=0, right=0 would have been the most faithful extrapolation.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right. I did that. I also changed the name to be more descriptive

share/picongpu/tests/Synchrotron_plugin/lib/validate.py Outdated Show resolved Hide resolved
@@ -114,11 +134,12 @@ def main(dataPath):
analytical_integrated = np.array(analytical_integrated)[mask]

x, y = subtract_functions(delta, analytical_integrated, b, a)
poorness = np.sum(y) / len(y) # average error
poorness = np.sum(y) / len(y) # average relative error
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use np.mean (potentially with axis=0) here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We left it because in the future we might do something like np.sum(y*np.sqrt(a)) / len(y)

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 still a mean isn't it? np.mean(y*np.sqrt(a))

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with @chillenzer

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and why is this now "relative" ?

Copy link
Contributor Author

@FilipO28555 FilipO28555 Jun 7, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was always relative.
Also changed to np.mean()

 - in np.interp() added left=0 and right=0
 - subtract_functions() is now relative_error_array()
 - SystemExit changed to ValueError
Copy link
Contributor

@chillenzer chillenzer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good work!

Copy link
Member

@PrometheusPi PrometheusPi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just some minor requests.

@@ -114,11 +134,12 @@ def main(dataPath):
analytical_integrated = np.array(analytical_integrated)[mask]

x, y = subtract_functions(delta, analytical_integrated, b, a)
poorness = np.sum(y) / len(y) # average error
poorness = np.sum(y) / len(y) # average relative error
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with @chillenzer

share/picongpu/tests/Synchrotron_plugin/lib/validate.py Outdated Show resolved Hide resolved
@PrometheusPi PrometheusPi added the CI:no-compile CI is skipping compile/runtime tests but runs PICMI tests label Jun 6, 2024
and reverted the ValueError to SystemExit
@PrometheusPi PrometheusPi merged commit 077ec93 into ComputationalRadiationPhysics:dev Jun 10, 2024
9 checks passed
@chillenzer chillenzer mentioned this pull request Sep 11, 2024
13 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CI:no-compile CI is skipping compile/runtime tests but runs PICMI tests component: tools scripts, python libs and CMake refactoring code change to improve performance or to unify a concept but does not change public API
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants