Skip to content

Commit

Permalink
Merge pull request #3 from JuliaArrays/bike-shed
Browse files Browse the repository at this point in the history
* is_time -> is_temporal: b/c the package is called SpatioTemporalTraits
* Removed direct reference to axes and keys for public functions. This comment worked on me for a while. The goal is to have sensible defaults that may be overloaded elsewhere. So it won't always make sense to have spatial_keys, but spatial_indices will make sense whether working with an array, plot, or mesh.
* All things should be inferable now.
* Given the conversation in Interop/testing #2, onset is now time_first and time_end was changed to time_last for symmetry. Also spatial_offset is now spatial_first. The short of the conversation is that the onset and offset are terms that may be interpreted differently depending on whether the first time point/spatial index coincide with the exact location of corresponding values or are off center from it as a reference.
* A very minimal set of metadata options are thrown in there right now. Mostly as a starting point and not a final design decision.
  • Loading branch information
Tokazama authored Sep 4, 2021
2 parents 938edb4 + c3dacc9 commit ddf44a8
Show file tree
Hide file tree
Showing 13 changed files with 342 additions and 580 deletions.
12 changes: 12 additions & 0 deletions .github/workflows/TagBot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
name: TagBot
on:
schedule:
- cron: 0 * * * *
jobs:
TagBot:
runs-on: ubuntu-latest
steps:
- uses: JuliaRegistries/TagBot@v1
with:
token: ${{ secrets.GITHUB_TOKEN }}
ssh: ${{ secrets.DOCUMENTER_KEY }}
42 changes: 42 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: CI
on:
- push
- pull_request
jobs:
test:
name: Julia ${{ matrix.version }} - ${{ matrix.os }} - ${{ matrix.arch }} - ${{ github.event_name }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
version:
- '1'
- 'nightly'
os:
- ubuntu-latest
- macOS-latest
- windows-latest
arch:
- x64
steps:
- uses: actions/checkout@v2
- uses: julia-actions/setup-julia@v1
with:
version: ${{ matrix.version }}
arch: ${{ matrix.arch }}
- uses: actions/cache@v1
env:
cache-name: cache-artifacts
with:
path: ~/.julia/artifacts
key: ${{ runner.os }}-test-${{ env.cache-name }}-${{ hashFiles('**/Project.toml') }}
restore-keys: |
${{ runner.os }}-test-${{ env.cache-name }}-
${{ runner.os }}-test-
${{ runner.os }}-
- uses: julia-actions/julia-buildpkg@v1
- uses: julia-actions/julia-runtest@v1
- uses: julia-actions/julia-processcoverage@v1
- uses: codecov/codecov-action@v1
with:
file: lcov.info
3 changes: 3 additions & 0 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,6 @@ version = "0.1.0"

[deps]
ArrayInterface = "4fba245c-0d91-5ea0-9b3e-6abc04ee57a9"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
Metadata = "4fb893c1-3164-4f58-823a-cb4c64eabb4f"
Static = "aedffcd0-7271-4cad-89d0-dc628f76c6d3"
55 changes: 20 additions & 35 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# SpatioTemporalTraits


[![Stable](https://img.shields.io/badge/docs-stable-blue.svg)](https://juliaarrays.github.io/SpatioTemporalTraits.jl/stable)
[![Dev](https://img.shields.io/badge/docs-dev-blue.svg)](https://juliaarrays.github.io/SpatioTemporalTraits.jl/dev)
[![CI](https://github.com/JuliaArrays/SpatioTemporalTraits.jl/workflows/CI/badge.svg)](https://github.com/JuliaArrays/SpatioTemporalTraits.jl/actions?query=workflow%3ACI)
[![CI (Julia nightly)](https://github.com/JuliaArrays/SpatioTemporalTraits.jl/workflows/CI%20(Julia%20nightly)/badge.svg)](https://github.com/JuliaArrays/SpatioTemporalTraits.jl/actions?query=workflow%3A%22CI+%28Julia+nightly%29%22)
[![Build status](https://badge.buildkite.com/a2db252d92478e1d7196ee7454004efdfb6ab59496cbac91a2.svg?branch=master)](https://buildkite.com/julialang/SpatioTemporalTraits-dot-jl)
[![codecov](https://codecov.io/gh/JuliaArrays/SpatioTemporalTraits.jl/branch/master/graph/badge.svg)](https://codecov.io/gh/JuliaArrays/SpatioTemporalTraits.jl)

# Warning

At the time of writing this, `SpatioTemporalTraits` is not tested on any specific array implementation.
Expand All @@ -10,7 +18,7 @@ They may still be informative for those developing code that wants to genericall

# Introduction

`SpatioTemporalTraits` provides spatial and temporal traits on top of [ArrayInterface.jl](https://github.com/SciML/ArrayInterface.jl).
`SpatioTemporalTraits` provides spatial and temporal traits on top of [ArrayInterface.jl](https://github.com/JuliaArrays/ArrayInterface.jl).
Types that use ArrayInterface.jl have inherent compatibility with methods that utilize `SpatioTemporalTraits`.
For example, the following method returns `x` if it's last dimension is a time dimension and otherwise permutes the last dimensions to be the time dimension.

Expand All @@ -30,8 +38,17 @@ end
```

By default the only dimensions that are considered "time dimensions" are those that return `:time` or `:Time` when `ArrayInterface.dimnames` is called (e.g., `ArrayInterface.dimnames(x::TimeMatrix) = (:observations, :time)` would return `2` when `timedim(x::TimeMatrix)` is called).
There may be instances you want to specify a different name refers to time, which is what `SpatioTemporalTraits.@is_time` is for.
For example, `SpatioTemporalTraits.@is_time :hammer_time` could be used for specifying a dimension of times that you "can't touch this".
Conversely, any all dimensions are considered spatial dimensions except for those with the names `:time` or `:Time`.
This can be changed by adding methods to `SpatioTemporalTraits.is_time` and `SpatioTemporalTraits.is_spatial`
For example, the "frequency" can be made a formal time dimension by doing the following:

```julia
using SpatioTemporalTraits
using Static

SpatioTemporalTraits.is_temporal(::Type{typeof(static(:frequency))}) = static(true)
SpatioTemporalTraits.is_spatial(::Type{typeof(static(:frequency))}) = static(false)
```

## Non-dependency compatibility with SpatioTemporalTraits

Expand All @@ -52,35 +69,3 @@ end

```

This is also true of packages that use `@defdim` to create new meaningful dimensions.
That is, methods using the interface provided by ArrayInterface should be compatible with any dimensions formally defined using the tools in this package.

## Defining new dimensions

We can create new meaningful dimensions using `@defdim`.
The first argument passed to `@defdim` is the suffix used for methods created (see the docstring for `@defdim` to get a full list of methods created).
The second argument is a method called when no dimension is found corresponding to the newly defined dimension.
In this instance an error is thrown when `x` doesn't have a dimension named `:observations` or `:obs`.
```julia
SpatioTemporalTraits.@defdim(
observations,
(x -> throw(ArgumentError("$x does not have a dimension corresponding to 'observations'")))
)

@is_observations :observations

@is_observations :obs
```
`@defdim` creates the `@is_observation` macro for formalizing which `Symbol` names should be considered observation dimensions.
This will internally assert that anything that refers to an observation is not spatial.
If we want to define a dimension that does refer to a spatial dimension we can do the following:
```julia
SpatioTemporalTraits.@defdim(
horizontal,
(x -> throw(ArgumentError("$x does not have a dimension corresponding to 'horizontal'"))),
true
)

@is_horizontal :horizontal
```

20 changes: 12 additions & 8 deletions src/SpatioTemporalTraits.jl
Original file line number Diff line number Diff line change
@@ -1,31 +1,35 @@
module SpatioTemporalTraits

using ArrayInterface
using ArrayInterface: False, True, StaticInt, StaticSymbol
using ArrayInterface: dimnames, has_dimnames, eachop, to_dims, static, nstatic
using ArrayInterface: dimnames, has_dimnames, to_dims, parent_type, to_parent_dims
using Metadata
using Metadata: MetaArray, NoMetadata
using Static
using Base: tail

using LinearAlgebra

export
assert_timedim_last,
duration,
each_time,
has_timedim,
ntimes,
onset,
origin,
pixel_spacing,
sampling_rate,
select_time,
spatialdims,
spatial_order,
spatial_axes,
spatial_size,
spatial_keys,
spatial_offset,
spatial_indices,
spatial_first,
spatial_last,
spatial_directions,
timedim,
times,
time_axis,
time_end,
time_first,
time_last,
time_step

include("spatial.jl")
Expand Down
Loading

0 comments on commit ddf44a8

Please sign in to comment.