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

Commit

Permalink
Fix new emitters (#83)
Browse files Browse the repository at this point in the history
* initial refactoring

1. rm Emitter2.jl
2. split Emitters.jl into separate submodule files
3. mv Emitters.Visualization -> Vis
4. rm hacky root-level include("Emitters.jl")
5. fix incorrect import statements

* docs-oriented namespace fixes

* spelling/grammar

* remove dodgy exports

* remove docstrings from glasscat source files

* remove docstrings from CARGILLE

* rm SVector

* add missing doc spectrumpower

* add page for notebook utilities

* add autodocs for OpticSim.Geometry

* remove redundant struct

* fix code style issues

* remove random whitespace
* remove redundant comments above docstrings
* fix docstrings to follow existing conventions
* fix many function type signatures
* move exports to top of files to provide clear submodule headers
* Int -> Integer
* added empty docstrings for generate, visual_size and apply
  these functions clearly need documentation

* bug fixes and doc changes warrant a patch number upgrade

Co-authored-by: BrianGun <[email protected]>
  • Loading branch information
alfredclwong and BrianGun authored Apr 12, 2021
1 parent 3b4150a commit 999b8a6
Show file tree
Hide file tree
Showing 25 changed files with 1,055 additions and 1,534 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name = "OpticSim"
uuid = "24114763-4efb-45e7-af0e-cde916beb153"
authors = ["Brian Guenter", "Charlie Hewitt", "Ran Gal", "Alfred Wong"]
repository = "https://github.com/microsoft/OpticSim.jl"
version = "0.4.1"
version = "0.4.2"

[deps]
CSV = "336ed68f-0bac-5ca0-87d4-7b16caf5d00b"
Expand Down
7 changes: 2 additions & 5 deletions deps/generate.jl
Original file line number Diff line number Diff line change
Expand Up @@ -198,18 +198,15 @@ function catalog_to_modstring(start_id::Integer, catalogname::AbstractString, ca
modstrings = [
"module $catalogname",
"using ..GlassCat: Glass, GlassID, AGF",
# "using StaticArrays: SVector",
"export $(join(keys(catalog), ", "))",
""
]
for (glassname, glassinfo) in catalog
# skip docstrings for CI builds to avoid 'missing docstring' warnings in makedocs
docstring = isCI ? "" : glassinfo_to_docstring(glassinfo, id, catalogname, glassname)
argstring = glassinfo_to_argstring(glassinfo, id)
append!(modstrings, [docstring, "const $glassname = Glass($argstring)", ""])
push!(modstrings, "const $glassname = Glass($argstring)")
id += 1
end
append!(modstrings, ["end #module", ""]) # last "" is for \n at EOF
append!(modstrings, ["end # module", ""]) # last "" is for \n at EOF

return id, join(modstrings, "\n")
end
Expand Down
3 changes: 2 additions & 1 deletion docs/make.jl
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
# SOFTWARE

using Documenter
using OpticSim, OpticSim.Geometry, OpticSim.Emitters
using OpticSim

makedocs(
sitename = "OpticSim.jl",
Expand Down Expand Up @@ -49,6 +49,7 @@ makedocs(
"Glass Functions" => "glasscat.md",
"Optimization" => "optimization.md",
"Cloud Execution" => "cloud.md",
"Notebook utilities" => "notebooksutils.md",
"Reference" => "ref.md",
"Roadmap" => "roadmap.md"
],
Expand Down
51 changes: 25 additions & 26 deletions docs/src/basic_types.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,26 +11,26 @@ using OpticSim, OpticSim.Geometry
Representing a 3D vector.

```@docs
Geometry.Vec3
Geometry.unitX3
Geometry.unitY3
Geometry.unitZ3
Geometry.zero3
Geometry.one3
OpticSim.Geometry.Vec3
OpticSim.Geometry.unitX3
OpticSim.Geometry.unitY3
OpticSim.Geometry.unitZ3
OpticSim.Geometry.zero3
OpticSim.Geometry.one3
```

## Vec4

Representing a 4D vector

```@docs
Geometry.Vec4
Geometry.unitX4
Geometry.unitY4
Geometry.unitZ4
Geometry.unitW4
Geometry.zero4
Geometry.one4
OpticSim.Geometry.Vec4
OpticSim.Geometry.unitX4
OpticSim.Geometry.unitY4
OpticSim.Geometry.unitZ4
OpticSim.Geometry.unitW4
OpticSim.Geometry.zero4
OpticSim.Geometry.one4
```

## Transform
Expand All @@ -39,17 +39,16 @@ Representing a general 3D transform (4x4 matrix). Currently only used as a rigid
Transforms are used to position surfaces within the CSG tree, position emitters in 3D, etc.

```@docs
Geometry.Transform
Geometry.identitytransform
Geometry.rotationX
Geometry.rotationY
Geometry.rotationZ
Geometry.rotation
Geometry.rotationd
Geometry.rotate
Geometry.translation
Geometry.rotmat
Geometry.rotmatd
Geometry.rotmatbetween
OpticSim.Geometry.Transform
OpticSim.Geometry.identitytransform
OpticSim.Geometry.rotationX
OpticSim.Geometry.rotationY
OpticSim.Geometry.rotationZ
OpticSim.Geometry.rotation
OpticSim.Geometry.rotationd
OpticSim.Geometry.rotate
OpticSim.Geometry.translation
OpticSim.Geometry.rotmat
OpticSim.Geometry.rotmatd
OpticSim.Geometry.rotmatbetween
```

2 changes: 1 addition & 1 deletion docs/src/csg.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ The code for this in our system would look this this:
```@example
using OpticSim # hide
cyl = Cylinder(0.7)
cyl_cross = csgunion(csgunion(leaf(cyl), leaf(cyl, rotationd(90, 0, 0))), leaf(cyl, rotationd(0, 90, 0)))
cyl_cross = csgunion(csgunion(leaf(cyl), leaf(cyl, Geometry.rotationd(90, 0, 0))), leaf(cyl, Geometry.rotationd(0, 90, 0)))
cube = Cuboid(1.0, 1.0, 1.0)
sph = Sphere(1.3)
Expand Down
9 changes: 5 additions & 4 deletions docs/src/emitters_new.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ The [`OpticSim`](index.html) package comes with various implementations of each
* [`Emitters.Origins.Point`](@ref) - a single point
* [`Emitters.Origins.RectUniform`](@ref) - a uniformly sampled rectangle with user defined number of samples
* [`Emitters.Origins.RectGrid`](@ref) - a rectangle sampled in a grid fashion
* [`Emitters.Origins.Hexapolar`](@ref) - a circle (or an ellipse) sampled in an hexapolar fasion (rings)
* [`Emitters.Origins.Hexapolar`](@ref) - a circle (or an ellipse) sampled in an hexapolar fashion (rings)
- Rays Directions Distribution - the interface **length** returns the number of samples, and **generate** returns the n'th sample.
* [`Emitters.Directions.Constant`](@ref)
* [`Emitters.Directions.RectGrid`](@ref)
Expand All @@ -30,7 +30,7 @@ The [`OpticSim`](index.html) package comes with various implementations of each

## [Examples of Basic Emitters](@id basic_emitters)

**Note**: All the examples on this page assumes the followin statement was executed:
**Note**: All of the examples on this page assume that the following statement was executed:

```@example
using OpticSim, OpticSim.Geometry, OpticSim.Emitters
Expand Down Expand Up @@ -209,7 +209,7 @@ P = AngularPower.Lambertian()
O = Origins.RectGrid(1.0, 1.0, 3, 3)
D = Directions.HexapolarCone(deg2rad(5.0), 3)
# construct the srouce. in this example a "pixel" source will contain only one source as we are simulating a "b/w" display.
# construct the source. in this example a "pixel" source will contain only one source as we are simulating a "b/w" display.
# for RGB displays we can combine 3 sources to simulate "a pixel".
Tr = Transform(Vec3(0.5, 0.5, 0.0))
source1 = Sources.Source(Tr, S, O, D, P)
Expand All @@ -232,7 +232,7 @@ end
Tr = Transform(Vec3(0.0, 0.0, 0.0))
my_display = Sources.CompositeSource(Tr, pixels)
Vis.draw(my_display) # render the display - nothing bu the origins primities
Vis.draw(my_display) # render the display - nothing but the origins primitives
rays = AbstractArray{OpticalRay{Float64, 3}}(collect(my_display)) # collect the rays generated by the display
Vis.draw!(rays) # render the rays
Expand Down Expand Up @@ -261,6 +261,7 @@ A display example using composite sources.
Emitters.Spectrum.Uniform
Emitters.Spectrum.DeltaFunction
Emitters.Spectrum.Measured
Emitters.Spectrum.spectrumpower
```

## [Angular Power Distribution](@id angular_power_distribution)
Expand Down
45 changes: 0 additions & 45 deletions docs/src/examples.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,51 +37,6 @@ nothing # hide

![Cooke triplet visualization](assets/cooke.png)

## Zoom Lens

```@example
using OpticSim
using DataFrames
function zoom_lens(pos = 1)
if pos == 0
stop = 2.89
zoom = 9.48
dist = 4.46970613
elseif pos == 1
stop = 3.99
zoom = 4.48
dist = 21.21
else
stop = 4.90
zoom = 2.00
dist = 43.81
end
return AxisymmetricOpticalSystem{Float64}(
DataFrame(Surface = [:Object, :Stop, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, :Image],
Radius = [Inf64, Inf64, -1.6202203499676E+01, -4.8875855327468E+01, 1.5666614444619E+01, -4.2955326460481E+01, 1.0869565217391E+02, 2.3623907394283E+01, -1.6059097478722E+01, -4.2553191489362E+02, -3.5435861091425E+01, -1.4146272457208E+01, -2.5125628140704E+02, -2.2502250225023E+01, -1.0583130489999E+01, -4.4444444444444E+01, Inf64],
Aspherics = [missing, missing, missing, missing, missing, [(4, 1.03860000000E-04), (6, 1.42090000000E-07), (8, -8.84950000000E-09), (10, 1.24770000000E-10), (12, -1.03670000000E-12), (14, 3.65560000000E-15)], missing, missing, [(4, 4.27210000000E-05), (6, 1.24840000000E-07), (8, 9.70790000000E-09), (10, -1.84440000000E-10), (12, 1.86440000000E-12), (14, -7.79750000000E-15)], [(4, 1.13390000000E-04), (6, 4.81650000000E-07), (8, 1.87780000000E-08), (10, -5.75710000000E-10), (12, 8.99940000000E-12), (14, -4.67680000000E-14)], missing, missing, missing, missing, missing, missing, missing],
Thickness = [Inf64, 0.0, 5.18, 0.10, 4.40, 0.16, 1.0, 4.96, zoom, 4.04, 1.35, 1.0, 2.80, 3.0, 1.22, dist, missing],
Material = [OpticSim.GlassCat.Air, OpticSim.GlassCat.Air, OpticSim.GlassCat.OHARA.S_LAH66, OpticSim.GlassCat.Air, OpticSim.GlassCat.NIKON.LLF6, OpticSim.GlassCat.Air, OpticSim.GlassCat.OHARA.S_TIH6, OpticSim.GlassCat.OHARA.S_FSL5, OpticSim.GlassCat.Air, OpticSim.GlassCat.OHARA.S_FSL5, OpticSim.GlassCat.Air, OpticSim.GlassCat.OHARA.S_LAL8, OpticSim.GlassCat.OHARA.S_FSL5, OpticSim.GlassCat.Air, OpticSim.GlassCat.OHARA.S_LAH66, OpticSim.GlassCat.Air, missing],
SemiDiameter = [Inf64, stop, 3.85433218451, 3.85433218451, 4.36304692871, 4.36304692871, 4.72505505439, 4.72505505439, 4.72505505439, 4.45240784026, 4.45240784026, 4.50974054117, 4.50974054117, 4.50974054117, 4.76271114409, 4.76271114409, 15.0]))
end
@show zoom_lens(0)
Vis.drawtracerays(zoom_lens(0), test = true, trackallrays = true, numdivisions = 50, resolution = (1200, 600))
Vis.make2dy() # hide
Vis.save("assets/zoom0.png") # hide
Vis.drawtracerays(zoom_lens(1), test = true, trackallrays = true, numdivisions = 50, resolution = (1200, 600))
Vis.make2dy() # hide
Vis.save("assets/zoom1.png") # hide
Vis.drawtracerays(zoom_lens(2), test = true, trackallrays = true, numdivisions = 50, resolution = (1200, 600))
Vis.make2dy() # hide
Vis.save("assets/zoom2.png") # hide
nothing # hide
```

![Zoom position 1 visualization](assets/zoom0.png)
![Zoom position 2 visualization](assets/zoom1.png)
![Zoom position 3 visualization](assets/zoom2.png)

## Schmidt Cassegrain Telescope

```@example
Expand Down
14 changes: 14 additions & 0 deletions docs/src/notebooksutils.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Notebook utilities

```@meta
CurrentModule = NotebooksUtils
```

[TODO]

```@docs
run_sample
SetBackend
run
InitNotebook
```
5 changes: 5 additions & 0 deletions docs/src/ref.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ Pages = ["ref.md"]
Modules = [OpticSim]
```

## Geometry
```@autodocs
Modules = [OpticSim.Geometry]
```

## Zernike

```@autodocs
Expand Down
3 changes: 3 additions & 0 deletions src/Geometry/Geometry.jl
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ module Geometry
include("Transform.jl")

end # module Geometry
export Geometry


using .Geometry

include("Ray.jl")
Expand Down
45 changes: 3 additions & 42 deletions src/GlassCat/data/CARGILLE.jl
Original file line number Diff line number Diff line change
Expand Up @@ -24,49 +24,10 @@

module CARGILLE
using ..GlassCat: Glass, GlassID, OTHER
using StaticArrays: SVector

""" CARGILLE.OG0608
```
ID: OTHER:1
RI @ 587nm: 1.457518
Abbe Number: 57.18978
ΔPgF: 0.008
TCE (÷1e-6): 800.0
Density: 0.878g/m³
Valid wavelengths: 0.32μm to 1.55μm
Reference Temp: 25°C
```
"""
const OG0608 = Glass(GlassID(OTHER, 1), -2, 1.4451400, 0.0043176, -1.80659e-5, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.32, 1.55, -0.0009083144750540808, 0.0, 0.0, 0.0, 0.0, 0.0, 25.0, 0.008, -1.0, -1.0, 800.0, -1.0, 0, -1.0, [SVector(0.32, 0.03, 10.0), SVector(0.365, 0.16, 100.0), SVector(0.4047, 0.40, 100.0), SVector(0.480, 0.71, 100.0), SVector(0.4861, 0.72, 100.0), SVector(0.5461, 0.80, 100.0), SVector(0.5893, 0.90, 100.0), SVector(0.6328, 0.92, 100.0), SVector(0.6439, 0.95, 100.0), SVector(0.6563, 0.96, 100.0), SVector(0.6943, 0.99, 100.0), SVector(0.840, 0.99, 100.0), SVector(0.10648, 0.74, 100.0), SVector(0.1300, 0.39, 100.0), SVector(0.1550, 0.16, 100.0)], 1.457518, -1.0, -1.0, 0, 57.18978, 0, 0.878, -1)

""" CARGILLE.OG0607
```
ID: OTHER:2
RI @ 587nm: 1.457587
Abbe Number: 57.19833
ΔPgF: 0.008
TCE (÷1e-6): 700.0
Density: 0.878g/m³
Valid wavelengths: 0.32μm to 1.55μm
Reference Temp: 25°C
```
"""
const OG0607 = Glass(GlassID(OTHER, 2), -2, 1.44503, 0.0044096, -2.85878e-5, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.32, 1.55, -0.0009083144750540808, 0.0, 0.0, 0.0, 0.0, 0.0, 25.0, 0.008, -1.0, -1.0, 700.0, -1.0, 0, -1.0, [SVector(0.32, 0.15, 10.0), SVector(0.365, 0.12, 100.0), SVector(0.4047, 0.42, 100.0), SVector(0.480, 0.78, 100.0), SVector(0.4861, 0.79, 100.0), SVector(0.5461, 0.86, 100.0), SVector(0.5893, 0.90, 100.0), SVector(0.6328, 0.92, 100.0), SVector(0.6439, 0.90, 100.0), SVector(0.6563, 0.92, 100.0), SVector(0.6943, 0.98, 100.0), SVector(0.840, 0.99, 100.0), SVector(0.10648, 0.61, 100.0), SVector(0.1300, 0.39, 100.0), SVector(0.1550, 0.11, 100.0)], 1.457587, -1.0, -1.0, 0, 57.19833, 0, 0.878, -1)

""" CARGILLE.OG081160
```
ID: OTHER:3
RI @ 587nm: 1.515549
Abbe Number: 36.82493
ΔPgF: 0.014
TCE (÷1e-6): 700.0
Density: 1.11g/m³
Valid wavelengths: 0.32μm to 1.55μm
Reference Temp: 25°C
```
"""
const OG081160 = Glass(GlassID(OTHER, 3), -2, 1.49614, 0.00692199, -8.07052e-5, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.32, 1.55, -0.000885983052189022, 0.0, 0.0, 0.0, 0.0, 0.0, 25.0, 0.014, -1.0, -1.0, 700.0, -1.0, 0, -1.0, [SVector(0.32, 0.04, 100.0), SVector(0.365, 0.13, 100.0), SVector(0.4047, 0.26, 100.0), SVector(0.480, 0.48, 100.0), SVector(0.4861, 0.49, 100.0), SVector(0.5461, 0.60, 100.0), SVector(0.5893, 0.68, 100.0), SVector(0.6328, 0.71, 100.0), SVector(0.6439, 0.73, 100.0), SVector(0.6563, 0.74, 100.0), SVector(0.6943, 0.76, 100.0), SVector(0.840, 0.83, 100.0), SVector(0.10648, 0.86, 100.0), SVector(0.1300, 0.89, 100.0), SVector(0.1550, 0.90, 100.0)], 1.515549, -1.0, -1.0, 0, 36.82493, 0, 1.11, -1)
const OG0608 = Glass(GlassID(OTHER, 1), -2, 1.4451400, 0.0043176, -1.80659e-5, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.32, 1.55, -0.0009083144750540808, 0.0, 0.0, 0.0, 0.0, 0.0, 25.0, 0.008, -1.0, -1.0, 800.0, -1.0, 0, -1.0, [(0.32, 0.03, 10.0), (0.365, 0.16, 100.0), (0.4047, 0.40, 100.0), (0.480, 0.71, 100.0), (0.4861, 0.72, 100.0), (0.5461, 0.80, 100.0), (0.5893, 0.90, 100.0), (0.6328, 0.92, 100.0), (0.6439, 0.95, 100.0), (0.6563, 0.96, 100.0), (0.6943, 0.99, 100.0), (0.840, 0.99, 100.0), (0.10648, 0.74, 100.0), (0.1300, 0.39, 100.0), (0.1550, 0.16, 100.0)], 1.457518, -1.0, -1.0, 0, 57.18978, 0, 0.878, -1)
const OG0607 = Glass(GlassID(OTHER, 2), -2, 1.44503, 0.0044096, -2.85878e-5, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.32, 1.55, -0.0009083144750540808, 0.0, 0.0, 0.0, 0.0, 0.0, 25.0, 0.008, -1.0, -1.0, 700.0, -1.0, 0, -1.0, [(0.32, 0.15, 10.0), (0.365, 0.12, 100.0), (0.4047, 0.42, 100.0), (0.480, 0.78, 100.0), (0.4861, 0.79, 100.0), (0.5461, 0.86, 100.0), (0.5893, 0.90, 100.0), (0.6328, 0.92, 100.0), (0.6439, 0.90, 100.0), (0.6563, 0.92, 100.0), (0.6943, 0.98, 100.0), (0.840, 0.99, 100.0), (0.10648, 0.61, 100.0), (0.1300, 0.39, 100.0), (0.1550, 0.11, 100.0)], 1.457587, -1.0, -1.0, 0, 57.19833, 0, 0.878, -1)
const OG081160 = Glass(GlassID(OTHER, 3), -2, 1.49614, 0.00692199, -8.07052e-5, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.32, 1.55, -0.000885983052189022, 0.0, 0.0, 0.0, 0.0, 0.0, 25.0, 0.014, -1.0, -1.0, 700.0, -1.0, 0, -1.0, [(0.32, 0.04, 100.0), (0.365, 0.13, 100.0), (0.4047, 0.26, 100.0), (0.480, 0.48, 100.0), (0.4861, 0.49, 100.0), (0.5461, 0.60, 100.0), (0.5893, 0.68, 100.0), (0.6328, 0.71, 100.0), (0.6439, 0.73, 100.0), (0.6563, 0.74, 100.0), (0.6943, 0.76, 100.0), (0.840, 0.83, 100.0), (0.10648, 0.86, 100.0), (0.1300, 0.89, 100.0), (0.1550, 0.90, 100.0)], 1.515549, -1.0, -1.0, 0, 36.82493, 0, 1.11, -1)

end

Expand Down
2 changes: 1 addition & 1 deletion src/NotebooksUtils/NotebooksUtils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ function run(; port=nothing, path=nothing, sysimage_file=nothing, auto_detect_sy
local file_path = $path
local sysimage_file_path = $sysimage_file

if (file_path==nothing)
if (file_path === nothing)
@info "Launching Pluto"
else
file_path = fix_path(file_path)
Expand Down
7 changes: 1 addition & 6 deletions src/OpticSim.jl
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,7 @@ include("constants.jl")
include("utilities.jl")
include("Geometry/Geometry.jl")
include("Optical/Optical.jl")
include("Visualization/Visualization.jl")

# TODO: RG: the following include is seperated from the Optical include due to the new approach of putting the visualazation
# part with the logic. We need to come up with a better approch to how and where visualization code should reside.
include("Optical/Emitters.jl") # defines the Emitters module

include("Vis/Vis.jl")
include("Examples/Examples.jl")
include("Optimization/Optimization.jl")
include("Cloud/Cloud.jl")
Expand Down
Loading

2 comments on commit 999b8a6

@alfredclwong
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@JuliaRegistrator register()

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

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

Registration pull request created: JuliaRegistries/General/34171

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.4.2 -m "<description of version>" 999b8a64564b4441fe76643a0b98b9dfb4ed8a7d
git push origin v0.4.2

Please sign in to comment.