diff --git a/Project.toml b/Project.toml index d3c9f26..db3c268 100644 --- a/Project.toml +++ b/Project.toml @@ -4,6 +4,7 @@ authors = ["fercarozzi "] version = "0.1.2" [deps] +DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0" Distributed = "8ba89e20-285c-5b6f-9357-94700520ee1b" Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4" DocumenterTools = "35a29f4d-8980-5a13-9543-d66fff28ecb8" @@ -15,6 +16,7 @@ Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2" [compat] Documenter = "0.27" DocumenterTools = "0.1" +DataFrames = "1" julia = "1" [extras] diff --git a/src/ReadWrite/SeisHeaderInfo.jl b/src/ReadWrite/SeisHeaderInfo.jl index 2979fa8..90f6925 100644 --- a/src/ReadWrite/SeisHeaderInfo.jl +++ b/src/ReadWrite/SeisHeaderInfo.jl @@ -1,67 +1,76 @@ """ - SeisHeaderInfo(filename;) + SeisHeaderInfo(filename;) Print Seis header information to screen. The input is the name of the data file # Arguments -- `ntrace=100000` : Number of traces to analyze +- `ntrace=nothing` : Number of traces to analyze *Credits: AS, 2015* """ -function SeisHeaderInfo(filename;ntrace=100000) +function SeisHeaderInfo(filename::String;ntrace::Union{Integer,Nothing}=nothing) - key = fieldnames(Header) - nhead = length(key) - filename_headers = ParseHeaderName(filename) - stream = open(filename_headers) - NX = GetNumTraces(filename) - h = GrabHeader(stream,1) - println("Displaying information for ", filename," (",NX," traces):") - min_h = zeros(Float32,length(key)) - max_h = zeros(Float32,length(key)) - mean_h = zeros(Float32,length(key)) + key = fieldnames(Header) + nhead = length(key) + filename_headers = ParseHeaderName(filename) + stream = open(filename_headers) + NX = GetNumTraces(filename) + newNTrace = isnothing(ntrace) ? NX : ntrace + h = GrabHeader(stream,1) + println("Displaying information for ", filename," (",NX," traces):") + min_h = zeros(Float32,length(key)) + max_h = zeros(Float32,length(key)) + mean_h = zeros(Float32,length(key)) - for ikey=1:length(key) - min_h[ikey] = convert(Float32,getfield(h,key[ikey])) - max_h[ikey] = convert(Float32,getfield(h,key[ikey])) - mean_h[ikey] += convert(Float32,getfield(h,key[ikey])) - end + for ikey=1:length(key) + min_h[ikey] = convert(Float32,getfield(h,key[ikey])) + max_h[ikey] = convert(Float32,getfield(h,key[ikey])) + mean_h[ikey] += convert(Float32,getfield(h,key[ikey])) + end - itrace = 2 - while itrace <= NX - nx = NX - itrace + 1 - ntrace = nx > ntrace ? ntrace : nx - position = 4*nhead*(itrace-1) - seek(stream,position) - h1 = read!(stream,Array{Header32Bits}(undef,nhead*ntrace)) - h1 = reshape(h1,nhead,convert(Int,ntrace)) - for ikey = 1 : length(key) - keytype = eval(Meta.parse("typeof(SeisMain.InitSeisHeader().$(string(key[ikey])))")) - h2 = reinterpret(keytype,vec(h1[ikey,:])) - a = minimum(h2) - b = maximum(h2) - c = mean(h2) - if (a < min_h[ikey]) - min_h[ikey] = a - end - if (b > max_h[ikey]) - max_h[ikey] = b - end - mean_h[ikey] += c*ntrace - end - itrace += ntrace - end + itrace = 2 + while itrace <= NX + nx = NX - itrace + 1 + newNTrace = nx > newNTrace ? newNTrace : nx + position = 4*nhead*(itrace-1) + seek(stream,position) + h1 = read!(stream,Array{Header32Bits}(undef,nhead*newNTrace)) + h1 = reshape(h1,nhead,convert(Int,newNTrace)) + for ikey = 1 : length(key) + keytype = eval(Meta.parse("typeof(SeisMain.InitSeisHeader().$(string(key[ikey])))")) + h2 = reinterpret(keytype,vec(h1[ikey,:])) + a = minimum(h2) + b = maximum(h2) + c = mean(h2) + if (a < min_h[ikey]) + min_h[ikey] = a + end + if (b > max_h[ikey]) + max_h[ikey] = b + end + mean_h[ikey] += c*newNTrace + end + itrace += newNTrace + end - for ikey=1:length(key) - mean_h[ikey] /= NX - end - close(stream) - println(" Key Minimum Maximum Mean"); - println("=============================================================") - for ikey=1:length(key) - @printf("%10s %11.3f %11.3f %11.3f\n",string(key[ikey]),min_h[ikey],max_h[ikey],mean_h[ikey]) - end + for ikey=1:length(key) + mean_h[ikey] /= NX + end + close(stream) + println(" Key Minimum Maximum Mean"); + println("=============================================================") + for ikey=1:length(key) + @printf("%10s %11.3f %11.3f %11.3f\n",string(key[ikey]),min_h[ikey],max_h[ikey],mean_h[ikey]) + end + df = DataFrame() + + df.Keys = key |> collect + df.Minimum = min_h + df.Mean = mean_h + df.Maximum = max_h + + return df end diff --git a/src/SeisMain.jl b/src/SeisMain.jl index f10fadf..ce70ca0 100644 --- a/src/SeisMain.jl +++ b/src/SeisMain.jl @@ -2,6 +2,7 @@ module SeisMain using Printf using Statistics using Distributed + using DataFrames include("ReadWrite/ReadWrite.jl") include("Utils/Utils.jl") end