Skip to content

Commit

Permalink
Merge pull request #27 from henry2004y/artifact
Browse files Browse the repository at this point in the history
Use artifact for test data
  • Loading branch information
henry2004y authored Sep 25, 2021
2 parents cb6b436 + 80406ec commit 1c81b71
Show file tree
Hide file tree
Showing 15 changed files with 55 additions and 677 deletions.
1 change: 1 addition & 0 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ on:
tags: '*'
paths-ignore:
- 'README.md'
- 'examples/**'
env:
JULIA_NUM_THREADS: 1
jobs:
Expand Down
7 changes: 7 additions & 0 deletions Artifacts.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[testdata]
git-tree-sha1 = "94103fd4bc493f5a2ddd9ec6ccd381cc07ebd7bf"
lazy = true

[[testdata.download]]
url = "https://github.com/henry2004y/batsrus_data/raw/master/batsrus_data.tar.gz"
sha256 = "a69460d2c73509aedbb833caa7bfad0cd2a8ddb75404c6c5765cd801b0891965"
5 changes: 3 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "Batsrus"
uuid = "e74ebddf-6ac1-4047-a0e5-c32c99e57753"
authors = ["Hongyang Zhou <[email protected]>"]
version = "0.3.9"
version = "0.3.10"

[deps]
Dierckx = "39dd38d3-220a-591b-8e3c-4c3a8c710a94"
Expand Down Expand Up @@ -30,8 +30,9 @@ WriteVTK = "1.9"
julia = "1.6"

[extras]
LazyArtifacts = "4af54fe1-eca0-43a8-85a7-787d91b784e3"
SHA = "ea8e919c-243c-51af-8825-aaa63cd721ce"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[targets]
test = ["Test", "SHA"]
test = ["Test", "LazyArtifacts", "SHA"]
13 changes: 12 additions & 1 deletion docs/src/man/log.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,18 @@ Because of the embarrassing parallelism nature of postprocessing, it is quite ea

For the plotting, streamline tracing and particle tracing, a common problem is the grid and related interpolation process. Now I have [FieldTracer.jl](https://github.com/henry2004y/FieldTracer.jl) and [TestParticle.jl](https://github.com/henry2004y/TestParticle.jl) designed specifically for these tasks.

### VTK AMR Grid Structure
## Test Data

If you don't have SWMF data at hand, Batsrus.jl provides some test data for you to begin with.
```
using LazyArtifacts
datapath = artifact"testdata" # where you can find multiple test data files
```

These are also used in the standard test. These will be automatically downloaded from [batsrus_data](https://github.com/henry2004y/batsrus_data) if you run the package test locally.

## VTK AMR Grid Structure

`vtkOverlappingAMR` implements a somewhat strict Berger-Collela AMR scheme:
1. All grids are Cartesian.
Expand Down
2 changes: 2 additions & 0 deletions src/Batsrus.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ struct FileList
name::String
"file type"
type::String
"directory"
dir::String
"file size"
bytes::Int
"number of snapshots"
Expand Down
35 changes: 17 additions & 18 deletions src/io.jl
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ function readdata(filenameIn::AbstractString; dir=".", npict=1, verbose=false)
throw(ArgumentError("Ambiguous filename $(filenameIn)!"))
end

filename = joinpath(dir, filename[1])
filelist, fileID, pictsize = getfiletype(filename)
filelist, fileID, pictsize = getfiletype(filename[1], dir)

verbose &&
@info "filename=$(filelist.name)\n"*"npict=$(filelist.npictinfiles)"
Expand Down Expand Up @@ -251,10 +250,10 @@ end


"Obtain file type."
function getfiletype(filename)

fileID = open(filename, "r")
bytes = filesize(filename)
function getfiletype(filename, dir)
file = joinpath(dir, filename)
fileID = open(file, "r")
bytes = filesize(file)
type = ""

# Check the appendix of file names
Expand Down Expand Up @@ -283,7 +282,7 @@ function getfiletype(filename)
type = "binary"
else
throw(ArgumentError(
"Error in getfiletype: incorrect formatted file: $(filename)"))
"Error in getfiletype: incorrect formatted file: $filename"))
end

if lenhead == 500
Expand All @@ -296,7 +295,7 @@ function getfiletype(filename)
npictinfiles = bytes ÷ pictsize
end

filelist = FileList(filename, type, bytes, npictinfiles)
filelist = FileList(filename, type, dir, bytes, npictinfiles)

filelist, fileID, pictsize
end
Expand Down Expand Up @@ -740,16 +739,16 @@ end
Displaying file header information.
"""
function showhead(file::FileList, head, io=stdout)
println(io, "filename = $(file.name)")
println(io, "filetype = $(file.type)")
println(io, "headline = $(head.headline)")
println(io, "iteration = $(head.it)")
println(io, "time = $(head.time)")
println(io, "gencoords = $(head.gencoord)")
println(io, "ndim = $(head.ndim)")
println(io, "neqpar = $(head.neqpar)")
println(io, "nw = $(head.nw)")
println(io, "nx = $(head.nx)")
println(io, "filename : $(file.name)")
println(io, "filetype : $(file.type)")
println(io, "headline : $(head.headline)")
println(io, "iteration: $(head.it)")
println(io, "time : $(head.time)")
println(io, "gencoords: $(head.gencoord)")
println(io, "ndim : $(head.ndim)")
println(io, "neqpar : $(head.neqpar)")
println(io, "nw : $(head.nw)")
println(io, "nx : $(head.nx)")

if head.neqpar > 0
println(io, "parameters = $(head.eqpar)")
Expand Down
261 changes: 0 additions & 261 deletions test/data/1d__raw_2_t25.60000_n00000258.out

This file was deleted.

Binary file removed test/data/3d_bin.dat
Binary file not shown.
Binary file removed test/data/3d_mhd_amr.tar.gz
Binary file not shown.
Binary file removed test/data/3d_raw.out
Binary file not shown.
121 changes: 0 additions & 121 deletions test/data/bx0_mhd_6_t00000100_n00000352.out

This file was deleted.

260 changes: 0 additions & 260 deletions test/data/log_n000001.log

This file was deleted.

Binary file removed test/data/y=0_var_1_t00000000_n00000000.out
Binary file not shown.
Binary file removed test/data/z=0_raw_1_t25.60000_n00000258.out
Binary file not shown.
27 changes: 13 additions & 14 deletions test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Tests of BATSRUS.jl

using Batsrus, Test, SHA
using Batsrus, Test, SHA, LazyArtifacts
using Batsrus.UnitfulBatsrus, Unitful

function filecmp(path1::AbstractString, path2::AbstractString)
Expand All @@ -25,10 +25,11 @@ function filecmp(path1::AbstractString, path2::AbstractString)
end

@testset "Batsrus.jl" begin
datapath = artifact"testdata"
@testset "Reading 1D ascii" begin
filename = "1d__raw_2_t25.60000_n00000258.out"
data = readdata(filename, dir="data", verbose=true)
@test startswith(repr(data), "filename = data")
data = readdata(filename, dir=datapath, verbose=true)
@test startswith(repr(data), "filename : 1d")
@test Batsrus.setunits(data.head, "NORMALIZED")
@test isa(data.head, NamedTuple)
@test extrema(data.x) == (-127.5, 127.5)
Expand All @@ -37,7 +38,7 @@ end

@testset "Reading 2D structured binary" begin
filename = "z=0_raw_1_t25.60000_n00000258.out"
data = readdata(filename, dir="data")
data = readdata(filename, dir=datapath)
@test data.head.time == 25.6f0
@test extrema(data.x) == (-127.5f0, 127.5f0)
@test extrema(data.w) == (-0.79985905f0, 1.9399388f0)
Expand All @@ -50,7 +51,7 @@ end

@testset "Reading 3D structured binary" begin
filename = "3d_raw.out"
data = readdata(filename, dir="data")
data = readdata(filename, dir=datapath)
plotrange = [-50.0, 50.0, -0.5, 0.5]
X, Z, p = cutdata(data, "p"; dir="y", sequence=1, plotrange)
@test p[1] 0.560976f0
Expand All @@ -60,39 +61,37 @@ end
end

@testset "Log" begin
logfilename = "data/log_n000001.log"
logfilename = joinpath(datapath, "log_n000001.log")
head, data = readlogdata(logfilename)
@test isa(head, NamedTuple)
@test extrema(data) == (-0.105, 258.0)
end

@testset "VTK" begin
filename = "data/3d_bin.dat"
filename = joinpath(datapath, "3d_bin.dat")
head, data, connectivity = readtecdata(filename)
@test maximum(connectivity) head[:nNode] # check if it's read correctly
convertTECtoVTU(head, data, connectivity)
sha_str = bytes2hex(open(sha1, "out.vtu"))
@test sha_str == "5b04747666542d802357dec183177f757754a254"
rm("out.vtu")

filetag = "data/3d_mhd_amr/3d__mhd_1_t00000000_n00000000"
run(`tar -C data -zxf data/3d_mhd_amr.tar.gz`)
filetag = joinpath(datapath, "3d_mhd_amr/3d__mhd_1_t00000000_n00000000")
batl = Batl(readhead(filetag*".info"), readtree(filetag)...)
# local block index check
@test Batsrus.find_grid_block(batl, [1.0, 0.0, 0.0]) == 4
@test Batsrus.find_grid_block(batl, [100.0, 0.0, 0.0]) == -100
connectivity = getConnectivity(batl)
sha_str = bytes2hex(sha256(string(connectivity)))
@test sha_str == "c6c5a65a46d86a9ba4096228c1516f89275e45e295cd305eb70c281a770ede74"
rm("data/3d_mhd_amr", recursive=true)
end

@testset "Plotting" begin
using PyPlot
ENV["MPLBACKEND"]="agg" # no GUI
@testset "1D ascii" begin
filename = "1d__raw_2_t25.60000_n00000258.out"
data = readdata(filename, dir="data", verbose=false)
data = readdata(filename, dir=datapath, verbose=false)
plotdata(data, "p", plotmode="line")
line = gca().lines[1]
@test line.get_xdata() data.x
Expand All @@ -101,7 +100,7 @@ end

@testset "2D structured binary" begin
filename = "z=0_raw_1_t25.60000_n00000258.out"
data = readdata(filename, dir="data")
data = readdata(filename, dir=datapath)
plotdata(data, "p bx;by", plotmode="contbar streamover")
@test isa(gca(), PyPlot.PyObject)
contourf(data, "p")
Expand All @@ -123,7 +122,7 @@ end

@testset "2D AMR Cartesian" begin
filename = "bx0_mhd_6_t00000100_n00000352.out"
data = readdata(filename, dir="data")
data = readdata(filename, dir=datapath)
plotdata(data, "P", plotmode="contbar")
ax = gca()
@test isa(ax, PyPlot.PyObject)
Expand All @@ -133,7 +132,7 @@ end
@testset "Units" begin
@test 1.0bu"R" > 2.0bu"Rg"
filename = "y=0_var_1_t00000000_n00000000.out"
data = readdata(filename, dir="data")
data = readdata(filename, dir=datapath)
varunit = getunit(data, "Rho")
@test varunit == bu"amucc"
varunit = getunit(data, "Ux")
Expand Down

0 comments on commit 1c81b71

Please sign in to comment.