1
1
# AxisArrays
2
2
3
- [ ![ Build Status] ( https://travis-ci.org/JuliaArrays/AxisArrays.jl.svg?branch=master )] ( https://travis-ci.org/JuliaArrays/AxisArrays.jl ) [ ![ Coverage Status] ( https://coveralls.io/repos/JuliaArrays/AxisArrays.jl/badge.svg?branch=master )] ( https://coveralls.io/r /JuliaArrays/AxisArrays.jl?branch=master )
3
+ [ ![ Build Status] ( https://travis-ci.org/JuliaArrays/AxisArrays.jl.svg?branch=master )] ( https://travis-ci.org/JuliaArrays/AxisArrays.jl ) [ ![ Coverage Status] ( https://coveralls.io/repos/github/ JuliaArrays/AxisArrays.jl/badge.svg?branch=master )] ( https://coveralls.io/github /JuliaArrays/AxisArrays.jl?branch=master )
4
4
5
5
This package for the Julia language provides an array type (the ` AxisArray ` ) that knows about its dimension names and axis values.
6
6
This allows for indexing with the axis name without incurring any runtime overhead.
@@ -13,14 +13,14 @@ Collaboration is welcome! This is still a work-in-progress. See [the roadmap](ht
13
13
## Example of currently-implemented behavior:
14
14
15
15
``` julia
16
- julia> Pkg. clone ( " https://github.com/JuliaArrays/ AxisArrays.jl " )
17
- using AxisArrays, SIUnits
18
- import SIUnits . ShortUnits : s, ms, µs
16
+ julia> Pkg. add ( " AxisArrays" )
17
+ using AxisArrays, Unitful
18
+ import Unitful : s, ms, µs
19
19
20
20
julia> fs = 40000 # Generate a 40kHz noisy signal, with spike-like stuff added for testing
21
21
y = randn (60 * fs+ 1 )* 3
22
- for spk = (sin (0.8 : 0.2 : 8.6 ) .* [0 : 0.01 : .1 ; .15 : .1 : .95 ; 1 : - .05 : .05 ] .* 50 ,
23
- sin (0.8 : 0.4 : 8.6 ) .* [0 : 0.02 : .1 ; .15 : .1 : 1 ; 1 : - .2 : .1 ] .* 50 )
22
+ for spk = (sin . (0.8 : 0.2 : 8.6 ) .* [0 : 0.01 : .1 ; .15 : .1 : .95 ; 1 : - .05 : .05 ] .* 50 ,
23
+ sin . (0.8 : 0.4 : 8.6 ) .* [0 : 0.02 : .1 ; .15 : .1 : 1 ; 1 : - .2 : .1 ] .* 50 )
24
24
i = rand (round (Int,.001 fs): 1 fs)
25
25
while i+ length (spk)- 1 < length (y)
26
26
y[i: i+ length (spk)- 1 ] += spk
@@ -54,16 +54,15 @@ indices in *any* order, just so long as we annotate them with the axis name:
54
54
55
55
``` jl
56
56
julia> A[Axis {:time} (4 )]
57
- 2 - dimensional AxisArray{Float64,2 ,... } with axes:
58
- :time , 7.5e-5 s: 2.5e-5 s: 7.5e-5 s
59
- :chan , [:c1 ,:c2 ]
60
- And data, a 1 x2 SubArray{Float64,2 ,Array{Float64,2 },Tuple{UnitRange{Int64},Colon},2 }:
57
+ 2 - dimensional AxisArray{Float64,1 ,... } with axes:
58
+ :chan , Symbol[:c1 ,:c2 ]
59
+ And data, a 2 - element Array{Float64,1 }:
61
60
- 1.4144 - 2.82879
62
61
63
62
julia> A[Axis {:chan} (:c2 ), Axis {:time} (1 : 5 )]
64
63
1 - dimensional AxisArray{Float64,1 ,... } with axes:
65
64
:time , 0.0 s: 2.5e-5 s: 0.0001 s
66
- And data, a 5 - element SubArray{Float64, 1 , Array{Float64,2 },Tuple{UnitRange{Int64},Int64}, 2 }:
65
+ And data, a 5 - element Array{Float64,1 }:
67
66
- 6.12181
68
67
0.304668
69
68
15.7366
@@ -80,7 +79,7 @@ still has the correct time information for those datapoints!
80
79
julia> A[40 µs .. 220 µs, :c1 ]
81
80
1 - dimensional AxisArray{Float64,1 ,... } with axes:
82
81
:time , 5.0e-5 s: 2.5e-5 s: 0.0002 s
83
- And data, a 7 - element SubArray{Float64, 1 , Array{Float64,2 },Tuple{UnitRange{Int64},Int64}, 2 }:
82
+ And data, a 7 - element Array{Float64,1 }:
84
83
7.86831
85
84
- 1.4144
86
85
- 2.02881
@@ -90,11 +89,26 @@ And data, a 7-element SubArray{Float64,1,Array{Float64,2},Tuple{UnitRange{Int64}
90
89
- 1.97716
91
90
92
91
julia> axes (ans, 1 )
93
- AxisArrays. Axis {:time,SIUnits.SIRange{FloatRange{Float64},Float64,0,0,1,0,0,0,0,0,0}} (5.0e-5 s: 2.5e-5 s: 0.0002 s)
92
+ 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)
93
+ ```
94
+
95
+ You can also index by a single value on an axis using ` atvalue ` . This will drop
96
+ a dimension. Indexing with an ` Interval ` type retains dimensions, even
97
+ when the ends of the interval are equal:
98
+
99
+ ``` jl
100
+ julia> A[atvalue (2.5e-5 s), :c1 ]
101
+ 0.152334
102
+
103
+ julia> A[2.5e-5 s.. 2.5e-5 s, :c1 ]
104
+ 1 - dimensional AxisArray{Float64,1 ,... } with axes:
105
+ :time , 2.5e-5 s: 2.5e-5 s: 2.5e-5 s
106
+ And data, a 1 - element Array{Float64,1 }:
107
+ 0.152334
94
108
```
95
109
96
110
Sometimes, though, what we're really interested in is a window of time about a
97
- specific index. The operation above (looking for values in the window from 40µs
111
+ specific index. One of the operations above (looking for values in the window from 40µs
98
112
to 220µs) might be more clearly expressed as a symmetrical window about a
99
113
specific index where we know something interesting happened. To represent this,
100
114
we use the ` atindex ` function:
@@ -125,7 +139,7 @@ julia> idxs = find(diff(A[:,:c1] .< -15) .> 0)
125
139
julia> spks = A[atindex (- 200 µs .. 800 µs, idxs), :c1 ]
126
140
2 - dimensional AxisArray{Float64,2 ,... } with axes:
127
141
:time_sub , - 0.000175 s: 2.5e-5 s: 0.000775 s
128
- :time_rep , SIUnits . SIQuantity {Float64,0 , 0 , 1 , 0 , 0 , 0 , 0 , 0 , 0 }[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]
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]
129
143
And data, a 39 x242 Array{Float64,2 }:
130
144
- 1.53038 4.72882 5.8706 … - 0.231564 0.624714 3.44076
131
145
- 2.24961 2.12414 5.69936 7.00179 2.30993 5.20432
0 commit comments