Skip to content

Commit

Permalink
Add some more documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
Tokazama committed Jun 18, 2020
1 parent 043f9c2 commit 1234e44
Show file tree
Hide file tree
Showing 4 changed files with 101 additions and 13 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "TimeAxes"
uuid = "9a9fc9a6-283d-47e9-a2f6-b3a44e559ea3"
authors = ["Zachary P. Christensen <[email protected]>"]
version = "0.1.1"
version = "0.2.0"

[deps]
AxisIndices = "f52c9ee2-1b1c-4fd8-8546-6350938c7f11"
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

[![Build Status](https://travis-ci.com/Tokazama/TimeAxes.jl.svg?branch=master)](https://travis-ci.com/Tokazama/TimeAxes.jl)
[![codecov](https://codecov.io/gh/Tokazama/TimeAxes.jl/branch/master/graph/badge.svg)](https://codecov.io/gh/Tokazama/TimeAxes.jl)
[![stable-docs](https://img.shields.io/badge/docs-stable-blue.svg)](https://Tokazama.github.io/TimeAxes.jl/stable)
[![dev-docs](https://img.shields.io/badge/docs-dev-blue.svg)](https://Tokazama.github.io/TimeAxes.jl/dev)

This package utilizes AxisIndices to interface with data that has a time axis.

Expand Down
79 changes: 78 additions & 1 deletion docs/src/index.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,88 @@
# TimeAxes

```@doc
TimeAxes
```

## Examples

A simple array with a time dimension time units along the axis.
```jldoctest doc_examples
julia> using TimeAxes
julia> using Unitful: s
julia> A = NamedAxisArray{(:time,)}(collect(1:100), (1:100)s);
```

### Iteration

One could use the time axis for iteration...
```jldoctest doc_examples
julia> sum([A[i] for i in axes(A, 1)])
5050
```


...or windows of the time axis.
```jldoctest doc_examples
julia> A2 = sum([A[i] for i in AxisIterator(axes(A, 1), 10)])
10-element NamedAxisArray{Int64,1}
• time - 1 s:1 s:10 s
1 s 460
2 s 470
3 s 480
4 s 490
5 s 500
6 s 510
7 s 520
8 s 530
9 s 540
10 s 550
```

Some other basic functions related to time data are also available.
```jldoctest doc_examples
julia> lag(A2, 1)
9-element NamedAxisArray{Int64,1}
• time - 2 s:1 s:10 s
2 s 460
3 s 470
4 s 480
5 s 490
6 s 500
7 s 510
8 s 520
9 s 530
10 s 540
julia> lead(A2, 1)
9-element NamedAxisArray{Int64,1}
• time - 1 s:1 s:9 s
1 s 470
2 s 480
3 s 490
4 s 500
5 s 510
6 s 520
7 s 530
8 s 540
9 s 550
```

More time specific methods may be found in the [References](#References)


## API
## References

```@autodocs
Modules = [TimeAxes]
Order = [:type, :function]
```
31 changes: 20 additions & 11 deletions src/timedim.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,26 @@ First time point along the time axis.
"""
onset(x) = first(time_keys(x))

"""
time_step(x)
The time step/interval between each element.
"""
time_step(x) = step(time_keys(x))

"""
duration(x)
Duration of the event along the time axis.
"""
function duration(x)
out = time_end(x) - onset(x)
return out + oneunit(out)
end
duration(x) = time_end(x) - onset(x) + time_step(x)

"""
sampling_rate(x)
Number of samples per second.
"""
sampling_rate(x) = 1 / step(time_keys(x))
sampling_rate(x) = 1 / time_step(x)

"""
assert_timedim_last(x)
Expand Down Expand Up @@ -63,8 +67,8 @@ julia> A = NamedAxisArray{(:time,)}(collect(1:5), (1:5)s)
5 s 5
julia> lead(A, 1)
4-element AxisArray{Int64,1}
dim_1 - 1 s:1 s:4 s
4-element NamedAxisArray{Int64,1}
time - 1 s:1 s:4 s
1 s 2
2 s 3
Expand Down Expand Up @@ -96,8 +100,8 @@ julia> A = NamedAxisArray{(:time,)}(collect(1:5), (1:5)s)
5 s 5
julia> lag(A, 1)
4-element AxisArray{Int64,1}
dim_1 - 2 s:1 s:5 s
4-element NamedAxisArray{Int64,1}
time - 2 s:1 s:5 s
2 s 1
3 s 2
Expand All @@ -112,7 +116,10 @@ lag(A::AbstractArray, n::Int) = _lag(A, timedim(A), n)
###
### lead
###
_lead(A::NamedAxisArray, dim::Int, n::Int)= _lead(parent(A), dim, n)
function _lead(A::NamedAxisArray, dim::Int, n::Int)
return NamedDimsArray{dimnames(A)}(_lead(parent(A), dim, n))
end

function _lead(A::AxisArray{T,N}, dim::Int, n::Int) where {T,N}
axs = axes(A)
p = parent(A)[_lead_indices(axs, dim, n)...]
Expand Down Expand Up @@ -159,7 +166,9 @@ end
###
### lags
###
_lag(A::NamedAxisArray, dim::Int, n::Int)= _lag(parent(A), dim, n)
function _lag(A::NamedAxisArray, dim::Int, n::Int)
return NamedDimsArray{dimnames(A)}(_lag(parent(A), dim, n))
end
function _lag(A::AxisArray{T,N}, dim::Int, n::Int) where {T,N}
axs = axes(A)
p = parent(A)[_lag_indices(axs, dim, n)...]
Expand Down

2 comments on commit 1234e44

@Tokazama
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator register

Release Notes:

  • Uses the latest version of AxisIndices.jl
  • new lead and lag functions
  • Beginning to get formal docs in place

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/16551

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.2.0 -m "<description of version>" 1234e44bc079f03b3c4dbf6884bf906d52946871
git push origin v0.2.0

Please sign in to comment.