Skip to content

Commit 7bf90a9

Browse files
authored
Merge pull request #94 from ajkeller34/docsfix
Update docs
2 parents d5cdc14 + 198250c commit 7bf90a9

File tree

4 files changed

+189
-168
lines changed

4 files changed

+189
-168
lines changed

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ script:
1313
- if [[ -a .git/shallow ]]; then git fetch --unshallow; fi
1414
- julia --check-bounds=yes -e 'Pkg.clone(pwd()); Pkg.build("AxisArrays"); Pkg.test("AxisArrays"; coverage=true)'
1515
after_success:
16+
- julia -e 'Pkg.add("Unitful")'
1617
- julia -e 'cd(Pkg.dir("AxisArrays")); Pkg.add("Coverage"); using Coverage; Coveralls.submit(Coveralls.process_folder())'
1718
- julia -e 'Pkg.add("Documenter")'
1819
- julia -e 'cd(Pkg.dir("AxisArrays")); include(joinpath("docs", "make.jl"))'

README.md

Lines changed: 83 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -17,76 +17,85 @@ julia> Pkg.add("AxisArrays")
1717
using AxisArrays, Unitful
1818
import Unitful: s, ms, µs
1919

20-
julia> fs = 40000 # Generate a 40kHz noisy signal, with spike-like stuff added for testing
21-
y = randn(60*fs+1)*3
20+
julia> rng = MersenneTwister(123) # Seed a random number generator for repeatable examples
21+
fs = 40000 # Generate a 40kHz noisy signal, with spike-like stuff added for testing
22+
y = randn(rng, 60*fs+1)*3
2223
for spk = (sin.(0.8:0.2:8.6) .* [0:0.01:.1; .15:.1:.95; 1:-.05:.05] .* 50,
2324
sin.(0.8:0.4:8.6) .* [0:0.02:.1; .15:.1:1; 1:-.2:.1] .* 50)
24-
i = rand(round(Int,.001fs):1fs)
25+
i = rand(rng, round(Int,.001fs):1fs)
2526
while i+length(spk)-1 < length(y)
2627
y[i:i+length(spk)-1] += spk
27-
i += rand(round(Int,.001fs):1fs)
28+
i += rand(rng, round(Int,.001fs):1fs)
2829
end
2930
end
3031

3132
julia> A = AxisArray([y 2y], Axis{:time}(0s:1s/fs:60s), Axis{:chan}([:c1, :c2]))
3233
2-dimensional AxisArray{Float64,2,...} with axes:
3334
:time, 0.0 s:2.5e-5 s:60.0 s
34-
:chan, [:c1,:c2]
35-
And data, a 2400001x2 Array{Float64,2}:
36-
-3.06091 -6.12181
37-
0.152334 0.304668
38-
7.86831 15.7366
39-
-1.4144 -2.82879
40-
-2.02881 -4.05763
41-
9.87901 19.758
42-
43-
-0.0254444 -0.0508888
44-
0.204358 0.408717
45-
-4.80093 -9.60186
46-
5.39751 10.795
47-
0.976276 1.95255
48-
0.336558 0.673116
35+
:chan, Symbol[:c1, :c2]
36+
And data, a 2400001×2 Array{Float64,2}:
37+
3.5708 7.14161
38+
6.14454 12.2891
39+
3.42795 6.85591
40+
1.37825 2.75649
41+
-1.19004 -2.38007
42+
-1.99414 -3.98828
43+
2.9429 5.88581
44+
-0.226449 -0.452898
45+
0.821446 1.64289
46+
-0.582687 -1.16537
47+
48+
-3.50593 -7.01187
49+
2.26783 4.53565
50+
-0.16902 -0.33804
51+
-3.84852 -7.69703
52+
0.226457 0.452914
53+
0.560809 1.12162
54+
4.67663 9.35326
55+
-2.41005 -4.8201
56+
-3.71612 -7.43224
4957
```
5058

5159
AxisArrays behave like regular arrays, but they additionally use the axis
5260
information to enable all sorts of fancy behaviors. For example, we can specify
5361
indices in *any* order, just so long as we annotate them with the axis name:
5462

55-
```jl
63+
```julia
5664
julia> A[Axis{:time}(4)]
57-
2-dimensional AxisArray{Float64,1,...} with axes:
58-
:chan, Symbol[:c1,:c2]
65+
1-dimensional AxisArray{Float64,1,...} with axes:
66+
:chan, Symbol[:c1, :c2]
5967
And data, a 2-element Array{Float64,1}:
60-
-1.4144 -2.82879
68+
1.37825
69+
2.75649
6170

6271
julia> A[Axis{:chan}(:c2), Axis{:time}(1:5)]
6372
1-dimensional AxisArray{Float64,1,...} with axes:
6473
:time, 0.0 s:2.5e-5 s:0.0001 s
6574
And data, a 5-element Array{Float64,1}:
66-
-6.12181
67-
0.304668
68-
15.7366
69-
-2.82879
70-
-4.05763
75+
7.14161
76+
12.2891
77+
6.85591
78+
2.75649
79+
-2.38007
7180
```
7281

7382
We can also index by the *values* of each axis using an `Interval` type that
7483
selects all values between two endpoints `a .. b` or the axis values directly.
7584
Notice that the returned AxisArray still has axis information itself... and it
7685
still has the correct time information for those datapoints!
7786

78-
```jl
87+
```julia
7988
julia> A[40µs .. 220µs, :c1]
8089
1-dimensional AxisArray{Float64,1,...} with axes:
8190
:time, 5.0e-5 s:2.5e-5 s:0.0002 s
8291
And data, a 7-element Array{Float64,1}:
83-
7.86831
84-
-1.4144
85-
-2.02881
86-
9.87901
87-
0.463201
88-
2.49211
89-
-1.97716
92+
3.42795
93+
1.37825
94+
-1.19004
95+
-1.99414
96+
2.9429
97+
-0.226449
98+
0.821446
9099

91100
julia> axes(ans, 1)
92101
AxisArrays.Axis{:time,StepRangeLen{Quantity{Float64, Dimensions:{𝐓}, Units:{s}},Base.TwicePrecision{Quantity{Float64, Dimensions:{𝐓}, Units:{s}}},Base.TwicePrecision{Quantity{Float64, Dimensions:{𝐓}, Units:{s}}}}}(5.0e-5 s:2.5e-5 s:0.0002 s)
@@ -96,15 +105,15 @@ You can also index by a single value on an axis using `atvalue`. This will drop
96105
a dimension. Indexing with an `Interval` type retains dimensions, even
97106
when the ends of the interval are equal:
98107

99-
```jl
108+
```julia
100109
julia> A[atvalue(2.5e-5s), :c1]
101-
0.152334
110+
6.14453912336772
102111

103112
julia> A[2.5e-5s..2.5e-5s, :c1]
104113
1-dimensional AxisArray{Float64,1,...} with axes:
105114
:time, 2.5e-5 s:2.5e-5 s:2.5e-5 s
106115
And data, a 1-element Array{Float64,1}:
107-
0.152334
116+
6.14454
108117
```
109118

110119
Sometimes, though, what we're really interested in is a window of time about a
@@ -113,47 +122,53 @@ to 220µs) might be more clearly expressed as a symmetrical window about a
113122
specific index where we know something interesting happened. To represent this,
114123
we use the `atindex` function:
115124

116-
```jl
125+
```julia
117126
julia> A[atindex(-90µs .. 90µs, 5), :c2]
118127
1-dimensional AxisArray{Float64,1,...} with axes:
119-
:time_sub, -7.5e-5 s:2.5e-5 s:7.5e-5 s
120-
And data, a 7-element SubArray{Float64,1,Array{Float64,2},Tuple{AxisArrays.AxisArray{Int64,1,UnitRange{Int64},Tuple{AxisArrays.Axis{:sub,SIUnits.SIRange{FloatRange{Float64},Float64,0,0,1,0,0,0,0,0,0}}}},Int64},0}:
121-
15.7366
122-
-2.82879
123-
-4.05763
124-
19.758
125-
0.926402
126-
4.98423
127-
-3.95433
128+
:time_sub, -7.5e-5 s:2.5e-5 s:7.500000000000002e-5 s
129+
And data, a 7-element Array{Float64,1}:
130+
6.85591
131+
2.75649
132+
-2.38007
133+
-3.98828
134+
5.88581
135+
-0.452898
136+
1.64289
128137
```
129138

130139
Note that the returned AxisArray has its time axis shifted to represent the
131140
interval about the given index! This simple concept can be extended to some
132141
very powerful behaviors. For example, let's threshold our data and find windows
133142
about those threshold crossings.
134143

135-
```jl
136-
julia> idxs = find(diff(A[:,:c1] .< -15) .> 0)
137-
242-element Array{Int64,1}: ...
144+
```julia
145+
julia> idxs = find(diff(A[:,:c1] .< -15) .> 0);
138146

139147
julia> spks = A[atindex(-200µs .. 800µs, idxs), :c1]
140148
2-dimensional AxisArray{Float64,2,...} with axes:
141-
:time_sub, -0.000175 s:2.5e-5 s:0.000775 s
142-
:time_rep, Quantity{Float64, Dimensions:{𝐓}, Units:{s}}[0.178725 s,0.806825 s,0.88305 s,1.47485 s,1.50465 s,1.53805 s,1.541025 s,2.16365 s,2.368425 s,2.739 s 57.797925 s,57.924075 s,58.06075 s,58.215125 s,58.6403 s,58.96215 s,58.990225 s,59.001325 s,59.48395 s,59.611525 s]
143-
And data, a 39x242 Array{Float64,2}:
144-
-1.53038 4.72882 5.8706 -0.231564 0.624714 3.44076
145-
-2.24961 2.12414 5.69936 7.00179 2.30993 5.20432
146-
5.96311 3.9713 -4.38335 1.32617 -0.686648 0.443454
147-
3.86592 5.7466 2.32469 1.30803 3.44585 1.17781
148-
3.56837 -3.32178 1.16106 -3.91796 2.41779 -6.17495
149-
-9.52063 -2.07014 -1.18463 -3.55719 2.23117 1.76089
150-
151-
3.51708 -1.63627 0.281915 -2.41759 3.39403 0.101004
152-
0.0421772 -2.13557 -4.71965 0.066912 3.25141 -0.445574
153-
3.53238 -3.72221 1.68314 -4.15147 -5.25241 -1.77557
154-
-4.38307 1.38275 -1.33641 3.40342 0.272826 -3.22013
155-
2.54846 -0.0194032 2.58679 -0.000676503 -2.71147 -0.288483
156-
0.260694 -4.1724 -0.111377 3.283 1.77147 -0.367888
149+
:time_sub, -0.0002 s:2.5e-5 s:0.0008 s
150+
:time_rep, Quantity{Float64, Dimensions:{𝐓}, Units:{s}}[0.162 s, 0.20045 s, 0.28495 s, 0.530325 s, 0.821725 s, 1.0453 s, 1.11967 s, 1.1523 s, 1.22085 s, 1.6253 s 57.0094 s, 57.5818 s, 57.8716 s, 57.8806 s, 58.4353 s, 58.7041 s, 59.1015 s, 59.1783 s, 59.425 s, 59.5657 s]
151+
And data, a 41×247 Array{Float64,2}:
152+
0.672063 7.25649 0.633375 1.54583 5.81194 -4.706
153+
-1.65182 2.57487 0.477408 3.09505 3.52478 4.13037
154+
4.46035 2.11313 4.78372 1.23385 7.2525 3.57485
155+
5.25651 -2.19785 3.05933 0.965021 6.78414 5.94854
156+
7.8537 0.345008 0.960533 0.812989 0.336715 0.303909
157+
0.466816 0.643649 -3.67087 3.92978 -3.1242 0.789722
158+
-6.0445 -13.2441 -4.60716 0.265144 -4.50987 -8.84897
159+
-9.21703 -13.2254 -14.4409 -8.6664 -13.3457 -11.6213
160+
-16.1809 -22.7037 -25.023 -15.9376 -28.0817 -16.996
161+
-23.2671 -31.2021 -25.3787 -24.4914 -32.2599 -26.1118
162+
163+
-0.301629 0.0683982 -4.36574 1.92362 -5.12333 -3.4431
164+
4.7182 1.18615 4.40717 -4.51757 -8.64314 0.0800021
165+
-2.43775 -0.151882 -1.40817 -3.38555 -2.23418 0.728549
166+
3.2482 -0.60967 0.471288 2.53395 0.468817 -3.65905
167+
-4.26967 2.24747 -3.13758 1.74967 4.5052 -0.145357
168+
-0.752487 1.69446 -1.20491 1.71429 1.81936 0.290158
169+
4.64348 -3.94187 -1.59213 7.15428 -0.539748 4.82309
170+
1.09652 -2.66999 0.521931 -3.80528 1.70421 3.40583
171+
-0.94341 2.60785 -3.34291 1.10584 4.31118 3.6404
157172
```
158173

159174
By indexing with a repeated interval, we have *added* a dimension to the
@@ -165,21 +180,6 @@ labeled its dimensions appropriately. Not only is there the proper time
165180
base for each waveform, but we also have recorded the event times as the axis
166181
across the columns.
167182

168-
Now we can do a cursory clustering analysis on these spike snippets to separate
169-
the two "neurons" back out into their own groups with Clustering.jl, and plot
170-
using Gadfly.
171-
172-
```jl
173-
julia> using Clustering
174-
Ks = Clustering.kmeans(spks.data, 2);
175-
176-
julia> using Gadfly
177-
plot(spks, x=:time_sub, y=:data, group=:time_rep, color=DataFrames.RepeatedVector(Ks.assignments, size(spks, 1), 1), Geom.line)
178-
```
179-
180-
![clustered spike snippets](docs/spikes.png)
181-
182-
183183
## Indexing
184184

185185
### Indexing axes

docs/make.jl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,10 @@ using Documenter, AxisArrays
22

33
makedocs(
44
modules = [AxisArrays],
5-
doctest = false
65
)
76

87
deploydocs(
98
deps = Deps.pip("mkdocs", "python-markdown-math"),
109
repo = "github.com/JuliaArrays/AxisArrays.jl.git",
11-
julia = "0.5"
10+
julia = "0.6"
1211
)

0 commit comments

Comments
 (0)