Skip to content

Commit 989cc1d

Browse files
committed
Share doctest environment
1 parent 6d78d9e commit 989cc1d

File tree

1 file changed

+21
-31
lines changed

1 file changed

+21
-31
lines changed

docs/src/index.md

Lines changed: 21 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,3 @@
1-
```@meta
2-
DocTestSetup = quote
3-
using AxisArrays, Unitful, Random
4-
import Unitful: s, ms, µs
5-
rng = MersenneTwister(123)
6-
fs = 40000
7-
y = randn(rng, 60*fs+1)*3
8-
for spk = (sin.(0.8:0.2:8.6) .* [0:0.01:.1; .15:.1:.95; 1:-.05:.05] .* 50,
9-
sin.(0.8:0.4:8.6) .* [0:0.02:.1; .15:.1:1; 1:-.2:.1] .* 50)
10-
i = rand(rng, round(Int,.001fs):1fs)
11-
while i+length(spk)-1 < length(y)
12-
y[i:i+length(spk)-1] += spk
13-
i += rand(rng, round(Int,.001fs):1fs)
14-
end
15-
end
16-
A = AxisArray([y 2y], Axis{:time}(0s:1s/fs:60s), Axis{:chan}([:c1, :c2]))
17-
end
18-
```
19-
201
# AxisArrays
212

223
[![Build Status](https://travis-ci.org/JuliaArrays/AxisArrays.jl.svg?branch=master)](https://travis-ci.org/JuliaArrays/AxisArrays.jl)
@@ -30,16 +11,25 @@ In contrast to similar approaches in [Images.jl](https://github.com/timholy/Imag
3011

3112
Collaboration is welcome! This is still a work-in-progress. See [the roadmap](https://github.com/JuliaArrays/AxisArrays.jl/issues/7) for the project's current direction.
3213

14+
## Installation
15+
From the Julia REPL, type
16+
```julia-repl
17+
julia> import Pkg; Pkg.add("AxisArrays")
18+
```
19+
3320
## Example of currently-implemented behavior:
3421

35-
```julia-repl
36-
julia> Pkg.add("AxisArrays")
22+
```jldoctest index
3723
julia> using AxisArrays, Unitful, Random
24+
3825
julia> import Unitful: s, ms, µs
3926
40-
julia> rng = MersenneTwister(123) # Seed a random number generator for repeatable examples
41-
julia> fs = 40000 # Generate a 40kHz noisy signal, with spike-like stuff added for testing
42-
julia> y = randn(rng, 60*fs+1)*3
27+
julia> rng = MersenneTwister(123); # Seed a random number generator for repeatable examples
28+
29+
julia> fs = 40000; # Generate a 40kHz noisy signal, with spike-like stuff added for testing
30+
31+
julia> y = randn(rng, 60*fs+1)*3;
32+
4333
julia> for spk = (sin.(0.8:0.2:8.6) .* [0:0.01:.1; .15:.1:.95; 1:-.05:.05] .* 50,
4434
sin.(0.8:0.4:8.6) .* [0:0.02:.1; .15:.1:1; 1:-.2:.1] .* 50)
4535
i = rand(rng, round(Int,.001fs):1fs)
@@ -50,7 +40,7 @@ julia> for spk = (sin.(0.8:0.2:8.6) .* [0:0.01:.1; .15:.1:.95; 1:-.05:.05] .* 50
5040
end
5141
```
5242

53-
```jldoctest
43+
```jldoctest index
5444
julia> A = AxisArray([y 2y], Axis{:time}(0s:1s/fs:60s), Axis{:chan}([:c1, :c2]))
5545
2-dimensional AxisArray{Float64,2,...} with axes:
5646
:time, (0.0:2.5e-5:60.0) s
@@ -83,7 +73,7 @@ AxisArrays behave like regular arrays, but they additionally use the axis
8373
information to enable all sorts of fancy behaviors. For example, we can specify
8474
indices in *any* order, just so long as we annotate them with the axis name:
8575

86-
```jldoctest
76+
```jldoctest index
8777
julia> A[Axis{:time}(4)]
8878
1-dimensional AxisArray{Float64,1,...} with axes:
8979
:chan, [:c1, :c2]
@@ -108,7 +98,7 @@ selects all values between two endpoints `a .. b` or the axis values directly.
10898
Notice that the returned AxisArray still has axis information itself... and it
10999
still has the correct time information for those datapoints!
110100

111-
```jldoctest
101+
```jldoctest index
112102
julia> A[40µs .. 220µs, :c1]
113103
1-dimensional AxisArray{Float64,1,...} with axes:
114104
:time, (5.0e-5:2.5e-5:0.0002) s
@@ -130,7 +120,7 @@ You can also index by a single value on an axis using `atvalue`. This will drop
130120
a dimension. Indexing with an `Interval` type retains dimensions, even
131121
when the ends of the interval are equal:
132122

133-
```jldoctest
123+
```jldoctest index
134124
julia> A[atvalue(2.5e-5s), :c1]
135125
-5.706943613190749
136126
@@ -144,7 +134,7 @@ And data, a 1-element Vector{Float64}:
144134

145135
You can even index by multiple values by broadcasting `atvalue` over an array:
146136

147-
```jldoctest
137+
```jldoctest index
148138
julia> A[atvalue.([2.5e-5s, 75.0µs])]
149139
2-dimensional AxisArray{Float64,2,...} with axes:
150140
:time, Quantity{Float64, 𝐓, Unitful.FreeUnits{(s,), 𝐓, nothing}}[2.5e-5 s, 7.5e-5 s]
@@ -161,7 +151,7 @@ to 220µs) might be more clearly expressed as a symmetrical window about a
161151
specific index where we know something interesting happened. To represent this,
162152
we use the `atindex` function:
163153

164-
```jldoctest
154+
```jldoctest index
165155
julia> A[atindex(-90µs .. 90µs, 5), :c2]
166156
1-dimensional AxisArray{Float64,1,...} with axes:
167157
:time_sub, (-7.5e-5:2.5e-5:7.500000000000002e-5) s
@@ -181,7 +171,7 @@ interval about the given index! This simple concept can be extended to some
181171
very powerful behaviors. For example, let's threshold our data and find windows
182172
about those threshold crossings.
183173

184-
```jldoctest
174+
```jldoctest index
185175
julia> idxs = findall(diff(A[:,:c1] .< -15) .> 0);
186176
187177
julia> spks = A[atindex(-200µs .. 800µs, idxs), :c1]

0 commit comments

Comments
 (0)