Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing tests #28

Merged
merged 5 commits into from
Jul 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 64 additions & 0 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
name: CI
on:
push:
branches:
- master
tags: ['*']
pull_request:
workflow_dispatch:
concurrency:
# Skip intermediate builds: always.
# Cancel intermediate builds: only if it is a pull request build.
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: ${{ startsWith(github.ref, 'refs/pull/') }}
jobs:
test:
name: Julia ${{ matrix.version }} - ${{ matrix.os }} - ${{ matrix.arch }} - ${{ github.event_name }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
version:
- '1.6'
- '1.9'
- 'nightly'
os:
- ubuntu-latest
arch:
- x64
steps:
- uses: actions/checkout@v3
- uses: julia-actions/setup-julia@v1
with:
version: ${{ matrix.version }}
arch: ${{ matrix.arch }}
- uses: julia-actions/cache@v1
- uses: julia-actions/julia-buildpkg@v1
- uses: julia-actions/julia-runtest@v1
docs:
name: Documentation
runs-on: ubuntu-latest
permissions:
contents: write
statuses: write
steps:
- uses: actions/checkout@v3
- uses: julia-actions/setup-julia@v1
with:
version: '1'
- name: Configure doc environment
run: |
julia --project=docs/ -e '
using Pkg
Pkg.develop(PackageSpec(path=pwd()))
Pkg.instantiate()'
- uses: julia-actions/julia-buildpkg@v1
- uses: julia-actions/julia-docdeploy@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- run: |
julia --project=docs -e '
using Documenter: DocMeta, doctest
using SeisMain
DocMeta.setdocmeta!(SeisMain, :DocTestSetup, :(using SeisMain); recursive=true)
doctest(SeisMain)'
16 changes: 16 additions & 0 deletions .github/workflows/CompatHelper.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: CompatHelper
on:
schedule:
- cron: 0 0 * * *
workflow_dispatch:
jobs:
CompatHelper:
runs-on: ubuntu-latest
steps:
- name: Pkg.add("CompatHelper")
run: julia -e 'using Pkg; Pkg.add("CompatHelper")'
- name: CompatHelper.main()
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
COMPATHELPER_PRIV: ${{ secrets.DOCUMENTER_KEY }}
run: julia -e 'using CompatHelper; CompatHelper.main()'
4 changes: 3 additions & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@ version = "0.1.1"
Distributed = "8ba89e20-285c-5b6f-9357-94700520ee1b"
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
DocumenterTools = "35a29f4d-8980-5a13-9543-d66fff28ecb8"
Downloads = "f43a241f-c20a-4ad4-852c-f6b1247861c6"
Printf = "de0858da-6303-5e67-8744-51eddeeeb8d7"
SHA = "ea8e919c-243c-51af-8825-aaa63cd721ce"
Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"

[compat]
julia = "1"
Documenter = "0.27"
DocumenterTools = "0.1"
julia = "1"

[extras]
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
Expand Down
50 changes: 50 additions & 0 deletions src/Utils/DownloadIfNeeded.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
using Downloads
using SHA

"""
download_if_needed(url::String, output::String, sha256sum::String)

Download the file from `url` to `output` if the file is not already present
or if its SHA256 checksum does not match the `sha256sum`.

# Arguments
- `url::String`: The URL from which to download the file.
- `output::String`: The path where the downloaded file will be saved.

# Keyword arguments
- `sha256sum::String`: The expected SHA256 checksum of the file to ensure its integrity.

# Output
- `nothing`: This function returns `nothing`. It performs the side effect of downloading a file and verifying its checksum. If the checksum does not match, the function raises an error and deletes the downloaded file.

*Credits: Átila Saraiva Quintela Soares, 2024*
"""
function download_if_needed(url::String, output::String; sha256sum::String)
file_exists = isfile(output)

if file_exists
file_sha256 = open(output) do io
io |> sha256 |> bytes2hex
end
if file_sha256 == sha256sum
return nothing
else
@warn("File exists but checksum does not match. Downloading again.")
end
end

# Download the file
Downloads.download(url, output)

# Verify checksum of the downloaded file
open(output) do io
file_sha256 = io |> sha256 |> bytes2hex
if file_sha256 != sha256sum
rm(output)
error("Downloaded file checksum does not match the expected checksum.")
end
end

return nothing
end

4 changes: 3 additions & 1 deletion src/Utils/Utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ SeisUnPatch,
SeisWindow,
SeisWindowHeaders,
SeisBinData,
SeisBinHeaders
SeisBinHeaders,
download_if_needed
include("SeisGeometry.jl")
include("SeisPatch.jl")
include("SeisWindowPatch.jl")
Expand All @@ -24,3 +25,4 @@ include("SeisWindow.jl")
include("SeisWindowHeaders.jl")
include("SeisBinData.jl")
include("SeisBinHeaders.jl")
include("DownloadIfNeeded.jl")
3 changes: 0 additions & 3 deletions test/chhh.jl

This file was deleted.

3 changes: 3 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
using SeisMain
using Test

include("test_IO.jl")
include("test_bin.jl")
include("test_patch.jl")
24 changes: 16 additions & 8 deletions test/test_IO.jl
Original file line number Diff line number Diff line change
@@ -1,15 +1,23 @@
using SeisMain
using Test

#From USGS, National Petroleum Reserve - Alaska Data Archive
#https://energy.usgs.gov/GeochemistryGeophysics/SeismicDataProcessingInterpretation/NPRASeismicDataArchive.aspx#3862174-data-

download("http://certmapper.cr.usgs.gov/data/NPRA/seismic/1976/125_76/PROCESSED/125_76_PT2_PR.SGY","125_76.SGY")

download_if_needed("https://saigfileserver.physics.ualberta.ca/static/Datasets/Testing/16_81_PT1_PR.SGY", "16_81_PT1_PR.SGY", sha256sum="54791e8626215d36f6ebcecc3039da2fd74f3472518f47d8e8137c81c2ccfc2f")

SegyToSeis("125_76.SGY","125_76")
d,h,ext = SeisRead("125_76")
SegyToSeis("16_81_PT1_PR.SGY","16_81_PT1_PR")
d,h,ext = SeisRead("16_81_PT1_PR")
imx = SeisMain.ExtractHeader(h,"imx")
println("size(d)=",size(d))
println("imx=",imx)
SeisWrite("125_76_copy",d,h,ext)
SeisWrite("16_81_PT1_PR_copy",d,h,ext)

for file in (
"16_81_PT1_PR",
"16_81_PT1_PR.SGY",
"16_81_PT1_PR@data@",
"16_81_PT1_PR@headers@",
"16_81_PT1_PR_copy",
"16_81_PT1_PR_copy@data@",
"16_81_PT1_PR_copy@headers@",
)
rm(joinpath(@__DIR__, file))
end
18 changes: 12 additions & 6 deletions test/test_bin.jl
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
using SeisMain
using Test

println("Testing test_bin.jl")

download("http://seismic.physics.ualberta.ca/data/prestack_section.su","section.su");
download_if_needed("https://saigfileserver.physics.ualberta.ca/static/Datasets/Testing/prestack_section.su", "section.su", sha256sum="8baaf281a36dcd5656e07e728bf97e0c1b513302b12206efbb24c3edb34d9ec8");

SegyToSeis("section.su","section",format="su",input_type="ieee");

param1 = Dict( :dmx=>15, :dmy=>15, :dh=>30, :daz=>45 );

param2 = Dict(:style=>"mxmyhaz", :min_imx=>10,:max_imx=>100, :min_imy=>35, :max_imy=>45,
:min_ih=>1, :max_ih=>6, :min_iaz=>0, :max_iaz=>7);

Expand All @@ -22,4 +19,13 @@ db,hb,eb=SeisRead("section_bin");

N =size(db)

@test N == (251, 91, 11, 6, 8)
@test N == (251, 91, 11, 6, 8)

for file in (
"section",
"section@data@",
"section@headers@",
"section.su",
)
rm(joinpath(@__DIR__, file))
end
18 changes: 14 additions & 4 deletions test/test_patch.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
using SeisMain
using Test

param2 = Dict(:style=>"mxmyhaz", :min_imx=>10,:max_imx=>100, :min_imy=>35, :max_imy=>45,
:min_ih=>1, :max_ih=>6, :min_iaz=>0, :max_iaz=>7);

Expand All @@ -20,4 +17,17 @@ df,hf,ef=SeisRead(file_final);

alpha = maximum(db-df)

@test alpha < 0.1
@test alpha < 0.1

for file in (
"section_bin",
"section_bin_final",
"patch_1",
"patch_2",
"patch_3",
"patch_4",
)
rm(joinpath(@__DIR__, file))
rm(joinpath(@__DIR__, file*"@data@"))
rm(joinpath(@__DIR__, file*"@headers@"))
end
Loading