diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml new file mode 100644 index 0000000..aef23ca --- /dev/null +++ b/.github/workflows/CI.yml @@ -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)' diff --git a/.github/workflows/CompatHelper.yml b/.github/workflows/CompatHelper.yml new file mode 100644 index 0000000..cba9134 --- /dev/null +++ b/.github/workflows/CompatHelper.yml @@ -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()' diff --git a/Project.toml b/Project.toml index a625e97..f76a0b4 100644 --- a/Project.toml +++ b/Project.toml @@ -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" diff --git a/src/Utils/DownloadIfNeeded.jl b/src/Utils/DownloadIfNeeded.jl new file mode 100644 index 0000000..dae5f4b --- /dev/null +++ b/src/Utils/DownloadIfNeeded.jl @@ -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 + diff --git a/src/Utils/Utils.jl b/src/Utils/Utils.jl index 6c4fc2a..7535cf4 100644 --- a/src/Utils/Utils.jl +++ b/src/Utils/Utils.jl @@ -10,7 +10,8 @@ SeisUnPatch, SeisWindow, SeisWindowHeaders, SeisBinData, -SeisBinHeaders +SeisBinHeaders, +download_if_needed include("SeisGeometry.jl") include("SeisPatch.jl") include("SeisWindowPatch.jl") @@ -24,3 +25,4 @@ include("SeisWindow.jl") include("SeisWindowHeaders.jl") include("SeisBinData.jl") include("SeisBinHeaders.jl") +include("DownloadIfNeeded.jl") diff --git a/test/chhh.jl b/test/chhh.jl deleted file mode 100644 index ddb47c9..0000000 --- a/test/chhh.jl +++ /dev/null @@ -1,3 +0,0 @@ - - -# test diff --git a/test/runtests.jl b/test/runtests.jl index ca89d68..fdc1ed3 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1,3 +1,6 @@ +using SeisMain +using Test + include("test_IO.jl") include("test_bin.jl") include("test_patch.jl") diff --git a/test/test_IO.jl b/test/test_IO.jl index 0c37e7f..7eb54ce 100644 --- a/test/test_IO.jl +++ b/test/test_IO.jl @@ -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 diff --git a/test/test_bin.jl b/test/test_bin.jl index c72092f..50d3f30 100644 --- a/test/test_bin.jl +++ b/test/test_bin.jl @@ -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); @@ -22,4 +19,13 @@ db,hb,eb=SeisRead("section_bin"); N =size(db) -@test N == (251, 91, 11, 6, 8) \ No newline at end of file +@test N == (251, 91, 11, 6, 8) + +for file in ( + "section", + "section@data@", + "section@headers@", + "section.su", + ) + rm(joinpath(@__DIR__, file)) +end diff --git a/test/test_patch.jl b/test/test_patch.jl index 70a4a9f..1eb9265 100644 --- a/test/test_patch.jl +++ b/test/test_patch.jl @@ -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); @@ -20,4 +17,17 @@ df,hf,ef=SeisRead(file_final); alpha = maximum(db-df) -@test alpha < 0.1 \ No newline at end of file +@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