Skip to content

Commit 0bb3285

Browse files
author
Michael Abbott
committed
a stab at the readme
1 parent c2f6f1f commit 0bb3285

File tree

1 file changed

+33
-22
lines changed

1 file changed

+33
-22
lines changed

README.md

+33-22
Original file line numberDiff line numberDiff line change
@@ -3,29 +3,41 @@
33
[![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)
44

55
This package for the Julia language provides an array type (the `AxisArray`) that knows about its dimension names and axis values.
6-
This allows for indexing with the axis name without incurring any runtime overhead.
7-
AxisArrays can also be indexed by the values of their axes, allowing column names or interval selections.
6+
This allows for indexing by name without incurring any runtime overhead.
87
This permits one to implement algorithms that are oblivious to the storage order of the underlying arrays.
8+
AxisArrays can also be indexed by the values along their axes, allowing column names or interval selections.
9+
910
In contrast to similar approaches in [Images.jl](https://github.com/timholy/Images.jl) and [NamedArrays.jl](https://github.com/davidavdav/NamedArrays), this allows for type-stable selection of dimensions and compile-time axis lookup. It is also better suited for regularly sampled axes, like samples over time.
1011

1112
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.
1213

13-
### Notice regarding `axes`
14+
### Note about `Axis{}` and keywords
15+
16+
An `AxisArray` stores an object of type `Axis{:name}` for each dimension,
17+
containing both the name (a `Symbol`) and the "axis values" (an `AbstractVector`).
18+
These types are what made compile-time lookup possible.
19+
Instead of providing them explicitly, it is now possible to use keyword arguments
20+
for both construction and indexing:
21+
22+
```julia
23+
V = AxisArray(rand(10); row='a':'j') # AxisArray(rand(10), Axis{:row}('a':'j'))
24+
V[row='c'] == V[Axis{:row}('c')] == V[row=3] == V[3]
25+
```
26+
27+
### Note about `axes()` and `indices()`
1428

15-
Since Julia version 0.7, the name `axes` is exported by default from `Base`
16-
with a meaning (and behavior) that is distinct from how AxisArrays has been
17-
using it. Since you cannot simultaneously be `using` the same name from the two
18-
different modules, Julia will issue a warning, and it'll error if you try to
19-
use `axes` without qualification:
29+
The function `AxisArrays.axes` returns the tuple of such `Axis` objects.
30+
Since Julia version 0.7, `Base.axes(V) == (1:10,)` gives instead the range of possible
31+
ordinary integer indices. (This was called `Base.indices`.) Since both names are exported,
32+
this collision results in a warning if you try to use `axes` without qualification:
2033

2134
```julia
22-
julia> axes([])
35+
julia> axes([1,2])
2336
WARNING: both AxisArrays and Base export "axes"; uses of it in module Main must be qualified
2437
ERROR: UndefVarError: axes not defined
2538
```
2639

27-
Packages that are upgrading to support 0.7+ and use AxisArrays should follow
28-
this upgrade path:
40+
Packages that are upgrading to support Julia 0.7+ should:
2941

3042
* Replace all uses of the `axes` function with the fully-qualified `AxisArrays.axes`
3143
* Replace all uses of the deprecated `indices` function with the un-qualified `axes`
@@ -38,14 +50,13 @@ path to whatever the new name will be.
3850
## Example of currently-implemented behavior:
3951

4052
```julia
41-
julia> using Pkg; Pkg.add("AxisArrays")
42-
julia> using AxisArrays, Unitful
43-
julia> import Unitful: s, ms, µs
44-
julia> using Random: MersenneTwister
53+
julia> using Pkg; pkg"add AxisArrays Unitful"
54+
julia> using AxisArrays, Unitful, Random
4555

46-
julia> rng = MersenneTwister(123) # Seed a random number generator for repeatable examples
47-
julia> fs = 40000 # Generate a 40kHz noisy signal, with spike-like stuff added for testing
48-
julia> y = randn(rng, 60*fs+1)*3
56+
julia> fs = 40000; # Generate a 40kHz noisy signal, with spike-like stuff added for testing
57+
julia> import Unitful: s, ms, µs
58+
julia> rng = Random.MersenneTwister(123); # Seed a random number generator for repeatable examples
59+
julia> y = randn(rng, 60*fs+1)*3;
4960
julia> for spk = (sin.(0.8:0.2:8.6) .* [0:0.01:.1; .15:.1:.95; 1:-.05:.05] .* 50,
5061
sin.(0.8:0.4:8.6) .* [0:0.02:.1; .15:.1:1; 1:-.2:.1] .* 50)
5162
i = rand(rng, round(Int,.001fs):1fs)
@@ -55,7 +66,7 @@ julia> for spk = (sin.(0.8:0.2:8.6) .* [0:0.01:.1; .15:.1:.95; 1:-.05:.05] .* 50
5566
end
5667
end
5768

58-
julia> A = AxisArray([y 2y], Axis{:time}(0s:1s/fs:60s), Axis{:chan}([:c1, :c2]))
69+
julia> A = AxisArray(hcat(y, 2 .* y); time = (0s:1s/fs:60s), chan = ([:c1, :c2]))
5970
2-dimensional AxisArray{Float64,2,...} with axes:
6071
:time, 0.0 s:2.5e-5 s:60.0 s
6172
:chan, Symbol[:c1, :c2]
@@ -87,14 +98,14 @@ information to enable all sorts of fancy behaviors. For example, we can specify
8798
indices in *any* order, just so long as we annotate them with the axis name:
8899

89100
```julia
90-
julia> A[Axis{:time}(4)]
101+
julia> A[time=4] # or A[Axis{:time}(4)]
91102
1-dimensional AxisArray{Float64,1,...} with axes:
92103
:chan, Symbol[:c1, :c2]
93104
And data, a 2-element Array{Float64,1}:
94105
1.37825
95106
2.75649
96107

97-
julia> A[Axis{:chan}(:c2), Axis{:time}(1:5)]
108+
julia> A[chan = :c2, time = 1:5] # or A[Axis{:chan}(:c2), Axis{:time}(1:5)]
98109
1-dimensional AxisArray{Float64,1,...} with axes:
99110
:time, 0.0 s:2.5e-5 s:0.0001 s
100111
And data, a 5-element Array{Float64,1}:
@@ -238,7 +249,7 @@ headers.
238249

239250
```julia
240251
B = AxisArray(reshape(1:15, 5, 3), .1:.1:0.5, [:a, :b, :c])
241-
B[Axis{:row}(0.2..0.4)] # restrict the AxisArray along the time axis
252+
B[row = (0.2..0.4)] # restrict the AxisArray along the time axis
242253
B[0.0..0.3, [:a, :c]] # select an interval and two of the columns
243254
```
244255

0 commit comments

Comments
 (0)