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

Gaussian optics module #617

Merged
merged 6 commits into from
Sep 30, 2011
Merged

Gaussian optics module #617

merged 6 commits into from
Sep 30, 2011

Conversation

Krastanov
Copy link
Member

This commit implements gaussian optics module.

Announced on the mailing list: https://groups.google.com/d/topic/sympy/nDG4i32GJF0/discussion

It implements
Ray transfer matrices for geometrical rays and gaussian beams.
Conjugation relations.

Not all functions have been used in practice, so errors in the implemented formulas are still possible. That being said, I have not found any.

Doctests are present.
Unittests are present.

  • multiplications of the three classes
  • all getters of RayTransferMatrix, GeometricalRay and BeamParameter
  • all helper functions

code_quality, doctest and test_gaussopt all pass.

I've checked the raised exceptions.

TODO: final review? or additional fixes...

This commit implements gaussian optics module.
To import use sympy.physics.gaussopt.

It implements
  Ray transfer matrices for geometrical rays and gaussian beams.
  Conjugation relations.

Doctests are present.
Unit tests are not present.
@mrocklin
Copy link
Member

Should there be a separate test_gaussopt.py file? I see that the functions all have nice doctests. Copying these over would be helpful.

@Krastanov
Copy link
Member Author

I have checked the spelling and your remark about NotImplementedError is correct. I'm adding it shortly.

This commit implements gaussian optics module.
To import use sympy.physics.gaussopt.

It implements
  Ray transfer matrices for geometrical rays and gaussian beams.
  Conjugation relations.

Doctests are present.
Unit tests are not present.
@Krastanov
Copy link
Member Author

Concerning separate test file test_gaussopt.py: should there be one if it only mimics the doctests? I don't think so. Still I can imagine some additional tests but they seem redundant.

@mrocklin
Copy link
Member

I prefer tests to doctests because I always check the tests and rarely run the doctests. This is a failing on my part to be sure but I get the impression that it's common.

@smichr
Copy link
Member

smichr commented Sep 24, 2011

The following lines/routines need tests
ang
dist
R
divergence
gouy
waist_aproximation_limit
if abs(a) == oo or abs(b) == oo:
return a if abs(b) == oo else b

I would recommend renaming R, dist and ang to radius, distance and angle.
Perhaps w_0 as beam_waist; is there are more descriptive name for w?
gouy as phase? is there any other phase that this would be confused with?

I put the doctests into a test suite and sent this as a pull request. Do you know how to merge it into your branch?

@Krastanov
Copy link
Member Author

I merged the tests. Thanks for the work (have you used a script to transform the tests?).

Renaming and testing those routines is on my todo list.

@asmeurer
Copy link
Member

You should definitely have tests in addition to doctests. The doctests are just examples, which happen to be tested so that they are correct. The unit tests are the ones that are used to check for regression. So, for example, the test coverage does not even consider the doctests, and it should be assumed that any doctest can be changed without worrying about changing coverage, e.g., if the example is more enlightening.

@smichr
Copy link
Member

smichr commented Sep 24, 2011

editor magic and elbow grease

CurvedRefraction, FlatMirror, FlatRefraction, FreeSpace, GeometricRay,
FreeSpace, RayTransferMatrix, ThinLens, ThinLens, conjugate_gauss_beams,
gaussian_conj , geometric_conj_ab, geometric_conj_af, geometric_conj_bf,
rayleigh2waist, waist2rayleigh)
Copy link
Member

Choose a reason for hiding this comment

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

I would put an empty line here, but that's minor.

@certik
Copy link
Member

certik commented Sep 25, 2011

Test results html report: http://pastehtml.com/view/b8ffy651i.html

Summary: There were test failures.

@Krastanov: Please fix the test failures.

Automatic review by sympy-bot.

and args[0].shape == (2,2):
temp = args[0]
else:
raise Exception('Bad arguments for the constructor.')
Copy link
Member

Choose a reason for hiding this comment

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

The code quality tests seem to fail here.

Copy link
Member

Choose a reason for hiding this comment

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

Something like this can be used:

raise ValueError('Expecting 2x2 Matrix or the 4 elements of the Matrix but got %s' % args)

@Krastanov
Copy link
Member Author

I have added the last tests suggested by smichr. I have also fixed the code quality errors.

doctests, test_gaussopt, and test_code_quality pass.

@smichr
Copy link
Member

smichr commented Sep 25, 2011

Just a question about the ray angle. I'm not sure how to think about that if I have a sequence of items through which the beam is passing, e.g. through two lenses. Are the lenses always perpendicular to the beam? If so, the only time I would imagine the beam angle mattering is when a mirror or refractive surface is hit. But in those cases, my first thought is that I would give them an orientation angle, not the beam.

@Krastanov
Copy link
Member Author

I'll check the error messages.

Concerning the formalism:
The angle of the geometrical ray is the angle between the ray and the optical axis. All elements are perpendicular to the optical axis. http://en.wikipedia.org/wiki/Ray_transfer_matrix_analysis

for example if we have a ray at angle alpha to the axis and passing at height h over the axis, after distance d in free space the angle will be the same, but the height of the ray will be alpha*d + h.

All angles are considered small (gaussian approximation)

@Krastanov
Copy link
Member Author

I've fixed the error message and squashed the last commit.

@mrocklin
Copy link
Member

Test results html report: http://pastehtml.com/view/b8hdxumpj.html

Summary: There do not appear to be any problems.

Please double check this against the test report given above before merging with master.

Automatic review by sympy-bot.

@smichr
Copy link
Member

smichr commented Sep 26, 2011

tests for height, angle, and multiplication of two RayTransferMatrix are missing.

@Krastanov
Copy link
Member Author

I've added those to the TODO.

No general exceptions in the code.
Tests for conjugation at distance == oo.
Tests for multiplication of RayTransferMatrices.
Tests for methods of GeometricalRay.
@Krastanov
Copy link
Member Author

I've squashed the last commit addressing the remarks of @smichr.

Unittests are present.

  • multiplications of the three classes
  • all getters of RayTransferMatrix, GeometricalRay and BeamParameter
  • all helper functions

code_quality, doctest and test_gaussopt all pass.

I've checked the raised exceptions.

@asmeurer
Copy link
Member

Test results html report: http://pastehtml.com/view/b912u79pq.html

Note A custom test command was used: python2.5 setup.py test

Summary: There do not appear to be any problems.

Please double check this against the test report given above before merging with master.

Automatic review by sympy-bot.

smichr added a commit that referenced this pull request Sep 30, 2011
@smichr smichr merged commit 17221aa into sympy:master Sep 30, 2011
@smichr
Copy link
Member

smichr commented Sep 30, 2011

Thanks, this is in! (I still remember the humiliation as a grad student of being given an exercise in tracing a ray through a series of optical pieces and failing miserably. The prof's introduction of sign conventions the next day was like water for a thirsty man :-))

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.

5 participants