Skip to content

Commit

Permalink
Merge pull request #35 from AtilaSaraiva/seisHeaderInfo
Browse files Browse the repository at this point in the history
Adding DataFrames output to SeisHeaderInfo
  • Loading branch information
AtilaSaraiva authored Sep 12, 2024
2 parents 9a4f9a9 + 43cefc2 commit 7d5f77e
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 51 deletions.
2 changes: 2 additions & 0 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ authors = ["fercarozzi <[email protected]>"]
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"
Expand All @@ -15,6 +16,7 @@ Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
[compat]
Documenter = "0.27"
DocumenterTools = "0.1"
DataFrames = "1"
julia = "1"

[extras]
Expand Down
111 changes: 60 additions & 51 deletions src/ReadWrite/SeisHeaderInfo.jl
Original file line number Diff line number Diff line change
@@ -1,67 +1,76 @@
"""
SeisHeaderInfo(filename;<keyword arguments>)
SeisHeaderInfo(filename;<keyword arguments>)
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
1 change: 1 addition & 0 deletions src/SeisMain.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ module SeisMain
using Printf
using Statistics
using Distributed
using DataFrames
include("ReadWrite/ReadWrite.jl")
include("Utils/Utils.jl")
end

0 comments on commit 7d5f77e

Please sign in to comment.