Re: [julia-users] Re: Computing colors of molecules with Julia
This is now implemented in Color.jl; not tagged yet, but you can of course do Pkg.checkout(Color) Fun thing to try: using Interact, Color @manipulate for m = 1:50, n = 1:100 RGB[RGB(i/m,j/n,0) for i=1:m, j=1:n] end On Monday, June 9, 2014 2:07:22 PM UTC-4, Stefan Karpinski wrote: That does seem like a rather nice solution. Makes sense for matrices too – displaying a color matrix as a 2D color swatch would be handy. On Mon, Jun 9, 2014 at 1:54 PM, Steven G. Johnson steve...@gmail.com javascript: wrote: Rather than defining a ColorVector type to display color vectors as rainbow swatches, it might be nice to update the writemime function for AbstractVector{:ColorValue} in Color.jl https://github.com/JuliaLang/Color.jl/blob/master/src/display.jl#L19-L50 so that it displays long vectors more nicely. That is, shrink the width of the swatch size further for long vectors, e.g. in order to fix the overall width.
Re: [julia-users] Re: Computing colors of molecules with Julia
wow, that Interact package is interesting... I guess I'll have to start using IJulia then. I'm still stuck with a Vim session and a Julia terminal. I tried the checkout version of Color, and it's the same (see attached), i.e. wrong: the blues should be close to the 400 mark and the reds closer to the 700. the UV purple and IR black should be closer to the ends than what we see. Any idea what's going wrong? Yakir Gagnon The Queensland Brain Institute (Building #79) The University of Queensland Brisbane QLD 4072 Australia cell +61 (0)424 393 332 work +61 (0)733 654 089 On Tue, Aug 26, 2014 at 4:21 AM, Steven G. Johnson stevenj@gmail.com wrote: This is now implemented in Color.jl; not tagged yet, but you can of course do Pkg.checkout(Color) Fun thing to try: using Interact, Color @manipulate for m = 1:50, n = 1:100 RGB[RGB(i/m,j/n,0) for i=1:m, j=1:n] end On Monday, June 9, 2014 2:07:22 PM UTC-4, Stefan Karpinski wrote: That does seem like a rather nice solution. Makes sense for matrices too – displaying a color matrix as a 2D color swatch would be handy. On Mon, Jun 9, 2014 at 1:54 PM, Steven G. Johnson steve...@gmail.com wrote: Rather than defining a ColorVector type to display color vectors as rainbow swatches, it might be nice to update the writemime function for AbstractVector{:ColorValue} in Color.jl https://github.com/JuliaLang/Color.jl/blob/master/src/display.jl#L19-L50 so that it displays long vectors more nicely. That is, shrink the width of the swatch size further for long vectors, e.g. in order to fix the overall width.
Re: [julia-users] Re: Computing colors of molecules with Julia
Oh sorry, I vaguely mentioned it in my first reply. The short answer is: using Color,Images n = 500 wl1 = 380. wl2 = 780. wl = linspace(wl1,wl2,n) I = Array(Float64,n,n,3) for i = 1:n xyz = colormatch(wl[i]) rgb = convert(RGB,xyz) for (j,f) in enumerate([:r,:g,:b]) I[i,:,j] = rgb.(f) end end imwrite(I,a.png) This results in the attached image. While I'm sure there's a much better way of getting that done (feel free to show be btw, I'd love to know how to improve), you can immediately see that the blues and reds are too far close to each other and that the UV violet and IR black are overly represented. The long answer is that I used pgfplots with Julia to generate that first image. So the pgfplots part is this: \begin{tikzpicture} \draw (0,0) node {\pgfuseshading{mySpectrum}}; \foreach \x/\xl in {-3/400,-1/500,1/600,3/700}{ \draw[gray] (\x,-.75) -- (\x,-1.25) node[anchor=north,black] {\xl}; } \node at (0,-2) {Wavelength (nm)}; \end{tikzpicture} and the julia part is this: using Color n = 50 wl1 = 380 wl2 = 780 width = 8 wl = linspace(wl1,wl2,n) d = linspace(0,width,n) f = open(spectrum.txt,w) write(f,\\pgfdeclarehorizontalshading{mySpectrum}{2cm}{\n) for i = 1:n-1 xyz = colormatch(wl[i]) rgb = convert(RGB,xyz) txt = \trgb($(d[i])cm)=($(rgb.r),$(rgb.g),$(rgb.b));\n write(f,txt) end i = n xyz = colormatch(wl[i]) rgb = convert(RGB,xyz) txt = \trgb($(d[i])cm)=($(rgb.r),$(rgb.g),$(rgb.b))} write(f,txt) close(f) xl = [400:100:700] nxl = length(xl) wli = wl2-wl1 w = zeros(nxl) for i = 1:nxl r = (xl[i]-wl1)/wli w[i] = width*r end w .-= width/2 Yakir Gagnon The Queensland Brain Institute (Building #79) The University of Queensland Brisbane QLD 4072 Australia cell +61 (0)424 393 332 work +61 (0)733 654 089 On Tue, Aug 26, 2014 at 11:43 AM, Steven G. Johnson stevenj@gmail.com wrote: On Monday, August 25, 2014 6:35:43 PM UTC-4, Yakir Gagnon wrote: I tried the checkout version of Color, and it's the same (see attached), i.e. wrong: the blues should be close to the 400 mark and the reds closer to the 700. the UV purple and IR black should be closer to the ends than what we see. Any idea what's going wrong? You didn't give any indication of how you made that plot...
Re: [julia-users] Re: Computing colors of molecules with Julia
I looked into xcolor, and the color matching function they implement is only a rough approximation (page 55 of the xcolor manual), whereas Color.jl actually matches wavelengths to the CIE standard observer measurements. In this case, I think Color is more correct. Here's someone else's plot made from the CIE data that looks close to the Color.jl one: http://en.wikipedia.org/wiki/Luminosity_function#mediaviewer/File:Srgbspectrum.png On Monday, August 25, 2014 8:43:13 PM UTC-7, Yakir Gagnon wrote: Oh sorry, I vaguely mentioned it in my first reply. The short answer is: using Color,Images n = 500 wl1 = 380. wl2 = 780. wl = linspace(wl1,wl2,n) I = Array(Float64,n,n,3) for i = 1:n xyz = colormatch(wl[i]) rgb = convert(RGB,xyz) for (j,f) in enumerate([:r,:g,:b]) I[i,:,j] = rgb.(f) end end imwrite(I,a.png) This results in the attached image. While I'm sure there's a much better way of getting that done (feel free to show be btw, I'd love to know how to improve), you can immediately see that the blues and reds are too far close to each other and that the UV violet and IR black are overly represented. The long answer is that I used pgfplots with Julia to generate that first image. So the pgfplots part is this: \begin{tikzpicture} \draw (0,0) node {\pgfuseshading{mySpectrum}}; \foreach \x/\xl in {-3/400,-1/500,1/600,3/700}{ \draw[gray] (\x,-.75) -- (\x,-1.25) node[anchor=north,black] {\xl}; } \node at (0,-2) {Wavelength (nm)}; \end{tikzpicture} and the julia part is this: using Color n = 50 wl1 = 380 wl2 = 780 width = 8 wl = linspace(wl1,wl2,n) d = linspace(0,width,n) f = open(spectrum.txt,w) write(f,\\pgfdeclarehorizontalshading{mySpectrum}{2cm}{\n) for i = 1:n-1 xyz = colormatch(wl[i]) rgb = convert(RGB,xyz) txt = \trgb($(d[i])cm)=($(rgb.r),$(rgb.g),$(rgb.b));\n write(f,txt) end i = n xyz = colormatch(wl[i]) rgb = convert(RGB,xyz) txt = \trgb($(d[i])cm)=($(rgb.r),$(rgb.g),$(rgb.b))} write(f,txt) close(f) xl = [400:100:700] nxl = length(xl) wli = wl2-wl1 w = zeros(nxl) for i = 1:nxl r = (xl[i]-wl1)/wli w[i] = width*r end w .-= width/2 Yakir Gagnon The Queensland Brain Institute (Building #79) The University of Queensland Brisbane QLD 4072 Australia cell +61 (0)424 393 332 work +61 (0)733 654 089 On Tue, Aug 26, 2014 at 11:43 AM, Steven G. Johnson steve...@gmail.com javascript: wrote: On Monday, August 25, 2014 6:35:43 PM UTC-4, Yakir Gagnon wrote: I tried the checkout version of Color, and it's the same (see attached), i.e. wrong: the blues should be close to the 400 mark and the reds closer to the 700. the UV purple and IR black should be closer to the ends than what we see. Any idea what's going wrong? You didn't give any indication of how you made that plot...
Re: [julia-users] Re: Computing colors of molecules with Julia
Stand corrected. See attached image for a comparison between the three scales we've discussed. The one in the background is the Julia one, the one on the bottom is the one you showed from Wikipedia, and the one on top is the one from xcolor. You can see that the point where Julia disagrees most with xcolor is at 440 nm: Julia says 440 nm is violet while xcolor says it's blue. I grabbed a 440 nm interference filter (I'm in a lab) and looked. It was violet. Thanks for your time! Yakir Gagnon The Queensland Brain Institute (Building #79) The University of Queensland Brisbane QLD 4072 Australia cell +61 (0)424 393 332 work +61 (0)733 654 089 On Tue, Aug 26, 2014 at 2:29 PM, Daniel Jones danielcjo...@gmail.com wrote: I looked into xcolor, and the color matching function they implement is only a rough approximation (page 55 of the xcolor manual), whereas Color.jl actually matches wavelengths to the CIE standard observer measurements. In this case, I think Color is more correct. Here's someone else's plot made from the CIE data that looks close to the Color.jl one: http://en.wikipedia.org/wiki/Luminosity_function#mediaviewer/File:Srgbspectrum.png On Monday, August 25, 2014 8:43:13 PM UTC-7, Yakir Gagnon wrote: Oh sorry, I vaguely mentioned it in my first reply. The short answer is: using Color,Images n = 500 wl1 = 380. wl2 = 780. wl = linspace(wl1,wl2,n) I = Array(Float64,n,n,3) for i = 1:n xyz = colormatch(wl[i]) rgb = convert(RGB,xyz) for (j,f) in enumerate([:r,:g,:b]) I[i,:,j] = rgb.(f) end end imwrite(I,a.png) This results in the attached image. While I'm sure there's a much better way of getting that done (feel free to show be btw, I'd love to know how to improve), you can immediately see that the blues and reds are too far close to each other and that the UV violet and IR black are overly represented. The long answer is that I used pgfplots with Julia to generate that first image. So the pgfplots part is this: \begin{tikzpicture} \draw (0,0) node {\pgfuseshading{mySpectrum}}; \foreach \x/\xl in {-3/400,-1/500,1/600,3/700}{ \draw[gray] (\x,-.75) -- (\x,-1.25) node[anchor=north,black] {\xl}; } \node at (0,-2) {Wavelength (nm)}; \end{tikzpicture} and the julia part is this: using Color n = 50 wl1 = 380 wl2 = 780 width = 8 wl = linspace(wl1,wl2,n) d = linspace(0,width,n) f = open(spectrum.txt,w) write(f,\\pgfdeclarehorizontalshading{mySpectrum}{2cm}{\n) for i = 1:n-1 xyz = colormatch(wl[i]) rgb = convert(RGB,xyz) txt = \trgb($(d[i])cm)=($(rgb.r),$(rgb.g),$(rgb.b));\n write(f,txt) end i = n xyz = colormatch(wl[i]) rgb = convert(RGB,xyz) txt = \trgb($(d[i])cm)=($(rgb.r),$(rgb.g),$(rgb.b))} write(f,txt) close(f) xl = [400:100:700] nxl = length(xl) wli = wl2-wl1 w = zeros(nxl) for i = 1:nxl r = (xl[i]-wl1)/wli w[i] = width*r end w .-= width/2 Yakir Gagnon The Queensland Brain Institute (Building #79) The University of Queensland Brisbane QLD 4072 Australia cell +61 (0)424 393 332 work +61 (0)733 654 089 On Tue, Aug 26, 2014 at 11:43 AM, Steven G. Johnson steve...@gmail.com wrote: On Monday, August 25, 2014 6:35:43 PM UTC-4, Yakir Gagnon wrote: I tried the checkout version of Color, and it's the same (see attached), i.e. wrong: the blues should be close to the 400 mark and the reds closer to the 700. the UV purple and IR black should be closer to the ends than what we see. Any idea what's going wrong? You didn't give any indication of how you made that plot...
[julia-users] Re: Computing colors of molecules with Julia
This is really cool. It looks like there are still some issues with syntax highlighting in these notebooks (breaking on triple quoted strings, highlighting unicode characters as errors for example) but this situation should improve greatly once my CodeMirror mode is ready for IJulia. On Monday, 9 June 2014 16:04:45 UTC+1, Jiahao Chen wrote: I've started a blog http://jiahao.github.io/julia-blog/ showcasing a few IJulia notebooks I've been working on over the past few months. Currently the only published post is one of my most recent notebooks on using Color.jl to calculate colors of molecules http://jiahao.github.io/julia-blog/2014/06/09/the-colors-of-chemistry.html from their UV-vis spectra. http://jiahao.github.io/julia-blog/2014/06/09/the-colors-of-chemistry.html IJulia notebooks live in a separate repo: https://github.com/jiahao/ijulia-notebooks This was a fun excursion into my former life as a chemist and hopefully gives people an idea of what you can do with IJulia, Color.jl, Gadfly.jl, SIUnits.jl, and Unicode characters.