Giter Club home page Giter Club logo

juxta.jl's Introduction

juxta

Build Status Codecov

This package facilitates creation and manipulation of multi-dimensional labeled arrays. The eventual aim of this package is to emulate something similar to Xarray in python.

A container, JuxtArray, is provided. Only slicing is currently implemented.

Examples

Creation:

julia> ja = juxta.JuxtArray(randn(5,10), ["x","y"], Dict("x"=>collect(1:5),"y"=>collect(1:10)))
Dimensions  : ["x", "y"]
Array       : 5×10 Array{Float64,2}
Coordinates :
    x: 5-element Array{Number,1}
    y: 10-element Array{Number,1}
Attributes  : Dict{Any,Any}()

Index-based slicing:

julia> ja = juxta.JuxtArray(randn(5,10), ["x","y"], Dict("x"=>collect(1:5),"y"=>collect(1:10)))
Dimensions  : ["x", "y"]
Array       : 5×10 Array{Float64,2}
Coordinates :
    x: 5-element Array{Number,1}
    y: 10-element Array{Number,1}
Attributes  : Dict{Any,Any}()

julia> juxta.isel!(ja, x=2:4, y=3:7)
Dimensions  : ["x", "y"]
Array       : 3×5 Array{Float64,2}
Coordinates :
    x: 3-element Array{Number,1}
    y: 5-element Array{Number,1}
Attributes  : Dict{Any,Any}()

Indexing based on physical values of dimensions:

julia> ja = juxta.JuxtArray(randn(5,10), ["x","y"], Dict("x"=>collect(1:5),"y"=>collect(1:10) .* 2))
julia> juxta.sel!(ja, y=3.7:7.9)
Dimensions  : ["x", "y"]
Array       : 5×2 Array{Float64,2}
Coordinates :
    x: 5-element Array{Number,1}
    y: 2-element Array{Number,1}
Attributes  : Dict{Any,Any}()

This returns a subset where the dimension y ranges from 4:2:6.

julia> ja = juxta.JuxtArray(randn(5,10), ["x","y"], Dict("x"=>collect(1:5),"y"=>collect(1:10) .* 2))
julia> juxta.sel!(ja, "nearest", y=3.7:7.9)
Dimensions  : ["x", "y"]
Array       : 5×3 Array{Float64,2}
Coordinates :
    x: 5-element Array{Number,1}
    y: 3-element Array{Number,1}
Attributes  : Dict{Any,Any}()

This returns a subset where the dimension y ranges from 4:2:8.

julia> ja = juxta.JuxtArray(randn(5,10), ["x","y"], Dict("x"=>collect(1:5),"y"=>collect(1:10) .* 2))
julia> juxta.sel!(ja, y=3.7)
Dimensions  : ["x", "y"]
Array       : 5×2 Array{Float64,2}
Coordinates :
    x: 5-element Array{Number,1}
    y: 2-element Array{Number,1}
Attributes  : Dict{Any,Any}()

This returns a subset where the dimension y ranges from 2:2:4.

julia> ja = juxta.JuxtArray(randn(5,10), ["x","y"], Dict("x"=>collect(1:5),"y"=>collect(1:10) .* 2))
julia> juxta.sel!(ja, "nearest", y=3.7)
Dimensions  : ["x", "y"]
Array       : 5×1 Array{Float64,2}
Coordinates :
    x: 5-element Array{Number,1}
    y: 1-element Array{Number,1}
Attributes  : Dict{Any,Any}()

This returns a subset where the dimension y ranges from 4:4.

Dropping singleton dimensions:

julia> ja = juxta.JuxtArray(randn(5,10), ["x","y"], Dict("x"=>collect(1:5),"y"=>collect(1:10) .* 2))
julia> ja = juxta.sel!(ja, "nearest", x=0.8)
julia> ja = dropdims(ja, ["x"])
Dimensions  : ["y"]
Array       : 10-element Array{Float64,1}
Coordinates :
    x: 1-element Array{Number,1}
    y: 10-element Array{Number,1}
Attributes  : Dict{Any,Any}()

All of the above operations can be combined using Julia's piping functionality:

julia> ja = juxta.JuxtArray(randn(5,10,1), ["x","y","za"],
                     Dict("x"=>collect(1:5),"y"=>collect(1:10) .* 2,"za"=>[2]))
julia> ja = (ja
               |> j->juxta.isel!(j,x=2)
               |> j->dropdims(j,["x","za"])
               |> j->size(j))
(10,)

or by using Pipe.jl:

julia> using Pipe
julia> ja = juxta.JuxtArray(randn(5,10,1), ["x","y","za"],
                     Dict("x"=>collect(1:5),"y"=>collect(1:10) .* 2,"za"=>[2]))
julia> ja = @pipe (ja
                     |> juxta.isel!(_,x=2)
                     |> dropdims(_,["x","za"])
                     |> size(_))
(10,)

or by using Lazy.jl:

julia> using Lazy
julia> ja = juxta.JuxtArray(randn(5,10,1), ["x","y","za"],
                     Dict("x"=>collect(1:5),"y"=>collect(1:10) .* 2,"za"=>[2]))
julia> ja = @> ja juxta.isel!(x=2) dropdims(["x","za"]) size()
(10,)

TODO

  • Test with datetime dimensions
  • Implement plotting

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.