Skip to content

Commit

Permalink
Merge pull request #17 from emsig/dev_julia
Browse files Browse the repository at this point in the history
Dev julia
  • Loading branch information
kerrykey committed Aug 17, 2021
2 parents 2e59b12 + fd360d7 commit a70d197
Show file tree
Hide file tree
Showing 6 changed files with 238 additions and 3 deletions.
48 changes: 48 additions & 0 deletions .github/workflows/julia_deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
name: julia-deploy

on:
pull_request:
push:
branches:
- main
release:
types:
- published

defaults:
run:
shell: bash

jobs:
# test:
deploy:
name: Deploy to package-julia
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v2
with:
fetch-depth: 100
persist-credentials: false
- name: Fetch git tags
run: git fetch origin 'refs/tags/*:refs/tags/*'
- uses: julia-actions/setup-julia@v1
with:
version: '1.6'
- name: Install dependencies
run: julia -e 'import Pkg; Pkg.add("DataStructures"); Pkg.add("JSON")'
- name: Create package
run: |
cd packages
julia create_julia.jl
- name: Deploy to packages-julia branch
uses: s0/git-publish-subdir-action@develop
if: success()
env:
REPO: self
BRANCH: package-julia
FOLDER: packages/julia
MESSAGE: "@JuliaRegistrator register branch=package-julia"
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
packages/python/
__pycache__
packages/julia/
.vscode/
19 changes: 17 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,26 @@ base, j0, j1 = libdlf.hankel.wer_201_2018()
# TODO: Do actual transform with the filter.
```


### Julia

ToDo
You can install `LibDLF` for Julia using:
```julia
import Pkg
Pkg.add("LibDLF")
```
or
```julia
pkg> add LibDLF
```
The package is structured into transform types with each filter function nested beneath its type. Each filter returns its base
and corresponding values as arrays:

```julia
using LibDLF
base, fcos, fsin = LibDLF.Fourier.key_201_2012()

# TODO: Do actual transform with the filter.
```

### Matlab

Expand Down
2 changes: 1 addition & 1 deletion lib/Fourier/fourier_key_81_2009_sincos.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# 101 point Fourier filter, Sine and Cosine
# 81 point Fourier filter, Sine and Cosine
# =========================================
#
# Designed and tested for controlled-source electromagnetic data.
Expand Down
15 changes: 15 additions & 0 deletions packages/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,18 @@ rm -rf python/
```

(All commands are meant to be run within the `packages` directory.)


# Julia

The Julia package `LibDLF` is created by running

```bash
julia create_julia.jl
```

The build requires packages `DataStructures` and `JSON`.

Packages `DelimitedFiles` and `Memoization` are required to use the `LibDLF` package.

(All commands are meant to be run within the `packages` directory.)
155 changes: 155 additions & 0 deletions packages/create_julia.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
using DataStructures
import JSON

# Create package directories
mkpath("julia/src")
mkpath("julia/test")

# Copy library to Julia package
cp(abspath("../lib"),abspath("julia/src/lib"),force=true)

# Copy README and LICENSE
cp("../README.md", "julia/README.md",force=true)
cp("../LICENSE", "julia/LICENSE",force=true)

# Get current version number in git:
version = split(read(`git describe --tags`,String),"-")[1][2:end]

# Create Project.toml
iop = open(abspath("julia/Project.toml"), "w")
println(iop,"name = \"LibDLF\"")
println(iop,"uuid = \"f0c3f387-4ff6-435f-9d63-77e28b8d1347\"")
println(iop,"authors = [\"The emsig community <[email protected]> \"]")
println(iop,"version = \"$version\"") #kwk debug: how to get version in github build?
println(iop,"\n[deps]")
println(iop,"DelimitedFiles = \"8bb1440f-4735-579b-a4ab-409b98df4dab\"")
println(iop,"\n[extras]")
println(iop,"Test = \"8dfed614-e22c-5e08-85e1-65c5234f0b40\"")
println(iop,"\n[targets]")
println(iop,"test = [\"Test\"]")
close(iop)

# Read in .json file listing all filters
filters = JSON.parsefile(abspath("julia/src/lib/filters.json"),
dicttype=DataStructures.OrderedDict)

# Create Julia module
iol = open(abspath("julia/src/LibDLF.jl"), "w")

# Module name
println(iol,"module LibDLF\n")

# Create LibDLF.jl files
for type in filters.keys

stype = titlecase(type)

# Include sub module file in parent
println(iol, "include(\"$stype.jl\")")

# Create sub module file for filter type
iot = open(abspath("julia/src/$stype.jl"), "w")

println(iot, "module $stype\n")

# Add used modules
println(iot, "using DelimitedFiles")

# Add library path variable:
println(iot, "\nlibpath = @__DIR__")

# Add cache:
println(iot, "\ncache = Dict() # local cache for any filters already loaded")

# Add filter functions:
for filt in filters[type]

# Get and write header as docstring:
iof = open(abspath("julia/src/" * filt["file"]), "r")

# Title
println(iot, "\n\"\"\"")

sname = filt["name"]
println(iot, "\t $sname()\n")

println(iot, readline(iof)[2:end])

# Get vals and preformat if sin & cos
vals = replace(filt["values"], "," => ", ")
# println(typeof(vals))
if type == "fourier"
vals = replace(vals, "cos" => "fcos")
vals = replace(vals, "sin" => "fsin")
end

# Rest of header
for line in eachline(iof)

# Do not copy the title-underline; just newline
if contains(line, "========")
println(iot, "")

# Empty lines: only remove comment
elseif line == "#\n"
println(iot, "")

# The license is the last thing of the header
elseif contains(line, "This file is part of libdlf")

# Add returned vals
println(iot, "# Returns\n")
println(iot, "base, $vals :: Array{Float64,1}")
println(iot, "Filter base and its values.\n")

# Example
println(iot, "# Example\n")
println(iot, "```julia")
println(iot, "base, $vals = LibDLF.$stype.$sname()")
println(iot, "```")

# Finish header
println(iot, "\n\"\"\"")

# Stop header loop
break

# Print entire line
else
println(iot, line[2:end])

end

end

println(iot, "function $sname()")

println(iot,"\tif !haskey(cache,\"$sname\") # read and add to cache")
sfile = filt["file"]
println(iot,"\t\tsfile = joinpath(libpath,\"$sfile\")")
println(iot, "\t\tdat = readdlm(sfile,comments=true)")
println(iot,"\t\tcache[\"$sname\"]= tuple([dat[:,c] for c in 1:size(dat,2)]...)")
println(iot, "\tend")
println(iot, "\treturn cache[\"$sname\"]")
println(iot, "end")

# Close file
close(iof)

end

# Close filter type sub module:
println(iot, "\nend")
close(iot)
end

# Close LibDLF module:
println(iol,"\nend")
close(iol)

# Create testing routine
ior = open(abspath("julia/test/runtests.jl"), "w")
println(ior,"using LibDLF")
println(ior,"using Test\n")
println(ior,"# insert code for @testset blocks and @test unit tests ")
close(ior)

0 comments on commit a70d197

Please sign in to comment.