Skip to content
This repository has been archived by the owner on Oct 23, 2022. It is now read-only.

Fix type validation and parsing in Parameter column #187

Merged
merged 2 commits into from
May 19, 2021

Conversation

alfredclwong
Copy link
Collaborator

  1. Make Parameters be subtypes of Vector{<:Pair{<:AbstractString,<:Real}} which allows for flexibility beyond numerically indexed coefficients.
  2. Fix the parsing of Aspherics to convert this into a Vector{Tuple{Int,S}} to conform with existing surface constructors (temporary fix, we'll probably rewrite the constructors soon).

Currently (without these changes), Examples.draw_zoomlenses doesn't work.

@alfredclwong alfredclwong added the bug Something isn't working label May 13, 2021
@alfredclwong alfredclwong requested a review from BrianGun May 13, 2021 18:43
@alfredclwong alfredclwong self-assigned this May 13, 2021
@alfredclwong alfredclwong enabled auto-merge (squash) May 13, 2021 18:44
@codecov-commenter
Copy link

codecov-commenter commented May 13, 2021

Codecov Report

Merging #187 (e2cdf0d) into main (13844d1) will decrease coverage by 0.80%.
The diff coverage is 78.26%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #187      +/-   ##
==========================================
- Coverage   56.65%   55.84%   -0.81%     
==========================================
  Files          67       65       -2     
  Lines        6381     6328      -53     
==========================================
- Hits         3615     3534      -81     
- Misses       2766     2794      +28     
Impacted Files Coverage Δ
src/Examples/docs_examples.jl 0.00% <ø> (ø)
src/Examples/other_examples.jl 1.50% <0.00%> (ø)
src/Optical/Lenses.jl 36.52% <0.00%> (-0.65%) ⬇️
src/Optical/OpticalSystem.jl 37.65% <90.00%> (+0.43%) ⬆️
src/Geometry/Primitives/Qtype.jl 75.00% <0.00%> (-8.34%) ⬇️
src/Optical/LensAssembly.jl 48.22% <0.00%> (-7.33%) ⬇️
src/Optical/Emitters/Emitters.jl 75.00% <0.00%> (-5.00%) ⬇️
src/Optical/OpticalInterface.jl 63.23% <0.00%> (-4.30%) ⬇️
src/Geometry/CSG/Intersection.jl 48.57% <0.00%> (-2.14%) ⬇️
src/Geometry/Geometry.jl 0.00% <0.00%> (-1.86%) ⬇️
... and 9 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 13844d1...e2cdf0d. Read the comment docs.

@@ -374,7 +374,12 @@ struct AxisymmetricOpticalSystem{T,C<:CSGOpticalSystem{T}} <: AbstractOpticalSys
elseif surface_type == "Aspheric"
semidiameter = convert(T, max(get_front_back_property(prescription, i, "SemiDiameter", zero(T))...))
Copy link
Contributor

@BrianGun BrianGun May 13, 2021

Choose a reason for hiding this comment

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

A call to convert shouldn't be necessary since semidiameter is declared of type T.

From the official documentation:

When is convert called?
The following language constructs call convert:

Assigning to an array converts to the array's element type.
Assigning to a field of an object converts to the declared type of the field.
Constructing an object with new converts to the object's declared field types.
Assigning to a variable with a declared type (e.g. local x::T) converts to that type.
A function with a declared return type converts its return value to that type.
Passing a value to ccall converts it to the corresponding argument type.

Similarly you should be able to replace this line:

vertices = convert(Vector{T}, -cumsum(replace(prescription[!, "Thickness"], Inf => 0, missing => 0)))

with

vertices::Vector{T} =  -cumsum(replace(prescription[!, "Thickness"], Inf => 0, missing => 0))

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Agreed, this is much better. I was using convert(T, x) to replace several usages of T(x) which were being highlighted as "possible method call errors" by VSCode.

I'm adding a commit that makes better use of type declarations. This also helps with readability.

Copy link
Contributor

@BrianGun BrianGun left a comment

Choose a reason for hiding this comment

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

It's cleaner not to have the explicit convert(T...), or convert(Vector{T}...) statements. What do you think?

@alfredclwong alfredclwong force-pushed the fix/asos-parameters branch from 15814af to e2cdf0d Compare May 14, 2021 08:57
@alfredclwong alfredclwong disabled auto-merge May 14, 2021 08:58
@alfredclwong alfredclwong enabled auto-merge (squash) May 14, 2021 08:58
Comment on lines -396 to 393
if firstelement && semidiameter !== NaN
if firstelement
systemsemidiameter = semidiameter
firstelement = false
end
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This change will allow the Stop semidiameter to define the systemsemidiameter if it's the first element. This is different from the previous behaviour - is this OK?

Copy link
Contributor

Choose a reason for hiding this comment

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

ask Joel Kollin. He could tell us if this makes sense optically.

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 asked the Cambridge team today and the general consensus was that individual semidiameters are important but not so much the system semidiameter. And, if anything, it'd be more useful to have this as the max value. I'll have a look around the code tomorrow to see if this is actually used anywhere currently.

src/Optical/OpticalSystem.jl Show resolved Hide resolved
@alfredclwong alfredclwong requested a review from BrianGun May 14, 2021 14:22
@alfredclwong alfredclwong merged commit 7d8b4b8 into main May 19, 2021
@alfredclwong alfredclwong deleted the fix/asos-parameters branch May 19, 2021 18:05
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants