Skip to content

Commit

Permalink
transitioned to Requires for PyPlot and ImageInTerminal
Browse files Browse the repository at this point in the history
  • Loading branch information
chakravala committed Jan 20, 2019
1 parent c06a828 commit 86e2c37
Show file tree
Hide file tree
Showing 9 changed files with 122 additions and 81 deletions.
16 changes: 7 additions & 9 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,21 @@ os:
- linux
- osx
julia:
- 0.7
- 1.0
- nightly
matrix:
allow_failures:
- julia: 1.0
- julia: 0.7
- julia: nightly
env:
global:
- PYTHON=conda
notifications:
email: false
# uncomment the following lines to override the default test script
script:
- if [[ -a .git/shallow ]]; then git fetch --unshallow; fi
- julia -e 'Pkg.clone(pwd()); Pkg.build("Fatou"); Pkg.test("Fatou"; coverage=true)'
#script:
# - if [[ -a .git/shallow ]]; then git fetch --unshallow; fi
# - julia -e 'Pkg.clone(pwd()); Pkg.build("Reduce"); Pkg.test("Reduce"; coverage=true)'
after_success:
# push coverage results to Coveralls
- julia -e 'cd(Pkg.dir("Fatou")); Pkg.add("Coverage"); using Coverage; Coveralls.submit(Coveralls.process_folder())'
- julia -e 'cd(Pkg.dir("Reduce")); Pkg.add("Coverage"); using Coverage; Coveralls.submit(Coveralls.process_folder())'
# push coverage results to Codecov
- julia -e 'cd(Pkg.dir("Fatou")); Pkg.add("Coverage"); using Coverage; Codecov.submit(Codecov.process_folder())'
- julia -e 'cd(Pkg.dir("Reduce")); Pkg.add("Coverage"); using Coverage; Codecov.submit(Codecov.process_folder())'
12 changes: 7 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,10 @@ The environment variable `JULIA_NUM_THREADS` can be used to enable the multi-thr

Please share your favorite fractals as `Fatou` snippet in the [discussion thread](https://discourse.julialang.org/t/ann-fatou-jl-easily-share-julia-fractals)!

## Launching `Fatou` on Julia 1.0.1

Note that `Fatou` is not compatible with Julia 1.0 but works on Julia 1.0.1 alright. At the moment, a stackoverflow error occurs on Julia 1.0.1 when `using Fatou`, which can be avoided by `using Reduce,Fatou` instead.
If you encounter an unsatisfiable requirement in the package manager, an easy workaround is to use `dev Fatou` instead of `add Fatou`.

## Basic Usage

The program can be initialized with `using Fatou, PyPlot` or `ImageInTerminal`.

A Fatou set is a collection of complex valued orbits of an iterated function. To help illustrate this, an additional feature is a plot function designed to visualize real-valued-orbits. The following is a cobweb orbit plot of a function:

```Julia
Expand Down Expand Up @@ -94,3 +91,8 @@ basin(nf,2)
## Detailed Explanation

View [Explore Fatou sets & Fractals](https://github.com/chakravala/Fatou.jl/wiki/Explore-Fatou-sets-&-fractals) in Wiki for detailed *examples*.

### Troubleshooting on Julia 1.0.1+

Note that `Fatou` is not compatible with Julia 1.0 but works on Julia 1.0.1 alright. Note that a stackoverflow error occurs on Julia 1.0.1+ when the `Reduce` package is precompiled with `ENV["REDPRE"]` flag set, therefore it is recommended to not set it.
If you encounter an unsatisfiable requirement in the package manager, an easy workaround is to use `dev Fatou` instead of `add Fatou`.
3 changes: 2 additions & 1 deletion REQUIRE
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
julia 1.0.1
SyntaxTree
Reduce
PyPlot
Requires
LaTeXStrings
ColorSchemes
49 changes: 23 additions & 26 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
environment:
matrix:
- JULIA_URL: "https://julialangnightlies-s3.julialang.org/bin/winnt/x86/julia-latest-win32.exe"
PYTHONDIR: "use_conda"
PYTHON: "use_conda"
- JULIA_URL: "https://julialangnightlies-s3.julialang.org/bin/winnt/x64/julia-latest-win64.exe"
PYTHONDIR: "use_conda"
PYTHON: "use_conda"
- julia_version: 0.7
- julia_version: 1
- julia_version: nightly

platform:
- x86 # 32-bit
- x64 # 64-bit

## uncomment the following lines to allow failures on nightly julia
## (tests will run but not make your overall status red)
matrix:
allow_failures:
- JULIA_URL: "https://julialangnightlies-s3.julialang.org/bin/winnt/x86/julia-latest-win32.exe"
- JULIA_URL: "https://julialangnightlies-s3.julialang.org/bin/winnt/x64/julia-latest-win64.exe"
- julia_version: 0.7
- julia_version: nightly

branches:
only:
- master
Expand All @@ -24,24 +27,18 @@ notifications:
on_build_status_changed: false

install:
- ps: "[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::Tls12"
# If there's a newer build queued for the same PR, cancel this one
- ps: if ($env:APPVEYOR_PULL_REQUEST_NUMBER -and $env:APPVEYOR_BUILD_NUMBER -ne ((Invoke-RestMethod `
https://ci.appveyor.com/api/projects/$env:APPVEYOR_ACCOUNT_NAME/$env:APPVEYOR_PROJECT_SLUG/history?recordsNumber=50).builds | `
Where-Object pullRequestId -eq $env:APPVEYOR_PULL_REQUEST_NUMBER)[0].buildNumber) { `
throw "There are newer queued builds for this pull request, failing early." }
# Download most recent Julia Windows binary
- ps: (new-object net.webclient).DownloadFile(
$env:JULIA_URL,
"C:\projects\julia-binary.exe")
# Run installer silently, output to C:\projects\julia
- C:\projects\julia-binary.exe /S /D=C:\projects\julia
- ps: iex ((new-object net.webclient).DownloadString("https://raw.githubusercontent.com/JuliaCI/Appveyor.jl/version-1/bin/install.ps1"))

build_script:
# Need to convert from shallow to complete for Pkg.clone to work
- IF EXIST .git\shallow (git fetch --unshallow)
- C:\projects\julia\bin\julia -e "versioninfo();
Pkg.clone(pwd(), \"Fatou\"); Pkg.build(\"Fatou\")"
- echo "%JL_BUILD_SCRIPT%"
- C:\julia\bin\julia -e "%JL_BUILD_SCRIPT%"

test_script:
- C:\projects\julia\bin\julia -e "Pkg.test(\"Fatou\")"
- echo "%JL_TEST_SCRIPT%"
- C:\julia\bin\julia -e "%JL_TEST_SCRIPT%"

# # Uncomment to support code coverage upload. Should only be enabled for packages
# # which would have coverage gaps without running on Windows
# on_success:
# - echo "%JL_CODECOV_SCRIPT%"
# - C:\julia\bin\julia -e "%JL_CODECOV_SCRIPT%"
35 changes: 6 additions & 29 deletions src/Fatou.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module Fatou
using SyntaxTree,Reduce,PyPlot,Base.Threads
using SyntaxTree,Reduce,LaTeXStrings,Requires,Base.Threads

# This file is part of Fatou.jl. It is licensed under the MIT license
# Copyright (C) 2017 Michael Reed
Expand Down Expand Up @@ -229,7 +229,7 @@ function newton(E;
end

# load additional functionality
include("internals.jl"); include("orbitplot.jl")
include("internals.jl")

"""
basin(::Fatou.Define, ::Integer)
Expand Down Expand Up @@ -275,33 +275,10 @@ function Compute(K::Define{FT,QT,CT,M,N})::Tuple{Matrix{UInt8},Matrix{Complex{Fl
return (matU,matF)
end

import PyPlot: plot

function plot(K::FilledSet;c::String="",bare::Bool=false)
# plot figure using imshow based in input preferences
figure()
isempty(c) && (c = K.meta.cmap)
isempty(c) ? imshow(K.meta.iter ? K.iter : K.mix, extent=K.meta.∂) :
imshow(K.meta.iter ? K.iter : K.mix, cmap=c, extent=K.meta.∂)
tight_layout()
if !bare
# determine if plot is Iteration, Roots, or Limit
typeof(K.meta.iter ? K.iter : K.mix) == Matrix{UInt8} ? t = L"iter. " :
K.meta.m==1 ? t = L"roots" : t = L"limit"
# annotate title using LaTeX
ttext = "f:z\\mapsto $(rdpm(Algebra.latex(K.meta.E))),\\,"
if K.meta.newt
title(latexstring("$ttext m = $(K.meta.m), ")*t)
# annotate y-axis with Newton's method
ylabel(L"Fatou\,set:\,"*L"z\,\,z-m\,×\,f(z)\,/\,f\,'(z)")
else
title(latexstring(ttext)*t)
end
tight_layout()
colorbar()
end
function __init__()
println("Fatou detected $(Threads.nthreads()) julia threads.")
@require PyPlot="d330b81b-6aea-500a-939a-2ce795aea3ee" include("pyplot.jl")
@require ImageInTerminal="d8c32880-2388-543b-8c61-d9f865259254" include("term.jl")
end

println("Fatou detected $(Threads.nthreads()) julia threads.")

end # module
2 changes: 1 addition & 1 deletion src/orbitplot.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Plot funciton compositions of the primary `Fatou.Define` function up to any `dep
julia> juliafill("z^2-0.67",∂=[-1.25,1.5],x0=1.25,orbit=17,depth=3) |> orbit
```
"""
function orbit(K::Define)
function orbit(K::Define{FT,QT,CT}) where {FT,QT,CT}
K.x0 == nothing ? (bi = K.∂[1:2]') : (bi = [K.∂[1:2]...,K.x0]')
orbit(K.E,z->K.F(z,0),convert(Array{Float64},bi),K.orbit,K.depth,Int(K.n))
end
Expand Down
32 changes: 32 additions & 0 deletions src/pyplot.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# This file is part of Fatou.jl. It is licensed under the MIT license
# Copyright (C) 2019 Michael Reed

using PyPlot
import PyPlot: plot

function plot(K::FilledSet;c::String="",bare::Bool=false)
# plot figure using imshow based in input preferences
figure()
isempty(c) && (c = K.meta.cmap)
isempty(c) ? PyPlot.imshow(K.meta.iter ? K.iter : K.mix, extent=K.meta.∂) :
PyPlot.imshow(K.meta.iter ? K.iter : K.mix, cmap=c, extent=K.meta.∂)
tight_layout()
if !bare
# determine if plot is Iteration, Roots, or Limit
typeof(K.meta.iter ? K.iter : K.mix) == Matrix{UInt8} ? t = L"iter. " :
K.meta.m==1 ? t = L"roots" : t = L"limit"
# annotate title using LaTeX
ttext = "f:z\\mapsto $(rdpm(Algebra.latex(K.meta.E))),\\,"
if K.meta.newt
title(latexstring("$ttext m = $(K.meta.m), ")*t)
# annotate y-axis with Newton's method
ylabel(L"Fatou\,set:\,"*L"z\,\,z-m\,×\,f(z)\,/\,f\,'(z)")
else
title(latexstring(ttext)*t)
end
tight_layout()
colorbar()
end
end

include("orbitplot.jl")
35 changes: 35 additions & 0 deletions src/term.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# This file is part of Fatou.jl. It is licensed under the MIT license
# Copyright (C) 2019 Michael Reed

using ImageInTerminal, ColorSchemes

function Base.show(io::IO,K::FilledSet;c::String="",bare::Bool=false)
# plot figure using imshow based in input preferences
isempty(c) && (c = K.meta.cmap)
S = size(K.iter)
H = zeros(ColorSchemes.RGB{Float64},S...)
C = getproperty(ColorSchemes, isempty(c) ? :balance : Symbol(c))
if K.meta.iter
for x 1:S[1], y 1:S[2]
H[x,y] = C[K.iter[x,y]]
end
else
for x 1:S[1], y 1:S[2]
H[x,y] = get(C,K.mix[x,y])
end
end
display(H)
if !bare
# determine if plot is Iteration, Roots, or Limit
typeof(K.meta.iter ? K.iter : K.mix) == Matrix{UInt8} ? t = "iter. " :
K.meta.m==1 ? t = "roots" : t = "limit"
# annotate title using LaTeX
ttext = "f : z ↦ $(K.meta.E), "
if K.meta.newt
print("$ttext m = $(K.meta.m), ",t)
else
print(ttext,t)
end
end
end

19 changes: 9 additions & 10 deletions test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
using Reduce,Fatou
using Fatou
using SyntaxTree
using LaTeXStrings
using PyPlot
using Test

load_package(:rlfi)
@test orbit(newton(:(z^3-1))) == nothing
@test orbit(:(1*x),x->x, [-1.7 2π -1.2],17,3,147) == nothing
@test orbit(:(1*x),x->x, [-1.7 2π -1.2],0,1) == nothing
Fatou.Reduce.load_package(:rlfi)
@test newton(:(z^3-1)) |> typeof <: Fatou.Define
#@test orbit(:(1*x),x->x, [-1.7 2π -1.2],17,3,147) == nothing
#@test orbit(:(1*x),x->x, [-1.7 2π -1.2],0,1) == nothing
@test basin(juliafill(:(z^3-1)),1) |> typeof == LaTeXStrings.LaTeXString
@test basin(newton(:(z^3-1)),1) |> typeof == LaTeXStrings.LaTeXString
@test (f=newton(:(z^3-1))|>fatou; plot(f) |> typeof == PyPlot.PyObject)
@test (f=mandelbrot(:(z^2+c))|>fatou ; plot(f) |> typeof == PyPlot.PyObject)
@test (f=juliafill(:(z^2-0.06+0.67im))|>fatou ; plot(f) |> typeof == PyPlot.PyObject)
@test= Fatou.newton_raphson(:(z^3-1),1); ξ = genfun(η,[:z,:c]); ζ = 2.1; [ξ(ζ,0), [Fatou.recomp(η,ζ,k) for k 2:3]...]) |> typeof <: Array
@test newton(:(z^3-1)) |> fatou |> typeof <: Fatou.FilledSet
@test mandelbrot(:(z^2+c)) |> fatou |> typeof <: Fatou.FilledSet
@test juliafill(:(z^2-0.06+0.67im)) |> fatou |> typeof <: Fatou.FilledSet
#@test (η = Fatou.newton_raphson(:(z^3-1),1); ξ = genfun(η,[:z,:c]); ζ = 2.1; [ξ(ζ,0), [Fatou.recomp(η,ζ,k) for k ∈ 2:3]...]) |> typeof <: Array
# fix for case k ∈ 2:4+

0 comments on commit 86e2c37

Please sign in to comment.