Skip to content

Commit a70d197

Browse files
authored
Merge pull request #17 from emsig/dev_julia
Dev julia
2 parents 2e59b12 + fd360d7 commit a70d197

File tree

6 files changed

+238
-3
lines changed

6 files changed

+238
-3
lines changed

.github/workflows/julia_deploy.yml

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
name: julia-deploy
2+
3+
on:
4+
pull_request:
5+
push:
6+
branches:
7+
- main
8+
release:
9+
types:
10+
- published
11+
12+
defaults:
13+
run:
14+
shell: bash
15+
16+
jobs:
17+
# test:
18+
deploy:
19+
name: Deploy to package-julia
20+
runs-on: ubuntu-latest
21+
22+
steps:
23+
- name: Checkout
24+
uses: actions/checkout@v2
25+
with:
26+
fetch-depth: 100
27+
persist-credentials: false
28+
- name: Fetch git tags
29+
run: git fetch origin 'refs/tags/*:refs/tags/*'
30+
- uses: julia-actions/setup-julia@v1
31+
with:
32+
version: '1.6'
33+
- name: Install dependencies
34+
run: julia -e 'import Pkg; Pkg.add("DataStructures"); Pkg.add("JSON")'
35+
- name: Create package
36+
run: |
37+
cd packages
38+
julia create_julia.jl
39+
- name: Deploy to packages-julia branch
40+
uses: s0/git-publish-subdir-action@develop
41+
if: success()
42+
env:
43+
REPO: self
44+
BRANCH: package-julia
45+
FOLDER: packages/julia
46+
MESSAGE: "@JuliaRegistrator register branch=package-julia"
47+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
48+

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
packages/python/
22
__pycache__
3+
packages/julia/
4+
.vscode/

README.md

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,26 @@ base, j0, j1 = libdlf.hankel.wer_201_2018()
6666
# TODO: Do actual transform with the filter.
6767
```
6868

69-
7069
### Julia
7170

72-
ToDo
71+
You can install `LibDLF` for Julia using:
72+
```julia
73+
import Pkg
74+
Pkg.add("LibDLF")
75+
```
76+
or
77+
```julia
78+
pkg> add LibDLF
79+
```
80+
The package is structured into transform types with each filter function nested beneath its type. Each filter returns its base
81+
and corresponding values as arrays:
82+
83+
```julia
84+
using LibDLF
85+
base, fcos, fsin = LibDLF.Fourier.key_201_2012()
7386

87+
# TODO: Do actual transform with the filter.
88+
```
7489

7590
### Matlab
7691

lib/Fourier/fourier_key_81_2009_sincos.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# 101 point Fourier filter, Sine and Cosine
1+
# 81 point Fourier filter, Sine and Cosine
22
# =========================================
33
#
44
# Designed and tested for controlled-source electromagnetic data.

packages/README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,18 @@ rm -rf python/
2828
```
2929

3030
(All commands are meant to be run within the `packages` directory.)
31+
32+
33+
# Julia
34+
35+
The Julia package `LibDLF` is created by running
36+
37+
```bash
38+
julia create_julia.jl
39+
```
40+
41+
The build requires packages `DataStructures` and `JSON`.
42+
43+
Packages `DelimitedFiles` and `Memoization` are required to use the `LibDLF` package.
44+
45+
(All commands are meant to be run within the `packages` directory.)

packages/create_julia.jl

Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
using DataStructures
2+
import JSON
3+
4+
# Create package directories
5+
mkpath("julia/src")
6+
mkpath("julia/test")
7+
8+
# Copy library to Julia package
9+
cp(abspath("../lib"),abspath("julia/src/lib"),force=true)
10+
11+
# Copy README and LICENSE
12+
cp("../README.md", "julia/README.md",force=true)
13+
cp("../LICENSE", "julia/LICENSE",force=true)
14+
15+
# Get current version number in git:
16+
version = split(read(`git describe --tags`,String),"-")[1][2:end]
17+
18+
# Create Project.toml
19+
iop = open(abspath("julia/Project.toml"), "w")
20+
println(iop,"name = \"LibDLF\"")
21+
println(iop,"uuid = \"f0c3f387-4ff6-435f-9d63-77e28b8d1347\"")
22+
println(iop,"authors = [\"The emsig community <info@emsig.xyz> \"]")
23+
println(iop,"version = \"$version\"") #kwk debug: how to get version in github build?
24+
println(iop,"\n[deps]")
25+
println(iop,"DelimitedFiles = \"8bb1440f-4735-579b-a4ab-409b98df4dab\"")
26+
println(iop,"\n[extras]")
27+
println(iop,"Test = \"8dfed614-e22c-5e08-85e1-65c5234f0b40\"")
28+
println(iop,"\n[targets]")
29+
println(iop,"test = [\"Test\"]")
30+
close(iop)
31+
32+
# Read in .json file listing all filters
33+
filters = JSON.parsefile(abspath("julia/src/lib/filters.json"),
34+
dicttype=DataStructures.OrderedDict)
35+
36+
# Create Julia module
37+
iol = open(abspath("julia/src/LibDLF.jl"), "w")
38+
39+
# Module name
40+
println(iol,"module LibDLF\n")
41+
42+
# Create LibDLF.jl files
43+
for type in filters.keys
44+
45+
stype = titlecase(type)
46+
47+
# Include sub module file in parent
48+
println(iol, "include(\"$stype.jl\")")
49+
50+
# Create sub module file for filter type
51+
iot = open(abspath("julia/src/$stype.jl"), "w")
52+
53+
println(iot, "module $stype\n")
54+
55+
# Add used modules
56+
println(iot, "using DelimitedFiles")
57+
58+
# Add library path variable:
59+
println(iot, "\nlibpath = @__DIR__")
60+
61+
# Add cache:
62+
println(iot, "\ncache = Dict() # local cache for any filters already loaded")
63+
64+
# Add filter functions:
65+
for filt in filters[type]
66+
67+
# Get and write header as docstring:
68+
iof = open(abspath("julia/src/" * filt["file"]), "r")
69+
70+
# Title
71+
println(iot, "\n\"\"\"")
72+
73+
sname = filt["name"]
74+
println(iot, "\t $sname()\n")
75+
76+
println(iot, readline(iof)[2:end])
77+
78+
# Get vals and preformat if sin & cos
79+
vals = replace(filt["values"], "," => ", ")
80+
# println(typeof(vals))
81+
if type == "fourier"
82+
vals = replace(vals, "cos" => "fcos")
83+
vals = replace(vals, "sin" => "fsin")
84+
end
85+
86+
# Rest of header
87+
for line in eachline(iof)
88+
89+
# Do not copy the title-underline; just newline
90+
if contains(line, "========")
91+
println(iot, "")
92+
93+
# Empty lines: only remove comment
94+
elseif line == "#\n"
95+
println(iot, "")
96+
97+
# The license is the last thing of the header
98+
elseif contains(line, "This file is part of libdlf")
99+
100+
# Add returned vals
101+
println(iot, "# Returns\n")
102+
println(iot, "base, $vals :: Array{Float64,1}")
103+
println(iot, "Filter base and its values.\n")
104+
105+
# Example
106+
println(iot, "# Example\n")
107+
println(iot, "```julia")
108+
println(iot, "base, $vals = LibDLF.$stype.$sname()")
109+
println(iot, "```")
110+
111+
# Finish header
112+
println(iot, "\n\"\"\"")
113+
114+
# Stop header loop
115+
break
116+
117+
# Print entire line
118+
else
119+
println(iot, line[2:end])
120+
121+
end
122+
123+
end
124+
125+
println(iot, "function $sname()")
126+
127+
println(iot,"\tif !haskey(cache,\"$sname\") # read and add to cache")
128+
sfile = filt["file"]
129+
println(iot,"\t\tsfile = joinpath(libpath,\"$sfile\")")
130+
println(iot, "\t\tdat = readdlm(sfile,comments=true)")
131+
println(iot,"\t\tcache[\"$sname\"]= tuple([dat[:,c] for c in 1:size(dat,2)]...)")
132+
println(iot, "\tend")
133+
println(iot, "\treturn cache[\"$sname\"]")
134+
println(iot, "end")
135+
136+
# Close file
137+
close(iof)
138+
139+
end
140+
141+
# Close filter type sub module:
142+
println(iot, "\nend")
143+
close(iot)
144+
end
145+
146+
# Close LibDLF module:
147+
println(iol,"\nend")
148+
close(iol)
149+
150+
# Create testing routine
151+
ior = open(abspath("julia/test/runtests.jl"), "w")
152+
println(ior,"using LibDLF")
153+
println(ior,"using Test\n")
154+
println(ior,"# insert code for @testset blocks and @test unit tests ")
155+
close(ior)

0 commit comments

Comments
 (0)